src/share/vm/utilities/intHisto.cpp

changeset 777
37f87013dfd8
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/intHisto.cpp	Thu Jun 05 15:57:56 2008 -0700
     1.3 @@ -0,0 +1,64 @@
     1.4 +/*
     1.5 + * Copyright 2001-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_intHisto.cpp.incl"
    1.30 +
    1.31 +IntHistogram::IntHistogram(int est, int max) : _max(max), _tot(0) {
    1.32 +  assert(0 <= est && est <= max, "Preconditions");
    1.33 +  _elements = new (ResourceObj::C_HEAP) GrowableArray<int>(est, true);
    1.34 +  guarantee(_elements != NULL, "alloc failure");
    1.35 +}
    1.36 +
    1.37 +void IntHistogram::add_entry(int outcome) {
    1.38 +  if (outcome > _max) outcome = _max;
    1.39 +  int new_count = _elements->at_grow(outcome) + 1;
    1.40 +  _elements->at_put(outcome, new_count);
    1.41 +  _tot++;
    1.42 +}
    1.43 +
    1.44 +int IntHistogram::entries_for_outcome(int outcome) {
    1.45 +  return _elements->at_grow(outcome);
    1.46 +}
    1.47 +
    1.48 +void IntHistogram::print_on(outputStream* st) const {
    1.49 +  double tot_d = (double)_tot;
    1.50 +  st->print_cr("Outcome     # of occurrences   %% of occurrences");
    1.51 +  st->print_cr("-----------------------------------------------");
    1.52 +  for (int i=0; i < _elements->length()-2; i++) {
    1.53 +    int cnt = _elements->at(i);
    1.54 +    if (cnt != 0) {
    1.55 +      st->print_cr("%7d        %10d         %8.4f",
    1.56 +                   i, cnt, (double)cnt/tot_d);
    1.57 +    }
    1.58 +  }
    1.59 +  // Does it have any max entries?
    1.60 +  if (_elements->length()-1 == _max) {
    1.61 +    int cnt = _elements->at(_max);
    1.62 +    st->print_cr(">= %4d        %10d         %8.4f",
    1.63 +                 _max, cnt, (double)cnt/tot_d);
    1.64 +  }
    1.65 +  st->print_cr("-----------------------------------------------");
    1.66 +  st->print_cr("    All        %10d         %8.4f", _tot, 1.0);
    1.67 +}

mercurial