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