src/share/vm/utilities/intHisto.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/intHisto.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,78 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 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_UTILITIES_INTHISTO_HPP
    1.29 +#define SHARE_VM_UTILITIES_INTHISTO_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "utilities/growableArray.hpp"
    1.33 +
    1.34 +// This class implements a simple histogram.
    1.35 +
    1.36 +// A histogram summarizes a series of "measurements", each of which is
    1.37 +// assumed (required in this implementation) to have an outcome that is a
    1.38 +// non-negative integer.  The histogram efficiently maps measurement outcomes
    1.39 +// to the number of measurements had that outcome.
    1.40 +
    1.41 +// To print the results, invoke print() on your Histogram*.
    1.42 +
    1.43 +// Note: there is already an existing "Histogram" class, in file
    1.44 +// histogram.{hpp,cpp}, but to my mind that's not a histogram, it's a table
    1.45 +// mapping strings to counts.  To be a histogram (IMHO) it needs to map
    1.46 +// numbers (in fact, integers) to number of occurrences of that number.
    1.47 +
    1.48 +// ysr: (i am not sure i agree with the above note.) i suspect we want to have a
    1.49 +// histogram template that will map an arbitrary type (with a defined order
    1.50 +// relation) to a count.
    1.51 +
    1.52 +
    1.53 +class IntHistogram : public CHeapObj<mtInternal> {
    1.54 + protected:
    1.55 +  int _max;
    1.56 +  int _tot;
    1.57 +  GrowableArray<int>* _elements;
    1.58 +
    1.59 +public:
    1.60 +  // Create a new, empty table.  "est" is an estimate of the maximum outcome
    1.61 +  // that will be added, and "max" is an outcome such that all outcomes at
    1.62 +  // least that large will be bundled with it.
    1.63 +  IntHistogram(int est, int max);
    1.64 +  // Add a measurement with the given outcome to the sequence.
    1.65 +  void add_entry(int outcome);
    1.66 +  // Return the number of entries recorded so far with the given outcome.
    1.67 +  int  entries_for_outcome(int outcome);
    1.68 +  // Return the total number of entries recorded so far.
    1.69 +  int  total_entries() { return _tot; }
    1.70 +  // Return the number of entries recorded so far with the given outcome as
    1.71 +  // a fraction of the total number recorded so far.
    1.72 +  double fraction_for_outcome(int outcome) {
    1.73 +    return
    1.74 +      (double)entries_for_outcome(outcome)/
    1.75 +      (double)total_entries();
    1.76 +  }
    1.77 +  // Print the histogram on the given output stream.
    1.78 +  void print_on(outputStream* st) const;
    1.79 +};
    1.80 +
    1.81 +#endif // SHARE_VM_UTILITIES_INTHISTO_HPP

mercurial