intHisto.hpp revision 3863
342N/A/*
1879N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_UTILITIES_INTHISTO_HPP
1879N/A#define SHARE_VM_UTILITIES_INTHISTO_HPP
1879N/A
1879N/A#include "memory/allocation.hpp"
1879N/A#include "utilities/growableArray.hpp"
1879N/A
342N/A// This class implements a simple histogram.
342N/A
342N/A// A histogram summarizes a series of "measurements", each of which is
342N/A// assumed (required in this implementation) to have an outcome that is a
342N/A// non-negative integer. The histogram efficiently maps measurement outcomes
342N/A// to the number of measurements had that outcome.
342N/A
342N/A// To print the results, invoke print() on your Histogram*.
342N/A
342N/A// Note: there is already an existing "Histogram" class, in file
342N/A// histogram.{hpp,cpp}, but to my mind that's not a histogram, it's a table
342N/A// mapping strings to counts. To be a histogram (IMHO) it needs to map
342N/A// numbers (in fact, integers) to number of occurrences of that number.
342N/A
342N/A// ysr: (i am not sure i agree with the above note.) i suspect we want to have a
342N/A// histogram template that will map an arbitrary type (with a defined order
342N/A// relation) to a count.
342N/A
342N/A
3863N/Aclass IntHistogram : public CHeapObj<mtInternal> {
342N/A protected:
342N/A int _max;
342N/A int _tot;
342N/A GrowableArray<int>* _elements;
342N/A
342N/Apublic:
342N/A // Create a new, empty table. "est" is an estimate of the maximum outcome
342N/A // that will be added, and "max" is an outcome such that all outcomes at
342N/A // least that large will be bundled with it.
342N/A IntHistogram(int est, int max);
342N/A // Add a measurement with the given outcome to the sequence.
342N/A void add_entry(int outcome);
342N/A // Return the number of entries recorded so far with the given outcome.
342N/A int entries_for_outcome(int outcome);
342N/A // Return the total number of entries recorded so far.
342N/A int total_entries() { return _tot; }
342N/A // Return the number of entries recorded so far with the given outcome as
342N/A // a fraction of the total number recorded so far.
342N/A double fraction_for_outcome(int outcome) {
342N/A return
342N/A (double)entries_for_outcome(outcome)/
342N/A (double)total_entries();
342N/A }
342N/A // Print the histogram on the given output stream.
342N/A void print_on(outputStream* st) const;
342N/A};
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_INTHISTO_HPP