Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice requested: Java usage #346

Closed
robfig opened this issue Mar 28, 2018 · 8 comments
Closed

Advice requested: Java usage #346

robfig opened this issue Mar 28, 2018 · 8 comments

Comments

@robfig
Copy link

@robfig robfig commented Mar 28, 2018

What version of pprof are you using?

"go get -u github.com/google/pprof"
a74ae6f

What operating system and processor architecture are you using?

Mac OS El Capitan

What did you do?

I want to profile my Java applications using pprof. I found this project that claims to implement such a thing:
https://github.com/papertrail/profiler

based on code from Twitter:
https://github.com/twitter/util/tree/develop/util-jvm/src/main/scala/com/twitter/jvm

Testing it out, it produces a profile that looks like that following:

--- symbol
binary=com.yext.profileservice.ProfileServer
0x0000000000000001 com.yext.rpc.RpcServer$Worker.run(RpcServer.java:356)
0x0000000000000002 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
0x0000000000000003 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
...
---
--- profile
^@^@^@^@^@^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^F^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^B^@^@^@^@
...

Full file here: https://github.com/robfig/testprofile/blob/master/legacy_profile

Trying to feed that to pprof is unsuccessful

$ pprof profile
legacy_profile: parsing profile: unrecognized profile format
pprof: failed to fetch any source profiles

I believe this is the legacy profile format. I was wondering if there's some trick to being able to read it. Alternatively, are you aware of any open source libraries that produce working profiles for Java?

I understand that some random library producing a file that pprof can't read isn't your problem; I was just hoping for some guidance on what would be the most fruitful way forward (even if it's writing a new implementation).

Thank you,
Rob

@aalexand

This comment has been minimized.

Copy link
Collaborator

@aalexand aalexand commented Mar 28, 2018

I'd suggest that you file an issue against that tool or debug yourself what happens if you are interested. The legacy format comes from the days of old Perl pprof and there can be some differences in the format that Go pprof doesn't support. These days it's recommended to produce profiles in the profile.proto format (see the proto directory).

@aalexand aalexand closed this Mar 28, 2018
@aalexand

This comment has been minimized.

Copy link
Collaborator

@aalexand aalexand commented Mar 28, 2018

To clarify: I am closing the issue not because I don't think it's important for you, but just to reflect that I don't view pprof team taking any action on it.

@robfig

This comment has been minimized.

Copy link
Author

@robfig robfig commented Mar 28, 2018

Ok, thanks for your input.

To confirm: you're not aware of anyone using pprof successfully with Java today?

@aalexand

This comment has been minimized.

Copy link
Collaborator

@aalexand aalexand commented Apr 3, 2018

You could try (at your own risk) using the Java profiling agent we wrote for Stackdriver Profiler product. It has an experimental mode to collect profiles in the pprof format to a file. See the example below.

$ wget -q -O- https://storage.googleapis.com/cloud-profiler/java/latest/profiler_java_agent.tar.gz | tar xzv
NOTICES
profiler_java_agent.so
libdataflow_profiler.jar

$ cat Test.java 
public class Test {
  private static void foo() {
    while (true) {}
  }

  public static void main(String[] argv) {
    foo();
  }
}

$ javac Test.java

$ java -agentpath:./profiler_java_agent.so=-logtostderr,-cprof_profile_filename=$PWD/profile_,-cprof_interval_sec=5,-cprof_duration_sec=10 Test
I0402 20:39:35.742357 140989 entry.cc:207] Profiler agent loaded
I0402 20:39:35.742499 140989 entry.cc:103] Prepare JVMTI
I0402 20:39:35.788872 140989 entry.cc:67] On VM init
I0402 20:39:35.789932 141005 throttler_timed.cc:61] Will save profiles to the local filesystem
I0402 20:39:35.789958 141005 throttler_timed.cc:75] sampling duration: cpu=10s, wall=10s
I0402 20:39:35.789969 141005 throttler_timed.cc:77] sampling interval: 5s
I0402 20:39:35.789978 141005 throttler_timed.cc:78] sampling delay: 0s
I0402 20:39:45.893823 141005 proto.cc:231] Collected a profile: total count=400, weight=40000000000
I0402 20:39:45.894408 141005 uploader_file.h:24] Saving profile to /usr/local/google/home/aalexand/projects/cprof-java-agent-collect-profile-to-file-example/profile_wall_1522726785.pb.gz
I0402 20:39:55.996594 141005 proto.cc:231] Collected a profile: total count=1000, weight=10000000000
I0402 20:39:55.996989 141005 uploader_file.h:24] Saving profile to /usr/local/google/home/aalexand/projects/cprof-java-agent-collect-profile-to-file-example/profile_cpu_1522726795.pb.gz
I0402 20:40:06.099144 141005 proto.cc:231] Collected a profile: total count=400, weight=40000000000
I0402 20:40:06.099649 141005 uploader_file.h:24] Saving profile to /usr/local/google/home/aalexand/projects/cprof-java-agent-collect-profile-to-file-example/profile_wall_1522726806.pb.gz
^CI0402 20:40:07.836849 141075 entry.cc:96] On VM death
I0402 20:40:16.201818 141005 proto.cc:231] Collected a profile: total count=1000, weight=10000000000
I0402 20:40:16.202256 141005 uploader_file.h:24] Saving profile to /usr/local/google/home/aalexand/projects/cprof-java-agent-collect-profile-to-file-example/profile_cpu_1522726816.pb.gz
I0402 20:40:16.202409 141005 worker.cc:116] Exiting the profiling loop

$ pprof -top profile_cpu_1522726816.pb.gz
File: java
Build ID: b8b4c6983f53365a453bf2958f19802be87f51fb
Type: cpu
Duration: 10s, Total samples = 10s (  100%)
Showing nodes accounting for 9.98s, 99.80% of 10s total
Dropped 2 nodes (cum <= 0.05s)
      flat  flat%   sum%        cum   cum%
     9.98s 99.80% 99.80%      9.98s 99.80%  Test.foo()
         0     0% 99.80%      9.98s 99.80%  JavaCalls::call_helper
         0     0% 99.80%      9.98s 99.80%  JavaMain
         0     0% 99.80%      9.98s 99.80%  Test.main
         0     0% 99.80%      9.98s 99.80%  WeakPreserveExceptionMark::~WeakPreserveExceptionMark (inline)
         0     0% 99.80%      9.98s 99.80%  __clone
         0     0% 99.80%      9.98s 99.80%  jni_CallStaticVoidMethod
         0     0% 99.80%      9.98s 99.80%  jni_invoke_static
         0     0% 99.80%      9.98s 99.80%  methodHandle::~methodHandle (inline)
         0     0% 99.80%      9.98s 99.80%  start_thread
@robfig

This comment has been minimized.

Copy link
Author

@robfig robfig commented Apr 3, 2018

Very interesting, thanks.

@liudanking

This comment has been minimized.

Copy link

@liudanking liudanking commented Sep 19, 2018

Very interesting, thanks.

Have you figured it out how to profile java application using pprof?

@smanurung

This comment has been minimized.

Copy link

@smanurung smanurung commented Oct 31, 2018

@aalexand I saw that profiling API only applies to compute engine, k8s engine, and app engine. I am using Apache Beam running on Cloud Dataflow. I used this class DataflowProfilingOptions from Apache Beam to generate profile files. I successfully run pprof -top <profile-file-name>.pb.gz; however, I want to get the profile showing my function calls (I did this in Go by putting the binary on the command). Do you know how to do this (in Java)?

@aalexand

This comment has been minimized.

Copy link
Collaborator

@aalexand aalexand commented Oct 31, 2018

@sonnythehottest I think what you might find useful is pprof -http :8080 <profile-file-name>.pb.gz then go to localhost:8080 in the browser and select the flame graph view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.