1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/histogram.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,115 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_UTILITIES_HISTOGRAM_HPP 1.29 +#define SHARE_VM_UTILITIES_HISTOGRAM_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "runtime/os.hpp" 1.33 +#include "utilities/growableArray.hpp" 1.34 +#ifdef TARGET_OS_FAMILY_linux 1.35 +# include "os_linux.inline.hpp" 1.36 +#endif 1.37 +#ifdef TARGET_OS_FAMILY_solaris 1.38 +# include "os_solaris.inline.hpp" 1.39 +#endif 1.40 +#ifdef TARGET_OS_FAMILY_windows 1.41 +# include "os_windows.inline.hpp" 1.42 +#endif 1.43 +#ifdef TARGET_OS_FAMILY_aix 1.44 +# include "os_aix.inline.hpp" 1.45 +#endif 1.46 +#ifdef TARGET_OS_FAMILY_bsd 1.47 +# include "os_bsd.inline.hpp" 1.48 +#endif 1.49 + 1.50 +// This class provides a framework for collecting various statistics. 1.51 +// The current implementation is oriented towards counting invocations 1.52 +// of various types, but that can be easily changed. 1.53 +// 1.54 +// To use it, you need to declare a Histogram*, and a subtype of 1.55 +// HistogramElement: 1.56 +// 1.57 +// HistogramElement* MyHistogram; 1.58 +// 1.59 +// class MyHistogramElement : public HistogramElement { 1.60 +// public: 1.61 +// MyHistogramElement(char* name); 1.62 +// }; 1.63 +// 1.64 +// MyHistogramElement::MyHistogramElement(char* elementName) { 1.65 +// _name = elementName; 1.66 +// 1.67 +// if(MyHistogram == NULL) 1.68 +// MyHistogram = new Histogram("My Call Counts",100); 1.69 +// 1.70 +// MyHistogram->add_element(this); 1.71 +// } 1.72 +// 1.73 +// #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count() 1.74 +// 1.75 +// This gives you a simple way to count invocations of specfic functions: 1.76 +// 1.77 +// void a_function_that_is_being_counted() { 1.78 +// MyCountWrapper("FunctionName"); 1.79 +// ... 1.80 +// } 1.81 +// 1.82 +// To print the results, invoke print() on your Histogram*. 1.83 + 1.84 +#ifdef ASSERT 1.85 + 1.86 +class HistogramElement : public CHeapObj<mtInternal> { 1.87 + protected: 1.88 + jint _count; 1.89 + const char* _name; 1.90 + 1.91 + public: 1.92 + HistogramElement(); 1.93 + virtual int count(); 1.94 + virtual const char* name(); 1.95 + virtual void increment_count(); 1.96 + void print_on(outputStream* st) const; 1.97 + virtual int compare(HistogramElement* e1,HistogramElement* e2); 1.98 +}; 1.99 + 1.100 +class Histogram : public CHeapObj<mtInternal> { 1.101 + protected: 1.102 + GrowableArray<HistogramElement*>* _elements; 1.103 + GrowableArray<HistogramElement*>* elements() { return _elements; } 1.104 + const char* _title; 1.105 + const char* title() { return _title; } 1.106 + static int sort_helper(HistogramElement** e1,HistogramElement** e2); 1.107 + virtual void print_header(outputStream* st); 1.108 + virtual void print_elements(outputStream* st); 1.109 + 1.110 + public: 1.111 + Histogram(const char* title,int estimatedSize); 1.112 + virtual void add_element(HistogramElement* element); 1.113 + void print_on(outputStream* st) const; 1.114 +}; 1.115 + 1.116 +#endif 1.117 + 1.118 +#endif // SHARE_VM_UTILITIES_HISTOGRAM_HPP