net.sf.jabb.util.perf
Class RunTime

java.lang.Object
  extended by net.sf.jabb.util.perf.RunTime

public class RunTime
extends Object

Record of time spent on something.
对某项工作所花时间的记录。

Duration is defined to be the period of time from the beginning to the end of an action. Run Time is defined to be the accumulated duration spent in all working threads. If there is no multi-threading, then Run Time should be the same as Duration.

Duration的定义是某项活动从开始到结束的时间段。 Run Time的定义是所有工作线程的Duration之和。 如果没有多线程处理,则Run Time与Duration是一样的。

start() and end() must be invoked in pair in same thread. But pairs of start() and end() can be invoked in multi-thread environment. add() is equivalent to a pair of start() and end().

start()和end()必须在同一个线程中成对调用。 但是各对start()和end()可以在多线程情况下使用。 add()可以用来代替一对start()和end()。

Author:
Zhengmao HU (James)

Field Summary
protected  Object attachment
           
protected  String description
           
protected  PutOnGetMap<String,RunTime> detail
           
protected  AtomicLong firstRunStartTime
           
protected static String INDENT
           
protected  long lastRunStartTime
           
protected  BasicNumberStatistics statistics
           
 
Constructor Summary
RunTime()
          Construct an instance without description text.
RunTime(String description)
          Constructor.
构造方法。
 
Method Summary
 void add(long milliStartTime, long nanoDurationTime)
          Add one run time.
增加一次RunTime。
 void addDetail(RunTime child)
          Add an existing detail record as a child.
将一条已有的详细记录加为下级。
 RunTime addDetail(String description)
          Create a detail record and add it as a child.
创建一条详细记录并加为下级。
 void addDetail(String desc, long milliStartTime, long nanoDurationTime)
          Add one run time to a specified detail record.
给指定的详细记录增加一次RunTime。
 void end()
          Ends the calculation of run time.
结束计时,它必须与开始计时在同一个线程中被调用。
 void endDetail(String desc)
          Ends the calculation of run time of a detail record.
结束对一个详细记录的计时,它必须与开始计时在同一个线程中被调用。
 Map<String,RunTime> getAllDetail()
           
 Object getAttachment()
           
 String getDescription()
           
 RunTime getDetail(String description)
          Get specified detail record, if it does not exist yet, create it first.
获得指定的详细记录,如果不存在则先创建一个。
 long getFirstRunStartTime()
           
 long getTotalDuration()
          Get the duration. 获得运行期间所跨的时间段。
 long getTotalRunTime()
          Get run time which is the add-up of the run duration of all threads.
获得实际的运行时间,它是所有线程的执行时间之和。
 void reset()
          Reset to initial status.
回复到初始状态。
 void setAttachment(Object attachment)
          Set an object to be attached to this RunTime object.
 void setDescription(String description)
           
 void start()
          Starts the calculation of run time.
 void startDetail(String desc)
          Starts the calculation of run time of a detail record.
开始对一个详细记录的计时,它必须与结束计时在同一个线程中被调用。
 String toString()
          Output to a TAB separated text which can be pasted into Excel.
输出成可以贴进Excel的由TAB分隔的文本。
 String toString(boolean header)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INDENT

protected static final String INDENT
See Also:
Constant Field Values

description

protected String description

detail

protected PutOnGetMap<String,RunTime> detail

attachment

protected Object attachment

statistics

protected BasicNumberStatistics statistics

firstRunStartTime

protected AtomicLong firstRunStartTime

lastRunStartTime

protected long lastRunStartTime
Constructor Detail

RunTime

public RunTime(String description)
Constructor.
构造方法。

Parameters:
description - Any text that describes this RunTime.

RunTime

public RunTime()
Construct an instance without description text. 创建一个description为空的实例。

Method Detail

reset

public void reset()
Reset to initial status.
回复到初始状态。


addDetail

public RunTime addDetail(String description)
Create a detail record and add it as a child.
创建一条详细记录并加为下级。

Parameters:
description - Any text that describes the detailed RunTime.
Returns:
The detailed RunTime created.

addDetail

public void addDetail(RunTime child)
Add an existing detail record as a child.
将一条已有的详细记录加为下级。

Parameters:
child - an existing record that need to be added as a child.

getDetail

public RunTime getDetail(String description)
Get specified detail record, if it does not exist yet, create it first.
获得指定的详细记录,如果不存在则先创建一个。

Parameters:
description - description of the detail record.
这条详细记录的description。
Returns:
The detail record with specified description.
具有指定description的详细记录。

start

public void start()
Starts the calculation of run time.
开始计时,它必须与结束计时在同一个线程中被调用。

The pair of start() and end() must be called from the same thread.


startDetail

public void startDetail(String desc)
Starts the calculation of run time of a detail record.
开始对一个详细记录的计时,它必须与结束计时在同一个线程中被调用。

Parameters:
desc - Description of the detail record.
详细记录的Description

endDetail

public void endDetail(String desc)
Ends the calculation of run time of a detail record.
结束对一个详细记录的计时,它必须与开始计时在同一个线程中被调用。

Parameters:
desc - Description of the detail record.
详细记录的Description

end

public void end()
Ends the calculation of run time.
结束计时,它必须与开始计时在同一个线程中被调用。

The pair of start() and end() must be called from the same thread.


add

public void add(long milliStartTime,
                long nanoDurationTime)
Add one run time.
增加一次RunTime。

Parameters:
milliStartTime - Start time in milliseconds (usually from System.currentTimeMillis())
nanoDurationTime - Run time duration in nanoseconds.

addDetail

public void addDetail(String desc,
                      long milliStartTime,
                      long nanoDurationTime)
Add one run time to a specified detail record.
给指定的详细记录增加一次RunTime。

Parameters:
desc - Description of the detail record.
详细记录的Description
milliStartTime - Start time in milliseconds (usually from System.currentTimeMillis())
nanoDurationTime - Run time duration in nanoseconds.

toString

public String toString()
Output to a TAB separated text which can be pasted into Excel.
输出成可以贴进Excel的由TAB分隔的文本。

The first row is the column headers. Fields in each following line:
第一行是列标题。后续每行的字段如下:

Description with left indent according to hierarchical structure First Run Start Time (in text format, in milliseconds) Run Count Total Duration (in text format, in milliseconds) Total Duration (in nanoseconds) Total Run Time (in text format, in milliseconds) Total Run Time (in nanoseconds) Average Duration (in text format, in milliseconds) Average Duration (in nanoseconds) Minimal Duration (in text format, in milliseconds) Minimal Duration (in nanoseconds) Maximal Duration (in text format, in milliseconds) Maximal Duration (in nanoseconds) Attachment

Overrides:
toString in class Object

toString

public String toString(boolean header)
Parameters:
header - true - with header row; false - without
Returns:
the string represents this object

getTotalRunTime

public long getTotalRunTime()
Get run time which is the add-up of the run duration of all threads.
获得实际的运行时间,它是所有线程的执行时间之和。

Returns:
add-up of the run duration of all threads

getFirstRunStartTime

public long getFirstRunStartTime()

getTotalDuration

public long getTotalDuration()
Get the duration. 获得运行期间所跨的时间段。

Returns:
in nanoseconds

getDescription

public String getDescription()

setDescription

public void setDescription(String description)

getAllDetail

public Map<String,RunTime> getAllDetail()

getAttachment

public Object getAttachment()

setAttachment

public void setAttachment(Object attachment)
Set an object to be attached to this RunTime object.

Parameters:
attachment - can be anything.


Copyright © 2012. All Rights Reserved.