Java Doc for Stopwatch.java in  » Profiler » stopwatch » com » commsen » stopwatch » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Profiler » stopwatch » com.commsen.stopwatch 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.commsen.stopwatch.Stopwatch

Stopwatch
public class Stopwatch (Code)
Stopwatch allows you to measure performance of any given piece of code. It's basic usage is as follows:
 .....
 long swId = Stopwatch.start("group", "label");
 // some code to be measured
 Stopwatch.stop(swId);
 ....
 
To skip already started mensuration (for example if an Exception is thrown) something similar to following code may be used:
 .....
 long swId = Stopwatch.start("group", "label");
 try {
 // some code to be measured
 } catch (Exception) { 
 Stopwatch.skip(swId);
 } finally {
 Stopwatch.stop(swId);
 }
 ....
 

By default Stopwatch is not active! It means all calls to Stopwatch.start(String,String) , Stopwatch.skip(long) and Stopwatch.stop(long) methods are simply ignored. To activate Stopwatch do one of the following:

  • explicitly call Stopwatch.setActive(true)
  • pass -Dcom.commsen.stopwatch.activeOnStart=true JVM parameter
  • create "stopwatch.properties" file on classpath and set activeOnStart=true
Stopwatch can also be activated/deactivated at runtime via JMX, RMI, etc.


author:
   Milen Dyankov


Field Summary
final public static  StringDEFAULT_ENGINE
    
final public static  intDEFAULT_MODE
    
final public static  StringDEFAULT_STORAGE
    
final public static  StringPROPERTY_ACTIVE
    
final public static  StringPROPERTY_DEBUG
    
final public static  StringPROPERTY_ENGINE
    
final public static  StringPROPERTY_JMX_MANAGED
    
final public static  StringPROPERTY_MBEAN_SERVER_NAME
    
final public static  StringPROPERTY_MODE
    
final public static  StringPROPERTY_STORAGE
    
final public static  StringSYSTEM_PROPERTIES_PREFIX
    


Method Summary
public static  Report[]getAllByGroupReports()
    
public static  Report[]getAllByLabelReports()
    
public static  Report[]getAllReports()
    
public static  StringgetEngineClass()
    
public static  long[]getGroupLoad(String group, int periodField, int numberOfPeriods)
     Returns information of how many instances of any masured code in group group ware running for the last numberOfPeriods periods.
public static  Report[]getGroupReports(String group)
    
public static  long[]getLabelLoad(String label, int periodField, int numberOfPeriods)
     Returns information of how many instances of any masured code labeled label ware running for the last numberOfPeriods periods.
public static  Report[]getLabelReports(String label)
    
public static  long[]getLoad(int periodField, int numberOfPeriods)
     Returns information of how many instances of any masured code ware running for the last numberOfPeriods periods.
public static  long[]getLoad(String group, String label, int periodField, int numberOfPeriods)
     Returns information of how many instances of any masured code in group gropup labeled label ware running for the last numberOfPeriods periods.
public static  StringgetPersistenceMode()
    
public static  StringgetProperty(String key, String defaultValue)
    
public static  ReportgetSingleReport(String group, String label)
    
public static  StringgetStorageClass()
    
public static  booleanisActive()
     Called to check if Stopwatch is active.
public static  booleanisDebugEnabled()
     Called to check if Stopwatch should produce debug information.
public static  voidreset()
    
public static  voidsetActive(boolean active)
     This method changes stopwatch's status Should be used to activate/inactivate Stopwatch at runtime.
public static  voidsetDebugEnabled(boolean debugEnabled)
     Used to disable/enable Stopwatch's debug information. The reason for this method to exist is to be able to minimize the performance impact Stopwatch may have on the measured application.
public static  voidskip(long id)
     Skip mensuration with id id. Method should be called if for some reason current mensuration should be skipped. Default stopwatch engine will delete any information related to this id but other engines may behave differently (for example to provide a "skipped mensurations" report).
public static  longstart(String group, String label)
     Start new mensuration.
public static  voidstop(long id)
     Stop mensuration with id id.

Field Detail
DEFAULT_ENGINE
final public static String DEFAULT_ENGINE(Code)



DEFAULT_MODE
final public static int DEFAULT_MODE(Code)



DEFAULT_STORAGE
final public static String DEFAULT_STORAGE(Code)



PROPERTY_ACTIVE
final public static String PROPERTY_ACTIVE(Code)



PROPERTY_DEBUG
final public static String PROPERTY_DEBUG(Code)



PROPERTY_ENGINE
final public static String PROPERTY_ENGINE(Code)



PROPERTY_JMX_MANAGED
final public static String PROPERTY_JMX_MANAGED(Code)



PROPERTY_MBEAN_SERVER_NAME
final public static String PROPERTY_MBEAN_SERVER_NAME(Code)



PROPERTY_MODE
final public static String PROPERTY_MODE(Code)



PROPERTY_STORAGE
final public static String PROPERTY_STORAGE(Code)



SYSTEM_PROPERTIES_PREFIX
final public static String SYSTEM_PROPERTIES_PREFIX(Code)





Method Detail
getAllByGroupReports
public static Report[] getAllByGroupReports()(Code)



getAllByLabelReports
public static Report[] getAllByLabelReports()(Code)



getAllReports
public static Report[] getAllReports()(Code)
Generates an array of reports which contains exectly 1 element for each combination of group and label If there is no enough data to produce reports, this method returns null array of reports of null.



getEngineClass
public static String getEngineClass()(Code)



getGroupLoad
public static long[] getGroupLoad(String group, int periodField, int numberOfPeriods)(Code)
Returns information of how many instances of any masured code in group group ware running for the last numberOfPeriods periods. Period length is defined by periodField which can be one of java.util.Calendar.FIELD_NAME

For example to see how many peaces of masured code in group g1 were running per day for the last 10 days, one could use:

 long[] load = Stopwatch.getLoad(
java.util.Calendar.DAY_OF_MONTH , 10);
 
In this case load[0] will contain the number of code instances running 10 days ago and load[9] number of code instances running today.
Parameters:
  group - the group for which report should be generated
Parameters:
  periodField - can be one of java.util.Calendar.FIELD_NAME
Parameters:
  numberOfPeriods - number of periods array of length numberOfPeriods where every element represents the load for given pariod.



getGroupReports
public static Report[] getGroupReports(String group)(Code)
Generates an array of reports which contains exectly 1 element for each group If there is no enough data to produce the report, this method returns null
Parameters:
  group - the group for which report should be generated array of reports of null.



getLabelLoad
public static long[] getLabelLoad(String label, int periodField, int numberOfPeriods)(Code)
Returns information of how many instances of any masured code labeled label ware running for the last numberOfPeriods periods. Period length is defined by periodField which can be one of java.util.Calendar.FIELD_NAME

For example to see how many peaces of masured code labeled l1 were running per second for the last 15 seconds, one could use:

 long[] load = Stopwatch.getLoad(
java.util.Calendar.SECOND , 15);
 
In this case load[0] will contain the number of code instances running 15 seconds ago and load[14] number of code instances running in the last second.
Parameters:
  label - the label for which report should be generated
Parameters:
  periodField - can be one of java.util.Calendar.FIELD_NAME
Parameters:
  numberOfPeriods - number of periods array of length numberOfPeriods where every element represents the load for given pariod.



getLabelReports
public static Report[] getLabelReports(String label)(Code)
Generates an array of reports which contains exectly 1 element for each label If there is no enough data to produce the report, this method returns null
Parameters:
  label - the label for which report should be generated array of reports or null.



getLoad
public static long[] getLoad(int periodField, int numberOfPeriods)(Code)
Returns information of how many instances of any masured code ware running for the last numberOfPeriods periods. Period length is defined by periodField which can be one of java.util.Calendar.FIELD_NAME

For example to see how many peaces of masured code were running per minute for the last 30 minutes, one could use:

 long[] load = Stopwatch.getLoad(
java.util.Calendar.MINUTE , 30);
 
In this case load[0] will contain the number of code instances running 30 minutes ago and load[29] number of code instances running in the last minute.
Parameters:
  periodField - can be one of java.util.Calendar.FIELD_NAME
Parameters:
  numberOfPeriods - number of periods array of length numberOfPeriods where every element represents the load for given pariod.



getLoad
public static long[] getLoad(String group, String label, int periodField, int numberOfPeriods)(Code)
Returns information of how many instances of any masured code in group gropup labeled label ware running for the last numberOfPeriods periods. Period length is defined by periodField which can be one of java.util.Calendar.FIELD_NAME

For example to see how many peaces of masured code in group g1 labeled l1 were running per second for the last 3 weeks, one could use:

 long[] load = Stopwatch.getLoad(
java.util.Calendar.WEEK_OF_YEAR , 3);
 
In this case load[0] will contain the number of code instances running 3 weeks ago and load[2] number of code instances running in the last week.
Parameters:
  group - the group for which report should be generated
Parameters:
  label - the label for which report should be generated
Parameters:
  periodField - can be one of java.util.Calendar.FIELD_NAME
Parameters:
  numberOfPeriods - number of periods array of length numberOfPeriods where every element represents the load for given pariod.



getPersistenceMode
public static String getPersistenceMode()(Code)



getProperty
public static String getProperty(String key, String defaultValue)(Code)
Tries to get the value of property key
Parameters:
  key -
Parameters:
  defaultValue - the value of property key of defaultValue if property not found.



getSingleReport
public static Report getSingleReport(String group, String label)(Code)
Generates a single report for provided group and label If there is no enough data to produce the report, this method returns null
Parameters:
  group - the group for which report should be generated
Parameters:
  label - the label for which report should be generated single report for provided group and label of null.



getStorageClass
public static String getStorageClass()(Code)



isActive
public static boolean isActive()(Code)
Called to check if Stopwatch is active. When this method returns false all calls to Stopwatch.start(String,String) and Stopwatch.stop(long) are ignored. Returns the Stopwatch's status.



isDebugEnabled
public static boolean isDebugEnabled()(Code)
Called to check if Stopwatch should produce debug information.
See Also:   Stopwatch.setDebugEnabled(boolean)
See Also:    Returns the true or false



reset
public static void reset()(Code)



setActive
public static void setActive(boolean active)(Code)
This method changes stopwatch's status Should be used to activate/inactivate Stopwatch at runtime.
Parameters:
  active - the Stopwatch's status.



setDebugEnabled
public static void setDebugEnabled(boolean debugEnabled)(Code)
Used to disable/enable Stopwatch's debug information. The reason for this method to exist is to be able to minimize the performance impact Stopwatch may have on the measured application. Generating debug info consumes additional CPU units, which may become a problem if Stopwatch is heavily used. Setting this to false (is is false by default) will cause no debug info being generated by Stopwatch even when log4j's level is set to DEBUG.
Parameters:
  debugEnabled - should debug information be generated



skip
public static void skip(long id)(Code)
Skip mensuration with id id. Method should be called if for some reason current mensuration should be skipped. Default stopwatch engine will delete any information related to this id but other engines may behave differently (for example to provide a "skipped mensurations" report). This method will do nothing if Stopwatch is not active or mensuration has been stopped already.
Parameters:
  id - which mensuration to stop



start
public static long start(String group, String label)(Code)
Start new mensuration. This method will do nothing and simply return a negative long if Stopwatch is not active.
Parameters:
  group - the name of the group this mensuration should be placed in
Parameters:
  label - how this mensuration should be labeled Unique ID representing current mensuration.



stop
public static void stop(long id)(Code)
Stop mensuration with id id. This method will do nothing if Stopwatch is not active or mensuration has been skipped already.
Parameters:
  id - which mensuration to stop



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.