KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > diagnostics > Profiler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Profiler.java
26  *
27  * Created on September 17, 2001, 12:42 PM
28  */

29
30 package com.sun.enterprise.util.diagnostics;
31
32 import java.util.*;
33 import com.sun.enterprise.util.diagnostics.Reporter;
34 import com.sun.enterprise.util.StringUtils;
35 /**
36  * A easy-to-use class that wraps one global ProfilerImpl object. Use it to begin
37  * and end profiling in one 'profiling thread'. I.e. use this object to get timing for
38  * sub-operations. Use separate ProfilerImpl objects to get timings for overlapping
39  * profile needs.
40  *
41  * <p> WARNING: Call reset at the end to avoid memory leaks.
42  *
43  * @author bnevins
44  * @version
45  */

46
47 public class Profiler
48 {
49     private Profiler()
50     {
51     }
52     /** Reset the global ProfilerImpl instance.
53      **/

54     public static void reset()
55     {
56         profiler.reset();
57     }
58     /** Start timing an item.
59      **/

60     public static void beginItem()
61     {
62         profiler.beginItem();
63     }
64     /** Start timing an item.
65      * @param desc - Descriptive text for the item
66      */

67     public static void beginItem(String JavaDoc desc)
68     {
69         profiler.beginItem(desc);
70     }
71     /** Stop timing of the latest item
72      */

73     public static void endItem()
74     {
75         profiler.endItem();
76     }
77     /** return a String report of all the timings
78      * @return */

79     public static String JavaDoc report()
80     {
81         return profiler.toString();
82     }
83     
84     ////////////////////////////////////////////////////////////////////////////
85

86     /**
87      * @param notUsed */

88     public static void main(String JavaDoc[] notUsed)
89     {
90         try
91         {
92             profiler.beginItem("first item");
93             Thread.sleep(3000);
94             profiler.beginItem("second item here dude whoa yowser yowser");
95             Thread.sleep(1500);
96             profiler.endItem();
97             profiler.endItem();
98             System.out.println("" + profiler);
99         }
100         catch(Exception JavaDoc e)
101         {
102         }
103     }
104     
105     static ProfilerImpl profiler = new ProfilerImpl();
106 }
107
Popular Tags