MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HrtProfiler.java
1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 /*
19  * HrtStopwatch.java
20  */
21 
22 package utils;
23 
24 import java.io.PrintWriter;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import java.text.DecimalFormat;
28 
32 public class HrtProfiler {
33 
34  static protected final PrintWriter out = new PrintWriter(System.out, true);
35 
36  static protected Map< String, Frame > methods
37  = new TreeMap< String, Frame >();
38 
39  static protected class Frame {
40  int calls;
41  double rtmicros;
42  double ctmicros;
43  }
44 
45  //static public void init(int cap);
46 
47  //static public void close();
48 
49  static public void enter(String name) {
50  HrtStopwatch.pushmark();
51  }
52 
53  static public void leave(String name) {
54  final int t1 = HrtStopwatch.pushmark();
55  final int t0 = t1 - 1;
56  final double rt = HrtStopwatch.rtmicros(t1, t0);
57  final double ct = HrtStopwatch.ctmicros(t1, t0);
58  HrtStopwatch.popmark();
59  HrtStopwatch.popmark();
60  Frame f = methods.get(name);
61  if (f == null) {
62  f = new Frame();
63  Frame g = methods.put(name, f);
64  assert (g == null);
65  }
66  f.calls++;
67  f.rtmicros += rt;
68  f.ctmicros += ct;
69  }
70 
71  static public void report() {
72  out.println("*** HrtProfile Begin ***");
73  out.println("\t#calls \trtmicros \tctmicros \tname");
74  for (Map.Entry< String, Frame > e : methods.entrySet()) {
75  String m = e.getKey();
76  Frame f = e.getValue();
77  DecimalFormat nf = new DecimalFormat("###,###,###,###");
78  out.print("\t" + nf.format(f.calls));
79  out.print("\t" + nf.format(f.rtmicros));
80  out.print("\t" + nf.format(f.ctmicros));
81  out.println("\t" + m);
82  }
83  out.println("*** HrtProfile End ***");
84  }
85 
86  //static public void clear();
87 }