src/share/vm/utilities/histogram.hpp

Mon, 02 Jul 2012 13:11:28 -0400

author
coleenp
date
Mon, 02 Jul 2012 13:11:28 -0400
changeset 3901
24b9c7f4cae6
parent 3900
d2a62e0f25eb
child 4153
b9a9ed0f8eeb
permissions
-rw-r--r--

Merge

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_HISTOGRAM_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_HISTOGRAM_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "runtime/os.hpp"
stefank@2314 30 #include "utilities/growableArray.hpp"
stefank@2314 31 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 32 # include "os_linux.inline.hpp"
stefank@2314 33 #endif
stefank@2314 34 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 35 # include "os_solaris.inline.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 38 # include "os_windows.inline.hpp"
stefank@2314 39 #endif
never@3156 40 #ifdef TARGET_OS_FAMILY_bsd
never@3156 41 # include "os_bsd.inline.hpp"
never@3156 42 #endif
stefank@2314 43
duke@435 44 // This class provides a framework for collecting various statistics.
duke@435 45 // The current implementation is oriented towards counting invocations
duke@435 46 // of various types, but that can be easily changed.
duke@435 47 //
duke@435 48 // To use it, you need to declare a Histogram*, and a subtype of
duke@435 49 // HistogramElement:
duke@435 50 //
duke@435 51 // HistogramElement* MyHistogram;
duke@435 52 //
duke@435 53 // class MyHistogramElement : public HistogramElement {
duke@435 54 // public:
duke@435 55 // MyHistogramElement(char* name);
duke@435 56 // };
duke@435 57 //
duke@435 58 // MyHistogramElement::MyHistogramElement(char* elementName) {
duke@435 59 // _name = elementName;
duke@435 60 //
duke@435 61 // if(MyHistogram == NULL)
duke@435 62 // MyHistogram = new Histogram("My Call Counts",100);
duke@435 63 //
duke@435 64 // MyHistogram->add_element(this);
duke@435 65 // }
duke@435 66 //
duke@435 67 // #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count()
duke@435 68 //
duke@435 69 // This gives you a simple way to count invocations of specfic functions:
duke@435 70 //
duke@435 71 // void a_function_that_is_being_counted() {
duke@435 72 // MyCountWrapper("FunctionName");
duke@435 73 // ...
duke@435 74 // }
duke@435 75 //
duke@435 76 // To print the results, invoke print() on your Histogram*.
duke@435 77
duke@435 78 #ifdef ASSERT
duke@435 79
zgu@3900 80 class HistogramElement : public CHeapObj<mtInternal> {
duke@435 81 protected:
duke@435 82 jint _count;
duke@435 83 const char* _name;
duke@435 84
duke@435 85 public:
duke@435 86 HistogramElement();
duke@435 87 virtual int count();
duke@435 88 virtual const char* name();
duke@435 89 virtual void increment_count();
duke@435 90 void print_on(outputStream* st) const;
duke@435 91 virtual int compare(HistogramElement* e1,HistogramElement* e2);
duke@435 92 };
duke@435 93
zgu@3900 94 class Histogram : public CHeapObj<mtInternal> {
duke@435 95 protected:
duke@435 96 GrowableArray<HistogramElement*>* _elements;
duke@435 97 GrowableArray<HistogramElement*>* elements() { return _elements; }
duke@435 98 const char* _title;
duke@435 99 const char* title() { return _title; }
duke@435 100 static int sort_helper(HistogramElement** e1,HistogramElement** e2);
duke@435 101 virtual void print_header(outputStream* st);
duke@435 102 virtual void print_elements(outputStream* st);
duke@435 103
duke@435 104 public:
duke@435 105 Histogram(const char* title,int estimatedSize);
duke@435 106 virtual void add_element(HistogramElement* element);
duke@435 107 void print_on(outputStream* st) const;
duke@435 108 };
duke@435 109
duke@435 110 #endif
stefank@2314 111
stefank@2314 112 #endif // SHARE_VM_UTILITIES_HISTOGRAM_HPP

mercurial