W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
java.lang.Object
|---ohos.utils.Stopwatch
public final class Stopwatch
extends Object
提供秒表功能來記錄從主任務(wù)拆分出來的子任務(wù)的執(zhí)行情況,并使用 HiLog 將記錄保存在調(diào)試級(jí)日志中。
示例代碼:
Stopwatch stopwatch = new Stopwatch(label, "main task");
// Records the completion time of subtask A split from the main task.
stopwatch.split("sub task A");
// Records the completion time of subtask B split from the main task.
stopwatch.split("sub task B");
// Records the completion time of subtask C split from the main task.
stopwatch.split("sub task C");
stopwatch.writeLog();
以下記錄被寫入日志:
8186 D 00000/StopwatchDemo: main task: begin
8186 D 00000/StopwatchDemo: main task: 11 ms, 11%, sub task A
8186 D 00000/StopwatchDemo: main task: 76 ms, 76%, sub task B
8186 D 00000/StopwatchDemo: main task: 13 ms, 13%, sub task C
8186 D 00000/StopwatchDemo: main task: end 100 ms
構(gòu)造函數(shù) | 描述 |
---|---|
Stopwatch(HiLogLabel label, String taskName) | 創(chuàng)建秒表記錄器。 |
修飾符和類型 | 方法 | 描述 |
---|---|---|
void | reset() | 重置秒表記錄器。 |
void | split(String subtaskName) | 記錄從主任務(wù)拆分出來的子任務(wù)的完成時(shí)間。 |
void | writeLog() | 將秒表記錄器中的記錄寫入 HiLog 中定義的調(diào)試級(jí)別日志。 |
從類 java.lang.Object 繼承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
public Stopwatch(HiLogLabel label, String taskName)
創(chuàng)建秒表記錄器。
建議您為每個(gè)主要任務(wù)創(chuàng)建一個(gè)秒表記錄器。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
label | 表示 HiLog 標(biāo)簽。 |
taskName | 表示任務(wù)名稱。 |
public void split(String subtaskName)
記錄從主任務(wù)拆分出來的子任務(wù)的完成時(shí)間。
該方法在子任務(wù)執(zhí)行后調(diào)用。 Stopwatch#writeLog() 使用記錄的時(shí)間來計(jì)算子任務(wù)執(zhí)行的持續(xù)時(shí)間。
參數(shù):
參數(shù)名稱 | 參數(shù)描述 |
---|---|
subtaskName | 表示子任務(wù)名稱。 |
public void reset()
重置秒表記錄器。
如果主任務(wù)需要重復(fù)執(zhí)行,調(diào)用此方法重置秒表記錄器。 重置后,所有歷史記錄將被清除。
public void writeLog()
將秒表記錄器中的記錄寫入 HiLog 中定義的調(diào)試級(jí)別日志。
注意:此方法不會(huì)清除歷史記錄,歷史記錄也會(huì)寫入日志。 要清除歷史記錄,請(qǐng)調(diào)用 Stopwatch#reset()。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: