File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed
main/java/com/vip/vjtools/vjkit/logging
test/java/com/vip/vjtools/vjkit/logging Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,18 @@ public static void start() {
35
35
localTimer .get ().start ();
36
36
}
37
37
38
+ /**
39
+ * 返回开始到现在的时间
40
+ */
41
+ public static long duration () {
42
+ return localTimer .get ().duration ();
43
+ }
44
+
38
45
/**
39
46
* 记录结束时间
40
47
*/
41
48
public static long end () {
42
- long duration = localTimer .get ().end ();
49
+ long duration = localTimer .get ().duration ();
43
50
localTimer .remove ();
44
51
return duration ;
45
52
}
@@ -51,11 +58,18 @@ public static void start(String key) {
51
58
getTimer (key ).start ();
52
59
}
53
60
61
+ /**
62
+ * 记录特定Timer的开始时间
63
+ */
64
+ public static long duration (String key ) {
65
+ return getTimer (key ).duration ();
66
+ }
67
+
54
68
/**
55
69
* 记录特定Timer结束时间,返回耗时
56
70
*/
57
71
public static long end (String key ) {
58
- long duration = getTimer (key ).end ();
72
+ long duration = getTimer (key ).duration ();
59
73
localTimerMap .get ().remove (key );
60
74
return duration ;
61
75
}
@@ -178,7 +192,7 @@ public void start() {
178
192
start = System .currentTimeMillis ();
179
193
}
180
194
181
- public long end () {
195
+ public long duration () {
182
196
return System .currentTimeMillis () - start ;
183
197
}
184
198
}
Original file line number Diff line number Diff line change 6
6
import ch .qos .logback .classic .Logger ;
7
7
8
8
public class PerformanceUtilsTest {
9
-
9
+
10
10
Logger logger = (Logger ) LoggerFactory .getLogger (PerformanceUtilsTest .class );
11
11
12
12
@ Test
13
13
public void test () throws InterruptedException {
14
14
PerformanceUtil .start ();
15
15
PerformanceUtil .start ("test" );
16
16
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 );
23
20
}
24
-
21
+
25
22
}
You can’t perform that action at this time.
0 commit comments