Skip to content

Commit a38814a

Browse files
committed
#134 fix case
1 parent 35b75d4 commit a38814a

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

vjkit/src/main/java/com/vip/vjtools/vjkit/logging/PerformanceUtil.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ public static void start() {
3535
localTimer.get().start();
3636
}
3737

38+
/**
39+
* 返回开始到现在的时间
40+
*/
41+
public static long duration() {
42+
return localTimer.get().duration();
43+
}
44+
3845
/**
3946
* 记录结束时间
4047
*/
4148
public static long end() {
42-
long duration = localTimer.get().end();
49+
long duration = localTimer.get().duration();
4350
localTimer.remove();
4451
return duration;
4552
}
@@ -51,11 +58,18 @@ public static void start(String key) {
5158
getTimer(key).start();
5259
}
5360

61+
/**
62+
* 记录特定Timer的开始时间
63+
*/
64+
public static long duration(String key) {
65+
return getTimer(key).duration();
66+
}
67+
5468
/**
5569
* 记录特定Timer结束时间,返回耗时
5670
*/
5771
public static long end(String key) {
58-
long duration = getTimer(key).end();
72+
long duration = getTimer(key).duration();
5973
localTimerMap.get().remove(key);
6074
return duration;
6175
}
@@ -178,7 +192,7 @@ public void start() {
178192
start = System.currentTimeMillis();
179193
}
180194

181-
public long end() {
195+
public long duration() {
182196
return System.currentTimeMillis() - start;
183197
}
184198
}

vjkit/src/test/java/com/vip/vjtools/vjkit/logging/PerformanceUtilsTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66
import ch.qos.logback.classic.Logger;
77

88
public class PerformanceUtilsTest {
9-
9+
1010
Logger logger = (Logger) LoggerFactory.getLogger(PerformanceUtilsTest.class);
1111

1212
@Test
1313
public void test() throws InterruptedException {
1414
PerformanceUtil.start();
1515
PerformanceUtil.start("test");
1616
Thread.sleep(1000L);// NOSONAR
17-
System.out.println(Thread.currentThread().getName() + " time cost: " + PerformanceUtil.duration() + "ms");
18-
PerformanceUtil.end();
19-
PerformanceUtil.warn(logger, 0L);
20-
PerformanceUtil.end("test");
21-
System.out.println(Thread.currentThread().getName() + " time cost: " + PerformanceUtil.duration() + "ms");
22-
PerformanceUtil.slowLog(logger, "test", 0L);
17+
18+
PerformanceUtil.endWithSlowLog(logger, 100L);
19+
PerformanceUtil.endWithSlowLog(logger, "test", 100L);
2320
}
24-
21+
2522
}

0 commit comments

Comments
 (0)