Fri, 12 Oct 2012 10:49:39 -0700
Merge
1 /*
2 * Copyright (c) 2012 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"
33 #if INCLUDE_NMT
35 /*
36 * MemBaselineReporter reports data to this outputer class,
37 * ReportOutputer is responsible for format, store and redirect
38 * the data to the final destination.
39 */
40 class BaselineOutputer : public StackObj {
41 public:
42 // start to report memory usage in specified scale.
43 // if report_diff = true, the reporter reports baseline comparison
44 // information.
46 virtual void start(size_t scale, bool report_diff = false) = 0;
47 // Done reporting
48 virtual void done() = 0;
50 /* report baseline summary information */
51 virtual void total_usage(size_t total_reserved,
52 size_t total_committed) = 0;
53 virtual void num_of_classes(size_t classes) = 0;
54 virtual void num_of_threads(size_t threads) = 0;
56 virtual void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) = 0;
58 /* report baseline summary comparison */
59 virtual void diff_total_usage(size_t total_reserved,
60 size_t total_committed,
61 int reserved_diff,
62 int committed_diff) = 0;
63 virtual void diff_num_of_classes(size_t classes, int diff) = 0;
64 virtual void diff_num_of_threads(size_t threads, int diff) = 0;
66 virtual void diff_thread_info(size_t stack_reserved, size_t stack_committed,
67 int stack_reserved_diff, int stack_committed_diff) = 0;
70 /*
71 * memory summary by memory types.
72 * for each memory type, following summaries are reported:
73 * - reserved amount, committed amount
74 * - malloc'd amount, malloc count
75 * - arena amount, arena count
76 */
78 // start reporting memory summary by memory type
79 virtual void start_category_summary() = 0;
81 virtual void category_summary(MEMFLAGS type, size_t reserved_amt,
82 size_t committed_amt,
83 size_t malloc_amt, size_t malloc_count,
84 size_t arena_amt, size_t arena_count) = 0;
86 virtual void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
87 size_t cur_committed_amt,
88 size_t cur_malloc_amt, size_t cur_malloc_count,
89 size_t cur_arena_amt, size_t cur_arena_count,
90 int reserved_diff, int committed_diff, int malloc_diff,
91 int malloc_count_diff, int arena_diff,
92 int arena_count_diff) = 0;
94 virtual void done_category_summary() = 0;
96 /*
97 * Report callsite information
98 */
99 virtual void start_callsite() = 0;
100 virtual void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count) = 0;
101 virtual void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt) = 0;
103 virtual void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
104 int malloc_diff, int malloc_count_diff) = 0;
105 virtual void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
106 int reserved_diff, int committed_diff) = 0;
108 virtual void done_callsite() = 0;
110 // return current scale in "KB", "MB" or "GB"
111 static const char* memory_unit(size_t scale);
112 };
114 /*
115 * This class reports processed data from a baseline or
116 * the changes between the two baseline.
117 */
118 class BaselineReporter : public StackObj {
119 private:
120 BaselineOutputer& _outputer;
121 size_t _scale;
123 public:
124 // construct a reporter that reports memory usage
125 // in specified scale
126 BaselineReporter(BaselineOutputer& outputer, size_t scale = K):
127 _outputer(outputer) {
128 _scale = scale;
129 }
130 virtual void report_baseline(const MemBaseline& baseline, bool summary_only = false);
131 virtual void diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
132 bool summary_only = false);
134 void set_scale(size_t scale);
135 size_t scale() const { return _scale; }
137 private:
138 void report_summaries(const MemBaseline& baseline);
139 void report_callsites(const MemBaseline& baseline);
141 void diff_summaries(const MemBaseline& cur, const MemBaseline& prev);
142 void diff_callsites(const MemBaseline& cur, const MemBaseline& prev);
144 // calculate memory size in current memory scale
145 size_t amount_in_current_scale(size_t amt) const;
146 // diff two unsigned values in current memory scale
147 int diff_in_current_scale(size_t value1, size_t value2) const;
148 // diff two unsigned value
149 int diff(size_t value1, size_t value2) const;
150 };
152 /*
153 * tty output implementation. Native memory tracking
154 * DCmd uses this outputer.
155 */
156 class BaselineTTYOutputer : public BaselineOutputer {
157 private:
158 size_t _scale;
160 size_t _num_of_classes;
161 size_t _num_of_threads;
162 size_t _thread_stack_reserved;
163 size_t _thread_stack_committed;
165 int _num_of_classes_diff;
166 int _num_of_threads_diff;
167 int _thread_stack_reserved_diff;
168 int _thread_stack_committed_diff;
170 outputStream* _output;
172 public:
173 BaselineTTYOutputer(outputStream* st) {
174 _scale = K;
175 _num_of_classes = 0;
176 _num_of_threads = 0;
177 _thread_stack_reserved = 0;
178 _thread_stack_committed = 0;
179 _num_of_classes_diff = 0;
180 _num_of_threads_diff = 0;
181 _thread_stack_reserved_diff = 0;
182 _thread_stack_committed_diff = 0;
183 _output = st;
184 }
186 // begin reporting memory usage in specified scale
187 void start(size_t scale, bool report_diff = false);
188 // done reporting
189 void done();
191 // total memory usage
192 void total_usage(size_t total_reserved,
193 size_t total_committed);
194 // report total loaded classes
195 void num_of_classes(size_t classes) {
196 _num_of_classes = classes;
197 }
199 void num_of_threads(size_t threads) {
200 _num_of_threads = threads;
201 }
203 void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) {
204 _thread_stack_reserved = stack_reserved_amt;
205 _thread_stack_committed = stack_committed_amt;
206 }
208 void diff_total_usage(size_t total_reserved,
209 size_t total_committed,
210 int reserved_diff,
211 int committed_diff);
213 void diff_num_of_classes(size_t classes, int diff) {
214 _num_of_classes = classes;
215 _num_of_classes_diff = diff;
216 }
218 void diff_num_of_threads(size_t threads, int diff) {
219 _num_of_threads = threads;
220 _num_of_threads_diff = diff;
221 }
223 void diff_thread_info(size_t stack_reserved_amt, size_t stack_committed_amt,
224 int stack_reserved_diff, int stack_committed_diff) {
225 _thread_stack_reserved = stack_reserved_amt;
226 _thread_stack_committed = stack_committed_amt;
227 _thread_stack_reserved_diff = stack_reserved_diff;
228 _thread_stack_committed_diff = stack_committed_diff;
229 }
231 /*
232 * Report memory summary categoriuzed by memory types.
233 * For each memory type, following summaries are reported:
234 * - reserved amount, committed amount
235 * - malloc-ed amount, malloc count
236 * - arena amount, arena count
237 */
238 // start reporting memory summary by memory type
239 void start_category_summary();
240 void category_summary(MEMFLAGS type, size_t reserved_amt, size_t committed_amt,
241 size_t malloc_amt, size_t malloc_count,
242 size_t arena_amt, size_t arena_count);
244 void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
245 size_t cur_committed_amt,
246 size_t cur_malloc_amt, size_t cur_malloc_count,
247 size_t cur_arena_amt, size_t cur_arena_count,
248 int reserved_diff, int committed_diff, int malloc_diff,
249 int malloc_count_diff, int arena_diff,
250 int arena_count_diff);
252 void done_category_summary();
254 /*
255 * Report callsite information
256 */
257 void start_callsite();
258 void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count);
259 void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt);
261 void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
262 int malloc_diff, int malloc_count_diff);
263 void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
264 int reserved_diff, int committed_diff);
266 void done_callsite();
267 };
270 #endif // INCLUDE_NMT
272 #endif // SHARE_VM_SERVICES_MEM_REPORTER_HPP