How to profile Native JNI library

徘徊边缘 提交于 2019-12-24 09:17:53

问题


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

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.


回答1:


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. 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

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

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



来源:https://stackoverflow.com/questions/14752459/how-to-profile-native-jni-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!