Wed, 27 Aug 2014 09:36:55 +0200
Merge
1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_SERVICES_MEM_REPORTER_HPP
26 #define SHARE_VM_SERVICES_MEM_REPORTER_HPP
28 #include "runtime/mutexLocker.hpp"
29 #include "services/memBaseline.hpp"
30 #include "services/memTracker.hpp"
31 #include "utilities/ostream.hpp"
32 #include "utilities/macros.hpp"
34 #if INCLUDE_NMT
36 /*
37 * MemBaselineReporter reports data to this outputer class,
38 * ReportOutputer is responsible for format, store and redirect
39 * the data to the final destination.
40 */
41 class BaselineOutputer : public StackObj {
42 public:
43 // start to report memory usage in specified scale.
44 // if report_diff = true, the reporter reports baseline comparison
45 // information.
47 virtual void start(size_t scale, bool report_diff = false) = 0;
48 // Done reporting
49 virtual void done() = 0;
51 /* report baseline summary information */
52 virtual void total_usage(size_t total_reserved,
53 size_t total_committed) = 0;
54 virtual void num_of_classes(size_t classes) = 0;
55 virtual void num_of_threads(size_t threads) = 0;
57 virtual void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) = 0;
59 /* report baseline summary comparison */
60 virtual void diff_total_usage(size_t total_reserved,
61 size_t total_committed,
62 int reserved_diff,
63 int committed_diff) = 0;
64 virtual void diff_num_of_classes(size_t classes, int diff) = 0;
65 virtual void diff_num_of_threads(size_t threads, int diff) = 0;
67 virtual void diff_thread_info(size_t stack_reserved, size_t stack_committed,
68 int stack_reserved_diff, int stack_committed_diff) = 0;
71 /*
72 * memory summary by memory types.
73 * for each memory type, following summaries are reported:
74 * - reserved amount, committed amount
75 * - malloc'd amount, malloc count
76 * - arena amount, arena count
77 */
79 // start reporting memory summary by memory type
80 virtual void start_category_summary() = 0;
82 virtual void category_summary(MEMFLAGS type, size_t reserved_amt,
83 size_t committed_amt,
84 size_t malloc_amt, size_t malloc_count,
85 size_t arena_amt, size_t arena_count) = 0;
87 virtual void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
88 size_t cur_committed_amt,
89 size_t cur_malloc_amt, size_t cur_malloc_count,
90 size_t cur_arena_amt, size_t cur_arena_count,
91 int reserved_diff, int committed_diff, int malloc_diff,
92 int malloc_count_diff, int arena_diff,
93 int arena_count_diff) = 0;
95 virtual void done_category_summary() = 0;
97 virtual void start_virtual_memory_map() = 0;
98 virtual void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc) = 0;
99 virtual void committed_memory_region(address base, address end, size_t size, address pc) = 0;
100 virtual void done_virtual_memory_map() = 0;
102 /*
103 * Report callsite information
104 */
105 virtual void start_callsite() = 0;
106 virtual void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count) = 0;
107 virtual void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt) = 0;
109 virtual void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
110 int malloc_diff, int malloc_count_diff) = 0;
111 virtual void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
112 int reserved_diff, int committed_diff) = 0;
114 virtual void done_callsite() = 0;
116 // return current scale in "KB", "MB" or "GB"
117 static const char* memory_unit(size_t scale);
118 };
120 /*
121 * This class reports processed data from a baseline or
122 * the changes between the two baseline.
123 */
124 class BaselineReporter : public StackObj {
125 private:
126 BaselineOutputer& _outputer;
127 size_t _scale;
129 public:
130 // construct a reporter that reports memory usage
131 // in specified scale
132 BaselineReporter(BaselineOutputer& outputer, size_t scale = K):
133 _outputer(outputer) {
134 _scale = scale;
135 }
136 virtual void report_baseline(const MemBaseline& baseline, bool summary_only = false);
137 virtual void diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
138 bool summary_only = false);
140 void set_scale(size_t scale);
141 size_t scale() const { return _scale; }
143 private:
144 void report_summaries(const MemBaseline& baseline);
145 void report_virtual_memory_map(const MemBaseline& baseline);
146 void report_callsites(const MemBaseline& baseline);
148 void diff_summaries(const MemBaseline& cur, const MemBaseline& prev);
149 void diff_callsites(const MemBaseline& cur, const MemBaseline& prev);
151 // calculate memory size in current memory scale
152 size_t amount_in_current_scale(size_t amt) const;
153 // diff two unsigned values in current memory scale
154 int diff_in_current_scale(size_t value1, size_t value2) const;
155 // diff two unsigned value
156 int diff(size_t value1, size_t value2) const;
157 };
159 /*
160 * tty output implementation. Native memory tracking
161 * DCmd uses this outputer.
162 */
163 class BaselineTTYOutputer : public BaselineOutputer {
164 private:
165 size_t _scale;
167 size_t _num_of_classes;
168 size_t _num_of_threads;
169 size_t _thread_stack_reserved;
170 size_t _thread_stack_committed;
172 int _num_of_classes_diff;
173 int _num_of_threads_diff;
174 int _thread_stack_reserved_diff;
175 int _thread_stack_committed_diff;
177 outputStream* _output;
179 public:
180 BaselineTTYOutputer(outputStream* st) {
181 _scale = K;
182 _num_of_classes = 0;
183 _num_of_threads = 0;
184 _thread_stack_reserved = 0;
185 _thread_stack_committed = 0;
186 _num_of_classes_diff = 0;
187 _num_of_threads_diff = 0;
188 _thread_stack_reserved_diff = 0;
189 _thread_stack_committed_diff = 0;
190 _output = st;
191 }
193 // begin reporting memory usage in specified scale
194 void start(size_t scale, bool report_diff = false);
195 // done reporting
196 void done();
198 // total memory usage
199 void total_usage(size_t total_reserved,
200 size_t total_committed);
201 // report total loaded classes
202 void num_of_classes(size_t classes) {
203 _num_of_classes = classes;
204 }
206 void num_of_threads(size_t threads) {
207 _num_of_threads = threads;
208 }
210 void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) {
211 _thread_stack_reserved = stack_reserved_amt;
212 _thread_stack_committed = stack_committed_amt;
213 }
215 void diff_total_usage(size_t total_reserved,
216 size_t total_committed,
217 int reserved_diff,
218 int committed_diff);
220 void diff_num_of_classes(size_t classes, int diff) {
221 _num_of_classes = classes;
222 _num_of_classes_diff = diff;
223 }
225 void diff_num_of_threads(size_t threads, int diff) {
226 _num_of_threads = threads;
227 _num_of_threads_diff = diff;
228 }
230 void diff_thread_info(size_t stack_reserved_amt, size_t stack_committed_amt,
231 int stack_reserved_diff, int stack_committed_diff) {
232 _thread_stack_reserved = stack_reserved_amt;
233 _thread_stack_committed = stack_committed_amt;
234 _thread_stack_reserved_diff = stack_reserved_diff;
235 _thread_stack_committed_diff = stack_committed_diff;
236 }
238 /*
239 * Report memory summary categoriuzed by memory types.
240 * For each memory type, following summaries are reported:
241 * - reserved amount, committed amount
242 * - malloc-ed amount, malloc count
243 * - arena amount, arena count
244 */
245 // start reporting memory summary by memory type
246 void start_category_summary();
247 void category_summary(MEMFLAGS type, size_t reserved_amt, size_t committed_amt,
248 size_t malloc_amt, size_t malloc_count,
249 size_t arena_amt, size_t arena_count);
251 void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
252 size_t cur_committed_amt,
253 size_t cur_malloc_amt, size_t cur_malloc_count,
254 size_t cur_arena_amt, size_t cur_arena_count,
255 int reserved_diff, int committed_diff, int malloc_diff,
256 int malloc_count_diff, int arena_diff,
257 int arena_count_diff);
259 void done_category_summary();
261 // virtual memory map
262 void start_virtual_memory_map();
263 void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc);
264 void committed_memory_region(address base, address end, size_t size, address pc);
265 void done_virtual_memory_map();
268 /*
269 * Report callsite information
270 */
271 void start_callsite();
272 void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count);
273 void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt);
275 void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
276 int malloc_diff, int malloc_count_diff);
277 void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
278 int reserved_diff, int committed_diff);
280 void done_callsite();
281 };
284 #endif // INCLUDE_NMT
286 #endif // SHARE_VM_SERVICES_MEM_REPORTER_HPP