1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/histogram.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Copyright 1998-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_histogram.cpp.incl" 1.30 + 1.31 +#ifdef ASSERT 1.32 + 1.33 +////////////////// HistogramElement //////////////////////// 1.34 + 1.35 +HistogramElement::HistogramElement() { 1.36 + _count = 0; 1.37 +} 1.38 + 1.39 +int HistogramElement::count() { 1.40 + return _count; 1.41 +} 1.42 + 1.43 +const char* HistogramElement::name() { 1.44 + return _name; 1.45 +} 1.46 + 1.47 +void HistogramElement::increment_count() { 1.48 + // We can't use the accessor :-(. 1.49 + Atomic::inc(&_count); 1.50 +} 1.51 + 1.52 +int HistogramElement::compare(HistogramElement* e1,HistogramElement* e2) { 1.53 + if(e1->count() > e2->count()) { 1.54 + return -1; 1.55 + } else if(e1->count() < e2->count()) { 1.56 + return 1; 1.57 + } 1.58 + return 0; 1.59 +} 1.60 + 1.61 +void HistogramElement::print_on(outputStream* st) const { 1.62 + st->print("%10d ",((HistogramElement*)this)->count()); 1.63 + st->print_cr("%s",((HistogramElement*)this)->name()); 1.64 +} 1.65 + 1.66 +////////////////// Histogram //////////////////////// 1.67 + 1.68 +int Histogram::sort_helper(HistogramElement** e1, HistogramElement** e2) { 1.69 + return (*e1)->compare(*e1,*e2); 1.70 +} 1.71 + 1.72 +Histogram::Histogram(const char* title,int estimatedCount) { 1.73 + _title = title; 1.74 + _elements = new (ResourceObj::C_HEAP) GrowableArray<HistogramElement*>(estimatedCount,true); 1.75 +} 1.76 + 1.77 +void Histogram::add_element(HistogramElement* element) { 1.78 + // Note, we need to add locking ! 1.79 + elements()->append(element); 1.80 +} 1.81 + 1.82 +void Histogram::print_header(outputStream* st) { 1.83 + st->print_cr("%s",title()); 1.84 + st->print_cr("--------------------------------------------------"); 1.85 +} 1.86 + 1.87 +void Histogram::print_elements(outputStream* st) { 1.88 + elements()->sort(Histogram::sort_helper); 1.89 + jint total = 0; 1.90 + for(int i=0; i < elements()->length(); i++) { 1.91 + elements()->at(i)->print(); 1.92 + total += elements()->at(i)->count(); 1.93 + } 1.94 + st->print("%10d ", total); 1.95 + st->print_cr("Total"); 1.96 +} 1.97 + 1.98 +void Histogram::print_on(outputStream* st) const { 1.99 + ((Histogram*)this)->print_header(st); 1.100 + ((Histogram*)this)->print_elements(st); 1.101 +} 1.102 + 1.103 +#endif