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