1 /*
   2  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 
  26 #include "gc/shenandoah/shenandoahAllocTracker.hpp"
  27 #include "utilities/ostream.hpp"
  28 
  29 void ShenandoahAllocTracker::print_on(outputStream* out) const {
  30   out->print_cr("ALLOCATION TRACING");
  31   out->print_cr("  These are the slow-path allocations, including TLAB/GCLAB refills, and out-of-TLAB allocations.");
  32   out->print_cr("  In-TLAB/GCLAB allocations happen orders of magnitude more frequently, and without delays.");
  33   out->cr();
  34 
  35   out->print("%22s", "");
  36   for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  37     out->print("%12s", ShenandoahAllocRequest::alloc_type_to_string(ShenandoahAllocRequest::Type(t)));
  38   }
  39   out->cr();
  40 
  41   out->print_cr("Counts:");
  42   out->print("%22s", "#");
  43   for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  44     out->print(SIZE_FORMAT_W(12), _alloc_size[t].num());
  45   }
  46   out->cr();
  47   out->cr();
  48 
  49   // Figure out max and min levels
  50   int lat_min_level = +1000;
  51   int lat_max_level = -1000;
  52   int size_min_level = +1000;
  53   int size_max_level = -1000;
  54   for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  55     lat_min_level = MIN2(lat_min_level, _alloc_latency[t].min_level());
  56     lat_max_level = MAX2(lat_max_level, _alloc_latency[t].max_level());
  57     size_min_level = MIN2(size_min_level, _alloc_size[t].min_level());
  58     size_max_level = MAX2(size_max_level, _alloc_size[t].max_level());
  59   }
  60 
  61   out->print_cr("Latency summary:");
  62   out->print("%22s", "sum, ms:");
  63   for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  64     out->print(SIZE_FORMAT_W(12), _alloc_latency[t].sum() / K);
  65   }
  66   out->cr();
  67   out->cr();
  68 
  69   out->print_cr("Sizes summary:");
  70   out->print("%22s", "sum, M:");
  71   for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  72     out->print(SIZE_FORMAT_W(12), _alloc_size[t].sum() * HeapWordSize / M);
  73   }
  74   out->cr();
  75   out->cr();
  76 
  77   out->print_cr("Latency histogram (time in microseconds):");
  78   for (int c = lat_min_level; c <= lat_max_level; c++) {
  79     out->print("%9d - %9d:", (c == 0) ? 0 : 1 << (c - 1), 1 << c);
  80     for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  81       out->print(SIZE_FORMAT_W(12), _alloc_latency[t].level(c));
  82     }
  83     out->cr();
  84   }
  85   out->cr();
  86 
  87   out->print_cr("Sizes histogram (size in bytes):");
  88   for (int c = size_min_level; c <= size_max_level; c++) {
  89     int l = (c == 0) ? 0 : 1 << (c - 1);
  90     int r = 1 << c;
  91     out->print("%9d - %9d:", l * HeapWordSize, r * HeapWordSize);
  92     for (size_t t = 0; t < ShenandoahAllocRequest::_ALLOC_LIMIT; t++) {
  93       out->print(SIZE_FORMAT_W(12), _alloc_size[t].level(c));
  94     }
  95     out->cr();
  96   }
  97   out->cr();
  98 }