public class RunTime extends Object
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()。
Modifier and Type | Field and Description |
---|---|
protected Object |
attachment |
protected String |
description |
protected PutIfAbsentMap<String,RunTime> |
detail |
protected AtomicLong |
firstRunStartTime |
protected static String |
INDENT |
protected long |
lastRunStartTime |
protected BasicNumberStatistics |
statistics |
Constructor and Description |
---|
RunTime()
Construct an instance without description text.
|
RunTime(String description)
Constructor.
构造方法。 |
Modifier and Type | Method and Description |
---|---|
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) |
protected static final String INDENT
protected String description
protected PutIfAbsentMap<String,RunTime> detail
protected Object attachment
protected BasicNumberStatistics statistics
protected AtomicLong firstRunStartTime
protected long lastRunStartTime
public RunTime(String description)
description
- Any text that describes this RunTime.public RunTime()
public void reset()
public RunTime addDetail(String description)
description
- Any text that describes the detailed RunTime.public void addDetail(RunTime child)
child
- an existing record that need to be added as a child.public RunTime getDetail(String description)
description
- description of the detail record.public void start()
The pair of start() and end() must be called from the same thread.
public void startDetail(String desc)
desc
- Description of the detail record.public void endDetail(String desc)
desc
- Description of the detail record.public void end()
The pair of start() and end() must be called from the same thread.
public void add(long milliStartTime, long nanoDurationTime)
milliStartTime
- Start time in milliseconds (usually from System.currentTimeMillis())nanoDurationTime
- Run time duration in nanoseconds.public void addDetail(String desc, long milliStartTime, long nanoDurationTime)
desc
- Description of the detail record.milliStartTime
- Start time in milliseconds (usually from System.currentTimeMillis())nanoDurationTime
- Run time duration in nanoseconds.public String toString()
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
public String toString(boolean header)
header
- true - with header row; false - withoutpublic long getTotalRunTime()
public long getFirstRunStartTime()
public long getTotalDuration()
public String getDescription()
public void setDescription(String description)
public Object getAttachment()
public void setAttachment(Object attachment)
attachment
- can be anything.Copyright © 2014. All Rights Reserved.