Smalldok's Tech Blog

穷则变、变则通、通则达


  • 首页

  • 分类

  • 关于

  • 标签

  • 归档

  • 公益 404

  • 搜索

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

| 分类于 源码学习 , MPush , 源码分析 , 功能组件 | 评论数: | 阅读次数:

测试

实现类: 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入门



功能组件文章目录:

  • CC-配置中心
  • EventBus-事件总线
  • FlowControl-流控
  • JVMUtil
  • Logs
  • Profiler-统计方法或者线程执行时间
  • Profiler入门
  • SPI机制
  • TimeLine-时间线
  • 服务启动监听
  • 监控
  • 通信模型与超时控制
  • 线程池
  • 状态判断-位运算
1…404142…100
smalldok

smalldok

JAVA服务端架构,目前方向是微服务落地、基础设施、中间件、DevOps

100 日志
27 分类
17 标签
Links
  • sofa-bolt
  • sofa-rpc
  • dubbo
  • sofa-tracer
  • sofa-boot
  • Sentinel
  • COLA
  • nacos
  • xxl-job
  • apollo
  • sharding-sphere
  • fescar
  • ByteTCC
  • tcc-transaction
  • rocketmq
  • canal
  • arthas
  • jvm-sandbox
  • sofa-lookout
  • disruptor
  • mpush
© 2007 – 2019 smalldok
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Mist v6.7.0