src/share/vm/utilities/histogram.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/histogram.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,91 @@
     1.4 +/*
     1.5 + * Copyright 1998-2000 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 +// This class provides a framework for collecting various statistics.
    1.29 +// The current implementation is oriented towards counting invocations
    1.30 +// of various types, but that can be easily changed.
    1.31 +//
    1.32 +// To use it, you need to declare a Histogram*, and a subtype of
    1.33 +// HistogramElement:
    1.34 +//
    1.35 +//  HistogramElement* MyHistogram;
    1.36 +//
    1.37 +//  class MyHistogramElement : public HistogramElement {
    1.38 +//    public:
    1.39 +//      MyHistogramElement(char* name);
    1.40 +//  };
    1.41 +//
    1.42 +//  MyHistogramElement::MyHistogramElement(char* elementName) {
    1.43 +//    _name = elementName;
    1.44 +//
    1.45 +//    if(MyHistogram == NULL)
    1.46 +//      MyHistogram = new Histogram("My Call Counts",100);
    1.47 +//
    1.48 +//    MyHistogram->add_element(this);
    1.49 +//  }
    1.50 +//
    1.51 +//  #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count()
    1.52 +//
    1.53 +// This gives you a simple way to count invocations of specfic functions:
    1.54 +//
    1.55 +// void a_function_that_is_being_counted() {
    1.56 +//   MyCountWrapper("FunctionName");
    1.57 +//   ...
    1.58 +// }
    1.59 +//
    1.60 +// To print the results, invoke print() on your Histogram*.
    1.61 +
    1.62 +#ifdef ASSERT
    1.63 +
    1.64 +class HistogramElement : public CHeapObj {
    1.65 + protected:
    1.66 +  jint _count;
    1.67 +  const char* _name;
    1.68 +
    1.69 + public:
    1.70 +  HistogramElement();
    1.71 +  virtual int count();
    1.72 +  virtual const char* name();
    1.73 +  virtual void increment_count();
    1.74 +  void print_on(outputStream* st) const;
    1.75 +  virtual int compare(HistogramElement* e1,HistogramElement* e2);
    1.76 +};
    1.77 +
    1.78 +class Histogram : public CHeapObj {
    1.79 + protected:
    1.80 +  GrowableArray<HistogramElement*>* _elements;
    1.81 +  GrowableArray<HistogramElement*>* elements() { return _elements; }
    1.82 +  const char* _title;
    1.83 +  const char* title() { return _title; }
    1.84 +  static int sort_helper(HistogramElement** e1,HistogramElement** e2);
    1.85 +  virtual void print_header(outputStream* st);
    1.86 +  virtual void print_elements(outputStream* st);
    1.87 +
    1.88 + public:
    1.89 +  Histogram(const char* title,int estimatedSize);
    1.90 +  virtual void add_element(HistogramElement* element);
    1.91 +  void print_on(outputStream* st) const;
    1.92 +};
    1.93 +
    1.94 +#endif

mercurial