java -agentlib:hprof详细说明

    -agentlib:hprof是堆内存和C的抽样代理工具,在控制台执行java -agentlib:hprof=help可以看到详细的使用说明,如下:

选项的key和value  描述                    默认值
---------------------  -----------                    -------
heap=dump|sites|all    堆内存使用抽样                 all
cpu=samples|times|old  CPU使用情况                      off
monitor=y|n            monitor contention             n
format=a|b             text(txt) or binary output     a
file=<file>            write data to file             java.hprof[{.txt}]
net=<host>:<port>      send data over a socket        off
depth=<size>           栈跟踪深度              4
interval=<ms>          抽样间隔时间ms          10
cutoff=<value>         output cutoff point            0.0001
lineno=y|n             line number in traces?         y
thread=y|n             thread in traces?              n
doe=y|n                dump on exit?                  y
msa=y|n                Solaris micro state accounting n
force=y|n              force output to <file>         y
verbose=y|n            print messages about dumps     y

废弃选项
----------------
gc_okay=y|n

举例:

a) 每20ms获取CUP抽样信息,跟踪3层堆栈

java -agentlib:hprof=cpu=samples,interval=20,depth=3 classname

b)  基于allocation sites方式的内存分配
java -agentlib:hprof=heap=sites classname

c) 命令行启动参数

备注:

format=b不能和monitor=y一起使用

format=b不能和cpu=old|times一起使用

 java -Xrunhprof:[help]|[<option>=<value>, ...]使用方式和 java -agentlib:hprof=[help]|[<option>=<value>, ...]操作结果是一样的

申明:

这种方式只是JVMTI接口的示范性代码,是BCI的使用方式,不是官方的product或者标准JDK部分

-Xrunhprof接口会在未来的release版本中移除

format=b是试验性的处理格式,可能会在未来的release版本中修改

实践:

通过java -agentlib:hprof=heap=sites classname方式执行时,classname是编译后的class类名,才能得到预期的执行结果。

CPU TIME (ms) BEGIN (total = 11094) Wed Nov  9 15:17:55 2016
rank   self  accum   count trace method
   1 90.14% 90.14%       1 301243 HProfTest.slowerMethod
   2  9.01% 99.15%       1 301244 HProfTest.slowMethod

   3  0.04% 99.19%       1 300163 java.lang.invoke.MethodHandle.<clinit>
   4  0.03% 99.22%       9 300421 java.io.UnixFileSystem.normalize
   5  0.03% 99.24%       6 300837 sun.misc.PerfCounter.<init>
   6  0.02% 99.26%      26 300053 java.lang.String.hashCode
   7  0.02% 99.28%      10 300316 sun.net.util.URLUtil.urlNoFragString

 

参考资料:

原文链接:http://www.jianshu.com/p/6df2963fe94e

转载于:https://my.oschina.net/u/914290/blog/784774

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值