23

I am looking for a Java code profiler which I can use to profile my application (its a service which runs in backend) on production (so means low over head, and it must not slow down my application). Primarily I want calling tree profiling, that is if a() calls b() and then b() calls c(), then how much time a() b() and c() took, both inclusively and exclusively.

Have seen jvisualvm and jprofiler, but this is not what I am looking for, because I cannot tie my production application to them as it will cause a major performance issue.

Also, I did go through metrics (https://github.com/dropwizard/metrics), but it does not give me a functionality to profile the calling tree.

Callgrind (http://valgrind.org/docs/manual/cl-manual.html) type library is what I need, as it gives calling tree profiling functionality and advanced options like avoiding calling cycles (recursion). But I am not sure that Callgrind can be used on production as it dumps data when program terminates.

Can anyone suggest good calling tree profiler for java that can be used on production without compromising the performance?

kc2001
  • 5,008
  • 4
  • 51
  • 92
Arry
  • 1,630
  • 9
  • 27
  • 46
  • If I recall correctly you can get more information from another JVM like JRockit. I am basing this on a vague recollection of years past though. – nablex Mar 07 '14 at 13:11
  • The JRockit profiling functionality you remember has been incorporated into Oracle's JVM versions 7u40+. See my answer below about Mission Control and Flight Recorder. – kc2001 Mar 11 '14 at 20:16

5 Answers5

14

Take a look at Java Mission Control in conjunction with Flight Recorder. Starting with the release of Oracle JDK 7 Update 40 (7u40), Java Mission Control is bundled with the HotSpot JVM, so it is highly integrated and purports to have small effects on run-time performance. I have only just started looking at it, and I do see some call tree functionality.

enter image description here

kc2001
  • 5,008
  • 4
  • 51
  • 92
  • 2
    Keep in mind Mission Control and Flight Recorder aren't free software. You have to pay Oracle to use it. – Sebastian Häni Dec 19 '16 at 23:11
  • 1
    Apparently, in 2018, Mission Control became open source. See https://www.reddit.com/r/java/comments/8h9m9t/java_mission_control_open_sourced/ – kc2001 Nov 07 '18 at 16:15
10

In general you don't (or I won't recommend) profilers that instrument your application. Instrumenting always means an uncontrollable production overhead.

What you can use is a sampling profiler. A sampling profiler makes a snapshot of the stack traces at a controllable interval. What you don't get is call counts, but, after some runtime, you get a good overview where you have hotspots. Since you can adjust the sample interval of the profiler you can influence the overhead of it.

A usable sampling profiler is shipped with the JDK, see the hprof page in the java 7 documentation. In former times there existed some graphical analysis tools for the hprof cpu traces (not the heap traces). Now they are gone. However, you can already work with the generated text file.

I took a quick look on the Java Mission Control stuff mentioned above. I think it is quite mighty and will satisfy a lot of needs, in the white paper they say it has only 2% overhead. However, it is not totally what I personally need or want. For my applications it is better to have a "light" profiling enabled all the time.

Felix D.
  • 786
  • 1
  • 11
  • 17
cruftex
  • 5,545
  • 2
  • 20
  • 36
4

Intel Amplifier XE http://software.intel.com/en-us/intel-vtune-amplifier-xe has got low overhead if any noticeable. It uses stack sampling technology to minimize the impact and it can attach and detach to running non-stop processes in production. You even do not need to have sources during profiling, you can dive into sources later after offline performance results browsing.

Andrew
  • 2,055
  • 2
  • 20
  • 27
1

I don't know of any tool which can do profiling without an impact on performance.

You could add logging to the methods that you're interested in. Make sure you include the time stamp in the log; then you can do the timing. You should also configure the logging framework to log asynchronously to reduce the performance loss.

A load time weaver like AspectJ is able to add these calls at runtime, which would allow you to easily select the methods you want to monitor without changing the source code all the time.

Using an around aspect, you can even add timing logging, so you don't have to parse the logs and try to find matching log entries. See this blog post for details.

Have a look at perfspy (tutorial), it might already do out of the box what you need.

Related:

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Aspect is great! But using aspect for calling tree profiling will be too much, and it may affect the application's performance. Don't you think so? – Arry Mar 07 '14 at 13:21
  • 1
    Yes, I said exactly that in the first sentence. You can only try to weave the aspect in only a few places; often a high-level method is enough to see in which part of the code most of the performance is spend. Always remember that 80% of the code is good enough. You need to identify the 20% where 80% of the time is spend. I also wished there was a simple one-click solution but I haven't seen one, yet. – Aaron Digulla Mar 10 '14 at 10:51
0

https://github.com/salesforce-misc/perfGenie looks to be an interesting option for profile / stack visualization with context filters and comparison.

OstmanJVM
  • 1
  • 1
  • 1
    Note that questions asking for tool recommendations are off-topic for Stack Overflow and should not really be answered. I'm not entirely sure, but this is a 9 years old question that *may* have been allowable when it was first asked. – Adrian Mole Apr 20 '23 at 15:13