src/hotspot/share/services/stathistDCmd.cpp
branchstuefe-statistical-history
changeset 57221 9653470b7294
equal deleted inserted replaced
53949:4a99d3a6a86d 57221:9653470b7294
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * Copyright (c) 2018, SAP SE.
       
     4  *
       
     5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6  *
       
     7  * This code is free software; you can redistribute it and/or modify it
       
     8  * under the terms of the GNU General Public License version 2 only, as
       
     9  * published by the Free Software Foundation.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  *
       
    25  */
       
    26 
       
    27 
       
    28 #include "precompiled.hpp"
       
    29 
       
    30 #include "memory/resourceArea.hpp"
       
    31 #include "services/stathist.hpp"
       
    32 #include "services/stathistDCmd.hpp"
       
    33 #include "utilities/ostream.hpp"
       
    34 #include "utilities/globalDefinitions.hpp"
       
    35 
       
    36 namespace StatisticsHistory {
       
    37 
       
    38 StatHistDCmd::StatHistDCmd(outputStream* output, bool heap)
       
    39   : DCmdWithParser(output, heap),
       
    40     _scale("scale", "Memory usage in which to scale. Valid values are: k, m, g (fixed scale) "
       
    41            "or \"dynamic\" for a dynamically chosen scale.",
       
    42            "STRING", false, "dynamic"),
       
    43     _cvs("cvs", "CVS format.", "BOOLEAN", false, "false"),
       
    44     _no_legend("no-legend", "Omit legend.", "BOOLEAN", false, "false")
       
    45 #ifdef ASSERT
       
    46     , _raw("raw", "Print raw values (debug only).", "BOOLEAN", false, "false")
       
    47 #endif
       
    48 {
       
    49   _dcmdparser.add_dcmd_option(&_scale);
       
    50   _dcmdparser.add_dcmd_option(&_no_legend);
       
    51   DEBUG_ONLY(_dcmdparser.add_dcmd_option(&_raw);)
       
    52   _dcmdparser.add_dcmd_option(&_cvs);
       
    53 }
       
    54 
       
    55 int StatHistDCmd::num_arguments() {
       
    56   ResourceMark rm;
       
    57   StatHistDCmd* dcmd = new StatHistDCmd(NULL, false);
       
    58   if (dcmd != NULL) {
       
    59     DCmdMark mark(dcmd);
       
    60     return dcmd->_dcmdparser.num_arguments();
       
    61   } else {
       
    62     return 0;
       
    63   }
       
    64 }
       
    65 
       
    66 static bool scale_from_name(const char* scale, size_t* out) {
       
    67   if (strcasecmp(scale, "dynamic") == 0) {
       
    68     *out = 0;
       
    69   } else if (strcasecmp(scale, "kb") == 0 || strcasecmp(scale, "k") == 0) {
       
    70     *out = K;
       
    71   } else if (strcasecmp(scale, "mb") == 0 || strcasecmp(scale, "m") == 0) {
       
    72     *out = M;
       
    73   } else if (strcasecmp(scale, "gb") == 0 || strcasecmp(scale, "g") == 0) {
       
    74     *out = G;
       
    75   } else {
       
    76     return false; // Invalid value
       
    77   }
       
    78   return true;
       
    79 }
       
    80 
       
    81 void StatHistDCmd::execute(DCmdSource source, TRAPS) {
       
    82   print_info_t pi;
       
    83   if (!scale_from_name(_scale.value(), &(pi.scale))) {
       
    84     output()->print_cr("Invalid scale: \"%s\".", _scale.value());
       
    85     return;
       
    86   }
       
    87   DEBUG_ONLY(pi.raw = _raw.value();)
       
    88   pi.cvs = _cvs.value();
       
    89   pi.no_legend = _no_legend.value();
       
    90   pi.avoid_sampling = false;
       
    91 
       
    92   StatisticsHistory::print_report(output(), &pi);
       
    93 }
       
    94 
       
    95 }; // namespace StatisticsHistory
       
    96