duke@435: /* mikael@4153: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * 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. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_UTILITIES_HISTOGRAM_HPP stefank@2314: #define SHARE_VM_UTILITIES_HISTOGRAM_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "runtime/os.hpp" stefank@2314: #include "utilities/growableArray.hpp" stefank@2314: #ifdef TARGET_OS_FAMILY_linux stefank@2314: # include "os_linux.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_solaris stefank@2314: # include "os_solaris.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_windows stefank@2314: # include "os_windows.inline.hpp" stefank@2314: #endif goetz@6461: #ifdef TARGET_OS_FAMILY_aix goetz@6461: # include "os_aix.inline.hpp" goetz@6461: #endif never@3156: #ifdef TARGET_OS_FAMILY_bsd never@3156: # include "os_bsd.inline.hpp" never@3156: #endif stefank@2314: duke@435: // This class provides a framework for collecting various statistics. duke@435: // The current implementation is oriented towards counting invocations duke@435: // of various types, but that can be easily changed. duke@435: // duke@435: // To use it, you need to declare a Histogram*, and a subtype of duke@435: // HistogramElement: duke@435: // duke@435: // HistogramElement* MyHistogram; duke@435: // duke@435: // class MyHistogramElement : public HistogramElement { duke@435: // public: duke@435: // MyHistogramElement(char* name); duke@435: // }; duke@435: // duke@435: // MyHistogramElement::MyHistogramElement(char* elementName) { duke@435: // _name = elementName; duke@435: // duke@435: // if(MyHistogram == NULL) duke@435: // MyHistogram = new Histogram("My Call Counts",100); duke@435: // duke@435: // MyHistogram->add_element(this); duke@435: // } duke@435: // duke@435: // #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count() duke@435: // duke@435: // This gives you a simple way to count invocations of specfic functions: duke@435: // duke@435: // void a_function_that_is_being_counted() { duke@435: // MyCountWrapper("FunctionName"); duke@435: // ... duke@435: // } duke@435: // duke@435: // To print the results, invoke print() on your Histogram*. duke@435: duke@435: #ifdef ASSERT duke@435: zgu@3900: class HistogramElement : public CHeapObj { duke@435: protected: duke@435: jint _count; duke@435: const char* _name; duke@435: duke@435: public: duke@435: HistogramElement(); duke@435: virtual int count(); duke@435: virtual const char* name(); duke@435: virtual void increment_count(); duke@435: void print_on(outputStream* st) const; duke@435: virtual int compare(HistogramElement* e1,HistogramElement* e2); duke@435: }; duke@435: zgu@3900: class Histogram : public CHeapObj { duke@435: protected: duke@435: GrowableArray* _elements; duke@435: GrowableArray* elements() { return _elements; } duke@435: const char* _title; duke@435: const char* title() { return _title; } duke@435: static int sort_helper(HistogramElement** e1,HistogramElement** e2); duke@435: virtual void print_header(outputStream* st); duke@435: virtual void print_elements(outputStream* st); duke@435: duke@435: public: duke@435: Histogram(const char* title,int estimatedSize); duke@435: virtual void add_element(HistogramElement* element); duke@435: void print_on(outputStream* st) const; duke@435: }; duke@435: duke@435: #endif stefank@2314: stefank@2314: #endif // SHARE_VM_UTILITIES_HISTOGRAM_HPP