src/share/vm/services/memReporter.hpp

changeset 3900
d2a62e0f25eb
child 4165
fb19af007ffc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/services/memReporter.hpp	Thu Jun 28 17:03:16 2012 -0400
     1.3 @@ -0,0 +1,268 @@
     1.4 +/*
     1.5 + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_SERVICES_MEM_REPORTER_HPP
    1.29 +#define SHARE_VM_SERVICES_MEM_REPORTER_HPP
    1.30 +
    1.31 +#include "runtime/mutexLocker.hpp"
    1.32 +#include "services/memBaseline.hpp"
    1.33 +#include "services/memTracker.hpp"
    1.34 +#include "utilities/ostream.hpp"
    1.35 +
    1.36 +/*
    1.37 + * MemBaselineReporter reports data to this outputer class,
    1.38 + * ReportOutputer is responsible for format, store and redirect
    1.39 + * the data to the final destination.
    1.40 + */
    1.41 +class BaselineOutputer : public StackObj {
    1.42 + public:
    1.43 +  // start to report memory usage in specified scale.
    1.44 +  // if report_diff = true, the reporter reports baseline comparison
    1.45 +  // information.
    1.46 +
    1.47 +  virtual void start(size_t scale, bool report_diff = false) = 0;
    1.48 +  // Done reporting
    1.49 +  virtual void done() = 0;
    1.50 +
    1.51 +  /* report baseline summary information */
    1.52 +  virtual void total_usage(size_t total_reserved,
    1.53 +                           size_t total_committed) = 0;
    1.54 +  virtual void num_of_classes(size_t classes) = 0;
    1.55 +  virtual void num_of_threads(size_t threads) = 0;
    1.56 +
    1.57 +  virtual void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) = 0;
    1.58 +
    1.59 +  /* report baseline summary comparison */
    1.60 +  virtual void diff_total_usage(size_t total_reserved,
    1.61 +                                size_t total_committed,
    1.62 +                                int reserved_diff,
    1.63 +                                int committed_diff) = 0;
    1.64 +  virtual void diff_num_of_classes(size_t classes, int diff) = 0;
    1.65 +  virtual void diff_num_of_threads(size_t threads, int diff) = 0;
    1.66 +
    1.67 +  virtual void diff_thread_info(size_t stack_reserved, size_t stack_committed,
    1.68 +        int stack_reserved_diff, int stack_committed_diff) = 0;
    1.69 +
    1.70 +
    1.71 +  /*
    1.72 +   * memory summary by memory types.
    1.73 +   * for each memory type, following summaries are reported:
    1.74 +   *  - reserved amount, committed amount
    1.75 +   *  - malloc'd amount, malloc count
    1.76 +   *  - arena amount, arena count
    1.77 +   */
    1.78 +
    1.79 +  // start reporting memory summary by memory type
    1.80 +  virtual void start_category_summary() = 0;
    1.81 +
    1.82 +  virtual void category_summary(MEMFLAGS type, size_t reserved_amt,
    1.83 +                                size_t committed_amt,
    1.84 +                                size_t malloc_amt, size_t malloc_count,
    1.85 +                                size_t arena_amt, size_t arena_count) = 0;
    1.86 +
    1.87 +  virtual void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
    1.88 +                                size_t cur_committed_amt,
    1.89 +                                size_t cur_malloc_amt, size_t cur_malloc_count,
    1.90 +                                size_t cur_arena_amt, size_t cur_arena_count,
    1.91 +                                int reserved_diff, int committed_diff, int malloc_diff,
    1.92 +                                int malloc_count_diff, int arena_diff,
    1.93 +                                int arena_count_diff) = 0;
    1.94 +
    1.95 +  virtual void done_category_summary() = 0;
    1.96 +
    1.97 +  /*
    1.98 +   *  Report callsite information
    1.99 +   */
   1.100 +  virtual void start_callsite() = 0;
   1.101 +  virtual void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count) = 0;
   1.102 +  virtual void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt) = 0;
   1.103 +
   1.104 +  virtual void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
   1.105 +              int malloc_diff, int malloc_count_diff) = 0;
   1.106 +  virtual void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
   1.107 +              int reserved_diff, int committed_diff) = 0;
   1.108 +
   1.109 +  virtual void done_callsite() = 0;
   1.110 +
   1.111 +  // return current scale in "KB", "MB" or "GB"
   1.112 +  static const char* memory_unit(size_t scale);
   1.113 +};
   1.114 +
   1.115 +/*
   1.116 + * This class reports processed data from a baseline or
   1.117 + * the changes between the two baseline.
   1.118 + */
   1.119 +class BaselineReporter : public StackObj {
   1.120 + private:
   1.121 +  BaselineOutputer&  _outputer;
   1.122 +  size_t             _scale;
   1.123 +
   1.124 + public:
   1.125 +  // construct a reporter that reports memory usage
   1.126 +  // in specified scale
   1.127 +  BaselineReporter(BaselineOutputer& outputer, size_t scale = K):
   1.128 +    _outputer(outputer) {
   1.129 +    _scale = scale;
   1.130 +  }
   1.131 +  virtual void report_baseline(const MemBaseline& baseline, bool summary_only = false);
   1.132 +  virtual void diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
   1.133 +                              bool summary_only = false);
   1.134 +
   1.135 +  void set_scale(size_t scale);
   1.136 +  size_t scale() const { return _scale; }
   1.137 +
   1.138 + private:
   1.139 +  void report_summaries(const MemBaseline& baseline);
   1.140 +  void report_callsites(const MemBaseline& baseline);
   1.141 +
   1.142 +  void diff_summaries(const MemBaseline& cur, const MemBaseline& prev);
   1.143 +  void diff_callsites(const MemBaseline& cur, const MemBaseline& prev);
   1.144 +
   1.145 +  // calculate memory size in current memory scale
   1.146 +  size_t amount_in_current_scale(size_t amt) const;
   1.147 +  // diff two unsigned values in current memory scale
   1.148 +  int    diff_in_current_scale(size_t value1, size_t value2) const;
   1.149 +  // diff two unsigned value
   1.150 +  int    diff(size_t value1, size_t value2) const;
   1.151 +};
   1.152 +
   1.153 +/*
   1.154 + * tty output implementation. Native memory tracking
   1.155 + * DCmd uses this outputer.
   1.156 + */
   1.157 +class BaselineTTYOutputer : public BaselineOutputer {
   1.158 + private:
   1.159 +  size_t         _scale;
   1.160 +
   1.161 +  size_t         _num_of_classes;
   1.162 +  size_t         _num_of_threads;
   1.163 +  size_t         _thread_stack_reserved;
   1.164 +  size_t         _thread_stack_committed;
   1.165 +
   1.166 +  int            _num_of_classes_diff;
   1.167 +  int            _num_of_threads_diff;
   1.168 +  int            _thread_stack_reserved_diff;
   1.169 +  int            _thread_stack_committed_diff;
   1.170 +
   1.171 +  outputStream*  _output;
   1.172 +
   1.173 + public:
   1.174 +  BaselineTTYOutputer(outputStream* st) {
   1.175 +    _scale = K;
   1.176 +    _num_of_classes = 0;
   1.177 +    _num_of_threads = 0;
   1.178 +    _thread_stack_reserved = 0;
   1.179 +    _thread_stack_committed = 0;
   1.180 +    _num_of_classes_diff = 0;
   1.181 +    _num_of_threads_diff = 0;
   1.182 +    _thread_stack_reserved_diff = 0;
   1.183 +    _thread_stack_committed_diff = 0;
   1.184 +    _output = st;
   1.185 +  }
   1.186 +
   1.187 +  // begin reporting memory usage in specified scale
   1.188 +  void start(size_t scale, bool report_diff = false);
   1.189 +  // done reporting
   1.190 +  void done();
   1.191 +
   1.192 +  // total memory usage
   1.193 +  void total_usage(size_t total_reserved,
   1.194 +                   size_t total_committed);
   1.195 +  // report total loaded classes
   1.196 +  void num_of_classes(size_t classes) {
   1.197 +    _num_of_classes = classes;
   1.198 +  }
   1.199 +
   1.200 +  void num_of_threads(size_t threads) {
   1.201 +    _num_of_threads = threads;
   1.202 +  }
   1.203 +
   1.204 +  void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) {
   1.205 +    _thread_stack_reserved = stack_reserved_amt;
   1.206 +    _thread_stack_committed = stack_committed_amt;
   1.207 +  }
   1.208 +
   1.209 +  void diff_total_usage(size_t total_reserved,
   1.210 +                        size_t total_committed,
   1.211 +                        int reserved_diff,
   1.212 +                        int committed_diff);
   1.213 +
   1.214 +  void diff_num_of_classes(size_t classes, int diff) {
   1.215 +    _num_of_classes = classes;
   1.216 +    _num_of_classes_diff = diff;
   1.217 +  }
   1.218 +
   1.219 +  void diff_num_of_threads(size_t threads, int diff) {
   1.220 +    _num_of_threads = threads;
   1.221 +    _num_of_threads_diff = diff;
   1.222 +  }
   1.223 +
   1.224 +  void diff_thread_info(size_t stack_reserved_amt, size_t stack_committed_amt,
   1.225 +               int stack_reserved_diff, int stack_committed_diff) {
   1.226 +    _thread_stack_reserved = stack_reserved_amt;
   1.227 +    _thread_stack_committed = stack_committed_amt;
   1.228 +    _thread_stack_reserved_diff = stack_reserved_diff;
   1.229 +    _thread_stack_committed_diff = stack_committed_diff;
   1.230 +  }
   1.231 +
   1.232 +  /*
   1.233 +   * Report memory summary categoriuzed by memory types.
   1.234 +   * For each memory type, following summaries are reported:
   1.235 +   *  - reserved amount, committed amount
   1.236 +   *  - malloc-ed amount, malloc count
   1.237 +   *  - arena amount, arena count
   1.238 +   */
   1.239 +  // start reporting memory summary by memory type
   1.240 +  void start_category_summary();
   1.241 +  void category_summary(MEMFLAGS type, size_t reserved_amt, size_t committed_amt,
   1.242 +                               size_t malloc_amt, size_t malloc_count,
   1.243 +                               size_t arena_amt, size_t arena_count);
   1.244 +
   1.245 +  void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
   1.246 +                          size_t cur_committed_amt,
   1.247 +                          size_t cur_malloc_amt, size_t cur_malloc_count,
   1.248 +                          size_t cur_arena_amt, size_t cur_arena_count,
   1.249 +                          int reserved_diff, int committed_diff, int malloc_diff,
   1.250 +                          int malloc_count_diff, int arena_diff,
   1.251 +                          int arena_count_diff);
   1.252 +
   1.253 +  void done_category_summary();
   1.254 +
   1.255 +  /*
   1.256 +   *  Report callsite information
   1.257 +   */
   1.258 +  void start_callsite();
   1.259 +  void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count);
   1.260 +  void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt);
   1.261 +
   1.262 +  void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
   1.263 +              int malloc_diff, int malloc_count_diff);
   1.264 +  void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
   1.265 +              int reserved_diff, int committed_diff);
   1.266 +
   1.267 +  void done_callsite();
   1.268 +};
   1.269 +
   1.270 +
   1.271 +#endif // SHARE_VM_SERVICES_MEM_REPORTER_HPP

mercurial