Profiler-统计方法或者线程执行时间

测试

实现类: Profiler.java
这两个类中打断点

  • AdminHandler.java
  • ServerChannelHandler.java

测试Profiler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class ProfilerTest {
//10ms
long profile_slowly_limit = CC.mp.monitor.profile_slowly_duration.toMillis();
@Test
public void testProfiler() throws Exception {
byte cmd = 1;
try {
Profiler.enable(true);
Profiler.start("time cost on [channel read]: %s", "111111");

Profiler.enter("time cost on [A]");
Thread.sleep(300);
Profiler.release();

Profiler.enter("time cost on [B]");
Thread.sleep(500);
Profiler.release();

Profiler.enter("time cost on [C]");
Thread.sleep(200);
Profiler.release();

Thread.sleep(400);
}finally {
Profiler.release();
if (Profiler.getDuration() > profile_slowly_limit) {
System.out.println(Profiler.dump());
}
Profiler.reset();
}
}
}

输出:

1
2
3
4
0 [1,400ms (400ms), 100%] - time cost on [channel read]:
+---0 [300ms, 21%, 21%] - time cost on [A]
+---300 [500ms, 36%, 36%] - time cost on [B]
`---800 [200ms, 14%, 14%] - time cost on [C]

Profiler入门

Profiler入门



功能组件文章目录:

------ 本文结束 感谢您的阅读 ------