如何分析本机JNI库 [英] How to profile Native JNI library

查看:74
本文介绍了如何分析本机JNI库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何分析用C编写的Java本机接口库?

How can I profile a Java Native Interface library written in C?

我了解通常的C探查器,但是我的问题是如何探查 整个 集,包括对JVM方法的调用,这可能会使程序变慢

I know about the usual C profilers, but my question is how can I profile the whole set including the calls to the JVM methods which might be slowing down the program.

推荐答案

在使用此处提出的一些方法进行了研究和测试之后,我最终使用了sprof.

After some research and testing with some of the methods proposed here I ended up using sprof.

基本上,我按照此答案中可用的说明进行操作.一些评论:

Basically I followed the instructions available in this answer. Some comments:

  1. 为了在/var/tmp/中获得结果,我必须将LD_PROFILE_OUTPUT留空,否则不会生成输出文件.
  2. 我分配了LD_PROFILE=libXXXX.so
  1. I had to leave LD_PROFILE_OUTPUT empty in order to get the result in /var/tmp/, otherwise the output file was not generated.
  2. I assigned LD_PROFILE=libXXXX.so

要获取配置文件,我运行了Java代码,该代码加载并使用了本机JNI库,并且我得到了一个带有分析结果的文件:

To get the profile I ran the Java code which loads and uses the native JNI library and I got a file with the profiling results in:

/var/tmp/libXXXX.so.profile

拥有文件后,您可以使用以下命令读取文件:

Once you have the file you can read it using the command:

sprof /path/to/libXXXX.so /var/tmp/libXXXX.so.profile

分析结果遵循与gprof相同的模板. 在这里,您可以找到有关内容的说明,他们的意思.

The results of the profiling follow the same template as gprof. Here you can find a description of the contents and their meaning.

这篇关于如何分析本机JNI库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆