9

I am writing an algorithm implementation using Java. Until OS X 10.7, I used the Shark Profiler to profile my implementation, which worked rather nicely. However, the new Instruments does not find the procedure names anymore. I already tried running the java application with the VM arguments for shark (namely, -agentlib:Shark ), but they are unknown to 10.7, and I couldn't find such an agentlib for instruments.

Any idea on how I can attach procedure names to the symbol names (which are some hex numbers) in Insturments? I am using Eclipse Indigo, if that makes any difference.

Thanks!

Edit: So far, nothing has changed with OS X Mountain Lion.

Edit #2: An update from a (?) developer via apple's bug reporter:

dtrace has had support for Java stacks at points in the past, though I honestly couldn't say whether the support has been maintained. It may be a viable workaround for what you're trying to measure – which is otherwise not a priority for the performance tools at this point. You may want to start with the D script in /usr/bin/cpu_profiler.d and amend it to collect the jstack as well.

Edit #3: Alright, after some more discussion it turns out that the developer himself didn't know where that script came from. Apparantly, the time profiler in Instruments doesn't use DTrace anyhow, so the only option left is to write our own DTrace script or instrument.

You're right, and I apologize. I'm not sure where that script came from, and when I looked at it carefully, it doesn't have jstack actions in it so it's not what you want anyway. It looks like the only java profiling option I can offer you is DTrace. DTrace has a profile provider, and a jstack action that collects java stacks. You can use "aggregates" to determine the heaviest stack traces, and all of this works from the command line. The documentation for DTrace is mostly maintained by Sun and I'd direct you to any DTrace tutorial since most cover the profile provider.

Despite what people say online, Instruments does not use DTrace for everything, specifically time profiling, so I can't offer you a quick fix in the Instruments UI.

Community
  • 1
  • 1
HdM
  • 169
  • 1
  • 11

3 Answers3

5

Instruments relies upon a bit of lovely software developed by Sun called dtrace. dtrace has a function called 'jstack()' that is supposed to print a stack trace with java symbols, there is also a 'ustack()' that is supposed to do similar things for other langauges (python, node.js, etc.). Unfortunately OS X's version of dtrace does not support those methods and as such Instruments won't provide that functionality.

So, unfortunately you're not going to get that information from those tools until Apple fixes their stuff. :(

Follow this thread for more info: http://www.mail-archive.com/dtrace-discuss@opensolaris.org/msg04863.html

I've filed a bug with apple regarding their lack of support for helper stack tracers, if you want this functionality you should file a bug too: https://bugreport.apple.com

Alpha Fighter
  • 110
  • 2
  • 9
  • Great, thank you. I hope this gets fixed soon, although the bug has been around for quite some time now. I'll file a bug report. – HdM Mar 29 '13 at 18:39
  • So, I got an update from a developer which reads the following: "dtrace has had support for Java stacks at points in the past, though I honestly couldn't say whether the support has been maintained. It may be a viable workaround for what you're trying to measure – which is otherwise not a priority for the performance tools at this point. You may want to start with the D script in /usr/bin/cpu_profiler.d and amend it to collect the jstack as well." – HdM Apr 09 '13 at 13:18
  • After checking, it seems that the file suggested doesn't even exist. On my system, at least. – HdM Apr 11 '13 at 07:52
  • However, you can build your own instrument in XCode Instruments (via cmd+b). In the following option window, you can specifically select which stack trace it's supposed to be working on. However, since I am a complete beginner (actually, I know nothing at all) with writing dtrace scripts, I don't know how to build your own java cpu profiler. If only I could open the shipped cpu profiler and compare it... – HdM Apr 11 '13 at 11:21
0

One thing that comes to my mind is the -g option to the javac compiler to include debugging information. In eclise (at least in helios) you can set different options for debugging data under 'Java Compiler', 'Classfile Generation'. Maybe some of those settings got mangled up.

This, however, does not solve the issue with method names, which are always included in the class files. Yet, different flavors of Java VMs perform runtime-optimizations in different ways, see for instance the note on the reliability of stack traces in the docs.

Therefore, switching to another (version of) VM may have impact on the ability of the profiler to do the correct thing. - By the way, you did not implicitly 'upgrade' your Java version (e.g. 1.6 to 1.7) in the process?

JimmyB
  • 12,101
  • 2
  • 28
  • 44
  • 1
    I did upgrade to a non-apple java version. Although as far as I know, this "bug" always persisted, and the missing "worksforme" posts indicate that it probably has nothing to do with the vm. I think it's more of a problem if finding a dtace hook. – HdM Dec 20 '12 at 05:42
0

If you want to profile java applications, i recommend you to use Visualvm from Oracle (via Java.net). This tool can profile memory and cpu down to the method, even for remote JVMs. On OSX it is obvious not part of the default JDK, but you can get it here: http://visualvm.java.net/download.html May be an alternative to shark.

dataverse
  • 116
  • 2
  • I tried visualvm, but I am highly unsatisfied with it. Compared with shark or instruments, it's clunky, has ridiculous overhead and it's pretty difficult to start, even with the eclipse plugin. For me this is not an alternative. – HdM Dec 20 '12 at 05:39