Skip to main content

Profiling java apps?

10 replies [Last post]
tgwozdz
Offline
Joined: 2009-06-23
Points: 0

Is it possible to use a Java profiler to profile a Java xlet running inside the RI? I found the link below that suggests that this may be possible, but I have not had any luck getting it to work.

http://wiki.java.net/bin/view/Mobileandembedded/PhoneMEAdvancedProfiling

The trace shows this:

Profiler Agent: Initializing...
Profiler Agent Error: Failed to obtain JVMTI capabilities, error code: 98
Profiler Agent: Options: >/home/tgwozdz/.netbeans/6.7/lib,5140<
Profiler Agent: Initialized succesfully
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) Profiler initialization failed due to:
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) java.lang.NullPointerException
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.global.Platform.getOperatingSystem(Platform.java:410)
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.global.Platform.getOperatingSystem(Platform.java:391)
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.global.Platform.isWindows(Platform.java:539)
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.global.Platform.getAgentNativeLibFullName(Platform.java:189)
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.server.ProfilerServer.loadNativeLibrary(ProfilerServer.java:817)
20100219 19:50:30.514 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.server.ProfilerServer.doActivate(ProfilerServer.java:872)
20100219 19:50:30.515 INFO RI.Stack- (JVM stdout) at org.netbeans.lib.profiler.server.ProfilerServer.activate(ProfilerServer.java:511)

Any hints as to how I can make this work?
Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
scottdeboy
Offline
Joined: 2009-02-02
Points: 0

I've created a wiki topic. Would you mind providing feedback if possible?

https://devzone.cablelabs.com/widget/web/ocapri/1/-/wiki/OCAP%20RI%20Pub...

tgwozdz
Offline
Joined: 2009-06-23
Points: 0

There's two differences that stand out.

First, you copy over the built phoneME jar and lib files over the ones in the remote pack. I was using the ones provided by Netbeans directly. I don't know if this is significant.

However, more importantly, you specify your "hostname" of the remote machine as 127.0.0.1. The profiling agent in the VM uses this as a hint that it is running in local mode, rather than remote mode. If its in local mode, you may run into the issue where the agent tries using a java.nio class, and fails.

Try forcing it into remote mode by using the actual IP address of your machine, rather than 127.0.0.1. It made the difference for me. However, when I did this, I also had to make sure that the calibration data was in the original location, not in .nbprofiler.

scottdeboy
Offline
Joined: 2009-02-02
Points: 0

Changing my profiler configuration to attach to the network IP instead of 127.0.0.1 gave me profiling data!

Thanks

greg80303
Offline
Joined: 2008-07-03
Points: 0

PhoneME Advanced does have a profiling library that comes with it, but I have not tried to use it (nor do I understand even how to use it). Complete integration and support for the profiler is not our current roadmap. However, as more people begin to use the RI, I can certainly see a need for this sort of tool.

I can give you some steps to get you started, but I can't guarantee that what we've got now is even close to everything that you need.

In $OCAPROOT/bin/$OCAPTC/env/mpeenv.ini, you will see the VMOPT entries which make up the command line args passed to the VM when the stack initializes. I'm guessing the the profiling stuff works similar to JDWP -- you must pass a -Xrun arg to the JVM to get it to load profiling support. Not sure what that arg is, but that is a first step for you to try.

Greg

tgwozdz
Offline
Joined: 2009-06-23
Points: 0

Hi Greg,

There is a VMOPT argument that I am passing to enable the profiler. It looks something like this:
VMOPT.8=-agentpath:/home/tgwozdz/.netbeans/6.7/lib/deployed/cvm/linux/libprofilerinterface.so=/home/tgwozdz/.netbeans/6.7/lib,5140

where libprofileinterface.so is the Netbeans specific profiling agent that gets linked into the VM.

I got past the exception that I mentioned earlier. It seems that the profiler agent was trying to query the system property "os.name", but it was returning null, and the agent wasn't checking for that (the Javadoc indicates that this should have a default). I modified my phoneME mpe implementation to hard code this to "Linux", and I was able to load the profiling agent.

At this point, the Netbeans was able to connect, but it requires calibration data before it allows anything useful. I'm not quite sure how to get the calibration tool to run on the phoneME VM, so I cheated and created a dummy calibration file based on my Java 1.6 VM. It won't produce accurate profiling data, but at least it gets me further for now...

With this data, Netbeans was able to connect and start collecting basic profiling data. I was able to get some overall data about threads and memory usage. But it looks like the profiling agent wasn't able to instrument any of the classes, so I don't get any detailed statistics. I don't yet know why this would be the case.

So, some success, but not yet fully working.

scottdeboy
Offline
Joined: 2009-02-02
Points: 0

I researched the built-in netbeans profiling support (profilerInterface), and have some information:
- I had the same problem with os name, but was able to get past it by setting it as a vm arg:
VMOPT.9=-Dos.name=Windows XP

You can generate the calibration data:
- add the two fluid-server jars to the java.class.path
- specify a javaagent:
VMOPT.8=-javaagent:/nbremote/lib/jfluid-server.jar
- modify the main class (temporarily)
MainClassArgs.0=org.netbeans.lib.profiler.server.ProfilerCalibrator

It will place the machinedata calibration file in the $OCAPROOT/bin/$OCAPTC/env/.nbprofiler folder - copy that to your $userhome/.nbprofiler folder

The NetBeans (6.8) profiler failed to generate a heap dump, mentioning a java 5 vm is required to use that feature.

tgwozdz
Offline
Joined: 2009-06-23
Points: 0

I was able to make some progress.

Your hints about creating the calibration data was useful. However, I also had to extend the java.library.path to point to my libprofilerinterface.so.

When I was using the profiling agent and trying to connect in "local" mode, the agent wanted to use an API that doesn't exist on OCAP (java.nio) to create a file. But it doesn't do this when running in remote mode, so I did that to get past this issue. However, when running in remote mode, it then looked for the calibration data in the $OCAPROOT/bin/$OCAPTC/env/.nbprofiler folder (not ~/.nbprofiler).

When running an Xlet that had been instrumented, it tries to call classes in the org.netbeans package, but this is prevented by default. I had to add this option to let the Xlet see the classes:
OCAP.extensions=org.netbeans.lib.profiler.server

Also, I seem to be running into a whole lot of stability issues. When I run with the profiler enabled, most of the time the RI won't even boot to the point to which it launches my Xlet. Most of the time it seems to get stuck at some point in the boot process. I haven't been able to track this down, nor to determine whether this is caused by the profiler, or just some side effect of an unrelated issue.

Other than that, if I do get to a point where the Xlet starts and runs correctly, I seem to be able to get some profiling data. So, it can be done with a bit of setup work.

scottdeboy
Offline
Joined: 2009-02-02
Points: 0

Are you able to get memory and cpu profiling data? (are you using NetBeans?)

I am able to collect VM telemetry and thread data, but I can't generate a heap dump or collect per-class memory and cpu information.

If so, would you mind adding a comment describing the steps you're taking to get that information?

tgwozdz
Offline
Joined: 2009-06-23
Points: 0

After I attach the Netbeans profiler using either the "Memory" or "CPU" monitoring modes, I'm able to look at the "Live Profiling Results" tab to get the data.

However, as I said, I'm still running into many stability issues, so much of the time the RI doesn't get far enough to generate any useful data before it stops.

I am unable to generate a heap dump (same error as you, it complains about the version of the VM), but everything else looks like it works.

I'm using Netbeans 6.7.1 to do this, if that's relevant. (Although 6.8 should work as well, as far as I can tell).

scottdeboy
Offline
Joined: 2009-02-02
Points: 0

I'm using the remote profiling pack support and I'm not getting that information.

I'm creating a topic on the public wiki describing how to do this - if you wouldn't mind providing feedback that would be helpful. I will post a message here when I've finished writing up the procedure.