Hi,
Goal: capture/record only at certain times
What I've done:
1) Bring up JVM with yjp at startup. On the client side, I can attach to the remote host and I can do things such as look at live data, capture-save-download-open the snapshot file etc. That is all working fine. However, when we do this, the analysis is "polluted" with data that we are not interested (startup, initialization etc). What we would like to do is something similar to JProfile whereby one can attach to a running JVM and then start capturing the profile.
2) I've also tried to bring up JVM without yjp, and then do an attach. It didn't work. Here's what I got:
FYI:
>: uname -a
Linux sip01.sip-prf4-001.orn-svc01.uci.altus.bblabs.rim.net 3.2.0-70-virtual #105-Ubuntu SMP Wed Sep 24 20:06:46 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
and when I tried the following:
>: ./yjp.sh -attach 16581
[YourKit Java Profiler 2014 build 14112] Log file: /root/.yjp/log/yjp-18935.log
Attaching to process 16581 using default options
com.yourkit.runtime.PresentableException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at com.yourkit.h.u.p.a(a:102)
at com.yourkit.h.u.c.a(a:200)
at com.yourkit.Main1.int(a:183)
at com.yourkit.Main1.entry(a:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.yourkit.Main$2.run(a:8)
Attach to a running JVM failed.
Solution: start JVM with the profiler agent instead of attaching it to a running JVM:
http://www.yourkit.com/docs/java/help/r ... ofiler.jsp
NOTE: I have saved the yjp log file and can post/send it, if you are interested.
Q1: Is it possible to attach to a running JVM? I can see where this is a useful ability (eg, we are running for a long period of time, and something happens and we are now interested in seeing what is happening)
Q2: Let's say that the answer to Q1 is "NO, it is not possible" and I must have the yjp agent running at startup. Is there a way to clear all the data and then start the capture? Specifically, when I do a capture and view the results, it looks like the "Hot Spots" is showing "everything" as in, from when yjp/JVM started.
Thanks,
Robert
Attaching to running JVM
-
- Posts: 2
- Joined: Thu Nov 20, 2014 3:19 pm
Re: Attaching to running JVM
NOTE: I have also tried the following, with the same results:
>: ./yjp.sh -attach 16581 "-agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat"
[YourKit Java Profiler 2014 build 14112] Log file: /root/.yjp/log/yjp-22409.log
Attaching to process 16581 using options -agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat
com.yourkit.runtime.PresentableException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at com.yourkit.h.u.p.a(a:102)
at com.yourkit.h.u.c.a(a:200)
at com.yourkit.Main1.int(a:183)
at com.yourkit.Main1.entry(a:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.yourkit.Main$2.run(a:8)
Attach to a running JVM failed.
Solution: start JVM with the profiler agent instead of attaching it to a running JVM:
http://www.yourkit.com/docs/java/help/r ... ofiler.jsp
>: ./yjp.sh -attach 16581 "-agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat"
[YourKit Java Profiler 2014 build 14112] Log file: /root/.yjp/log/yjp-22409.log
Attaching to process 16581 using options -agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat
com.yourkit.runtime.PresentableException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at com.yourkit.h.u.p.a(a:102)
at com.yourkit.h.u.c.a(a:200)
at com.yourkit.Main1.int(a:183)
at com.yourkit.Main1.entry(a:271)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.yourkit.Main$2.run(a:8)
Attach to a running JVM failed.
Solution: start JVM with the profiler agent instead of attaching it to a running JVM:
http://www.yourkit.com/docs/java/help/r ... ofiler.jsp
-
- Posts: 6172
- Joined: Wed Aug 11, 2004 8:37 am
Re: Attaching to running JVM
Hi Robert
CPU profiling, either sampling or tracing, starts only when you explicitly instruct the profiler to do it.
http://www.yourkit.com/docs/java/help/cpu_intro.jsp
Note: by default it is not started. You can start via a startup option or start/stop in UI, via API, triggers.
If you mean CPU telemetry, it is always collected:
http://www.yourkit.com/docs/java/help/cpu_telemetry.jsp
It's light weight thus adds no overhead.
Thread telemetry (includes states and stacks) may add overhead but you can turn it off:
http://www.yourkit.com/docs/java/help/threads.jsp
http://www.yourkit.com/docs/java/help/attach_agent.jsp
yjp.sh -attach is just a frontend to corresponding JVM API which allows to attach given agent library to a running JVM by its PID. The error which you see comes from JVM, it's not the profiler's one.
In this particular case I think the problem may be with access rights. According to the log file location /root/.yjp you run yjp.sh as root. Does application you want to attach also run as root? Please note that the attaching process (yjp.sh -attach) should run under the same user as the JVM process you attach to.
Anyway, please note that you incorrectly specified the options:
http://www.yourkit.com/docs/java/help/s ... ptions.jsp
It should be './yjp.sh -attach 16581 "delay=10000,sessionname=Tomcat"' instead, i.e. only the part after "agent name =".
The -agentpath is a JVM option, it's a thing like -Xmx or -Dproperty=value. It is specified when you launch Java via a command line.
When you attach to a running JVM, there is no command line. It has already started. The agent options should be passed "naked".
Best regards,
Anton
This is possible and easy to achieve. Please find my comments below.Goal: capture/record only at certain times
Could you please clarify what profiling results you mean.1)... That is all working fine. However, when we do this, the analysis is "polluted" with data that we are not interested (startup, initialization etc).
CPU profiling, either sampling or tracing, starts only when you explicitly instruct the profiler to do it.
http://www.yourkit.com/docs/java/help/cpu_intro.jsp
Note: by default it is not started. You can start via a startup option or start/stop in UI, via API, triggers.
If you mean CPU telemetry, it is always collected:
http://www.yourkit.com/docs/java/help/cpu_telemetry.jsp
It's light weight thus adds no overhead.
Thread telemetry (includes states and stacks) may add overhead but you can turn it off:
http://www.yourkit.com/docs/java/help/threads.jsp
This is of course possible.What we would like to do is something similar to JProfile whereby one can attach to a running JVM and then start capturing the profile.
You use the attach mode:>: ./yjp.sh -attach 16581
[YourKit Java Profiler 2014 build 14112] Log file: /root/.yjp/log/yjp-18935.log
Attaching to process 16581 using default options
com.yourkit.runtime.PresentableException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
http://www.yourkit.com/docs/java/help/attach_agent.jsp
yjp.sh -attach is just a frontend to corresponding JVM API which allows to attach given agent library to a running JVM by its PID. The error which you see comes from JVM, it's not the profiler's one.
In this particular case I think the problem may be with access rights. According to the log file location /root/.yjp you run yjp.sh as root. Does application you want to attach also run as root? Please note that the attaching process (yjp.sh -attach) should run under the same user as the JVM process you attach to.
Yes.Q1: Is it possible to attach to a running JVM?
Please see my comment above. Which Hot Spots do you mean? As I wrote, CPU profiling starts only when you tell it to start.Q2: .... Is there a way to clear all the data and then start the capture? Specifically, when I do a capture and view the results, it looks like the "Hot Spots" is showing "everything" as in, from when yjp/JVM started.
The error is same as above. The startup options are applied by the agent when it loads. But since the attach did not happen, the agent did not start loading and the options processing was not performed. You could specify any string in "" instead with the same effect.NOTE: I have also tried the following, with the same results:
>: ./yjp.sh -attach 16581 "-agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat"
[YourKit Java Profiler 2014 build 14112] Log file: /root/.yjp/log/yjp-22409.log
Attaching to process 16581 using options -agentpath:/home/local/yjp-2014-build-14112/bin/linux-x86-64/libyjpagent.so=delay=10000,sessionname=Tomcat
com.yourkit.runtime.PresentableException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
Anyway, please note that you incorrectly specified the options:
http://www.yourkit.com/docs/java/help/s ... ptions.jsp
It should be './yjp.sh -attach 16581 "delay=10000,sessionname=Tomcat"' instead, i.e. only the part after "agent name =".
The -agentpath is a JVM option, it's a thing like -Xmx or -Dproperty=value. It is specified when you launch Java via a command line.
When you attach to a running JVM, there is no command line. It has already started. The agent options should be passed "naked".
Best regards,
Anton