【入门篇】TProfiler工具使用


1、TProfiler下载与安装

第一步先去Github https://github.com/taobao/TProfiler下载源文件,接着将下载好的TProfiler-master.zip解压并打开文件夹,将dist下的TProfiler_1.0.1.zip再解压,最后将TProfiler_1.0.1中的profile.properties、lib/tprofiler-1.0.1.jar 拷贝出来,我们只需要这两个文件即可。

第二步我们看下profile.properties中的每个参数的含义。

第三步,在我们设置好profile.properties相关属性后,将这两个文件拷贝到本地/usr/local/tprofiler/目录下,同时添加jvm启动参数:

        -javaagent:/usr/local/tprofiler-1.0.1.jar 
        -Dprofile.properties=/usr/local/tprofiler/profile.properties 

然后启动相应的tomcat、weblogic等服务器,观察输出没有报错即可。

#基础的一些参数配置,一般使用默认即可
startProfTime = 9:00:00  开始profile的时间点
endProfTime = 23:00:00  结束profile的时间点
eachProfUseTime = 5  profile时间长度(单位秒)
eachProfIntervalTime = 50  两次profile的时间间隔(单位秒)
samplerIntervalTime = 20  两次采样的时间间隔(单位秒)
port = 30033  对外提供服务支持查询的端口号
debugMode = false  是否进入调试模式
needNanoTime = false  是否需要用纳秒记录时间
ignoreGetSetMethod = true  是否忽略采集get/set方法

#下面三个日志的存放路径、名称可以自行设置
logFilePath = /usr/tprofiler/logs/logprofiler.log  (profile log的存放位置)
methodFilePath = /usr/tprofiler/logs/logmethod.log  (method log的存放位置)
samplerFilePath = /usr/tprofiler/logs/logsampler.log   (sampler log的存放位置)

#需要、不需要profile的包路径
excludeClassLoader = org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader  不注入的类加载器(分号分割),使用默认即可
includePackageStartsWith = com.alibaba.fastjson;com.fasterxml.jackson.databind;org.quartz;org.springframework  (进行profile的类包名(分号分割),这里按需求,将项目中需要profile的包名入进来即可)
excludePackageStartsWith = com.taobao.sketch;org.apache.velocity;com.alibaba;com.taobao.forest.domain.dataobject 不进行profile的类包名(分号分割),使用默认即可

2、TProfiler远程操作

Java -cp /usr/local/tprofiler/tprofiler-1.0.1.jar com.taobao.profile.client.TProfilerClient [ip] [port] [command] 

这个命令是用于查看TProfiler的运行情况,ip:TProfiler的机器ip,port:上面配置文件中的port,command:start、stop、status、flushmethod。

其中flushmethod是将运行过程中采集的数据输出到指定目录下。例如输出到/usr/tprofiler/logs/下,如配置文件中的logprofiler.log、logmethod.log、logsampler.log。


3、TProfiler本地数据统计

普通方法、线程统计命令

java -cp /usr/local/tprofiler/tprofiler-1.0.1.jar com.taobao.profile.analysis.SamplerLogAnalysis /usr/tprofiler/logs/logsampler.log /usr/tprofiler/logs/allmethod.log 

/usr/tprofiler/logs/allthread.log 这条命令里,logsampler.log的路径在配置文件中指定,后面两个日志文件是分析统计后的日志输出路径,一个是所有方法的调用情况,另一个是所有线程的运行状态,从类名也可看出,就是对生成的sampler日志进行统计分析。


4、top 统计

java -cp /usr/local/tprofiler/tprofiler-1.0.1.jar com.taobao.profile.analysis.ProfilerLogAnalysis 
#待分析的日志路径
/usr/tprofiler/logs/logprofiler.log /usr/tprofiler/logs/logmethod.log 
#分析后输出日志
/usr/tprofiler/logs/topmethod.log /usr/tprofiler/logs/topobject.log

上面命令中的前两个参数是logprofiler.log、logmethod.log的路径,后面两个参数是分析后所得日志的输出路径。(其中:topmethod.log指调用次数最多的一些方法,topobject指调用次数最多的对象类)

调用该命令后,查看topmethod.log的结构如下:

Tables执行次数平均执行时间全部执行时间
/lib/tpcache/mongodb/MongodbTemplate:getById:14022939089364
/lib/tp/HttpClientTemplate:getForObject:92255399905
/api/module/CacheService:getVideoById:115229079
/api/module/comment/CommentService:getCommentList:130226074
/api/module/comment/dto/CommentListDto::93236
/api/module/comment/CommentController:getCommentList:4622600
/lib/tpcache/cbase/MemcachedTemplate:getProtobuf:448122
/lib/tp/comment/CommentTpDao:comment:6725501

参考:
http://blog.csdn.net/chen7253886/article/details/54091666
http://blog.csdn.net/defonds/article/details/52605670
http://blog.kinval.com/open/taobao-profiler.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值