alibaba / TProfiler

TProfiler是一个可以在生产环境长期使用的性能分析工具
GNU General Public License v2.0
2.38k stars 923 forks source link

能够将java进程的pid加入到log文件的文件名中? #14

Closed haoweishow closed 11 years ago

haoweishow commented 11 years ago

step1:修改profile.properties文件中的日志文件格式,增加,程序中会将替换为实际的pid logFilePath = E:/Dropbox/code/javaworkspace/jvmDemo/src/tprofiler.log methodFilePath = E:/Dropbox/code/javaworkspace/jvmDemo/src/tmethod.log samplerFilePath = E:/Dropbox/code/javaworkspace/jvmDemo/src/tsampler.log

step2:在Manager.java中增加下面两个方法 private void initPID(){ String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); pid = processName.split("@")[0]; } public String getPID(){ if(pid==null){ this.initPID(); } return pid; }

step3:修改ProfConfig.java中下面三个方法 public void setLogFilePath(String logFilePath) { this.logFilePath = logFilePath.replace("", Manager.instance().getPID()); } public void setMethodFilePath(String methodFilePath) { this.methodFilePath = methodFilePath.replace("", Manager.instance().getPID()); } public void setSamplerFilePath(String samplerFilePath) { this.samplerFilePath = samplerFilePath.replace("", Manager.instance().getPID()); }

step4:输出日志文件名: tprofiler_5728.log tsampler_5728.log

jlusdy commented 11 years ago

这个工具还是以分析性能问题为主,不是实时监控类的工具,所以,记录进程ID的作用是?

haoweishow commented 11 years ago

看到wiki里 “TProfiler配置部署”的注意事项中提到,会将记录续写到文件中,而两次采集的日志会导致分析不准确,所以增加个pid这样有助于避免忘记清空上次采集的日志。

这个属于边边角角的改动,可有可无,还请你来定夺。

jlusdy commented 11 years ago

明白你的意思,这么修改非常利于手动操作的情况下使用,多次改参数重新采集。 当参数被确定下来,开始定期采集以后,这个功能就会对数据分析(日志抓取)带来一点麻烦, 所以权衡一下,PID还是不加了,使用的时候注意下就可以规避
感谢你的建议!