Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/histogram.hpp
32285 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_UTILITIES_HISTOGRAM_HPP25#define SHARE_VM_UTILITIES_HISTOGRAM_HPP2627#include "memory/allocation.hpp"28#include "runtime/os.hpp"29#include "utilities/growableArray.hpp"30#ifdef TARGET_OS_FAMILY_linux31# include "os_linux.inline.hpp"32#endif33#ifdef TARGET_OS_FAMILY_solaris34# include "os_solaris.inline.hpp"35#endif36#ifdef TARGET_OS_FAMILY_windows37# include "os_windows.inline.hpp"38#endif39#ifdef TARGET_OS_FAMILY_aix40# include "os_aix.inline.hpp"41#endif42#ifdef TARGET_OS_FAMILY_bsd43# include "os_bsd.inline.hpp"44#endif4546// This class provides a framework for collecting various statistics.47// The current implementation is oriented towards counting invocations48// of various types, but that can be easily changed.49//50// To use it, you need to declare a Histogram*, and a subtype of51// HistogramElement:52//53// HistogramElement* MyHistogram;54//55// class MyHistogramElement : public HistogramElement {56// public:57// MyHistogramElement(char* name);58// };59//60// MyHistogramElement::MyHistogramElement(char* elementName) {61// _name = elementName;62//63// if(MyHistogram == NULL)64// MyHistogram = new Histogram("My Call Counts",100);65//66// MyHistogram->add_element(this);67// }68//69// #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count()70//71// This gives you a simple way to count invocations of specfic functions:72//73// void a_function_that_is_being_counted() {74// MyCountWrapper("FunctionName");75// ...76// }77//78// To print the results, invoke print() on your Histogram*.7980#ifdef ASSERT8182class HistogramElement : public CHeapObj<mtInternal> {83protected:84jint _count;85const char* _name;8687public:88HistogramElement();89virtual int count();90virtual const char* name();91virtual void increment_count();92void print_on(outputStream* st) const;93virtual int compare(HistogramElement* e1,HistogramElement* e2);94};9596class Histogram : public CHeapObj<mtInternal> {97protected:98GrowableArray<HistogramElement*>* _elements;99GrowableArray<HistogramElement*>* elements() { return _elements; }100const char* _title;101const char* title() { return _title; }102static int sort_helper(HistogramElement** e1,HistogramElement** e2);103virtual void print_header(outputStream* st);104virtual void print_elements(outputStream* st);105106public:107Histogram(const char* title,int estimatedSize);108virtual void add_element(HistogramElement* element);109void print_on(outputStream* st) const;110};111112#endif113114#endif // SHARE_VM_UTILITIES_HISTOGRAM_HPP115116117