Skip to Main Content

Need help creating a recording from JVM startup to JVM shutdown (28.0.1)

Bill SOct 17 2012 — edited Oct 17 2012
I'm trying to record performance of a stand-alone java app from start to finish (memory allocated, CPU level, and other interesting things). I want to start a flight recording when my app starts up and finish the recording when the app exists.

Part 1
Start up is no problem because I can use command line args. Stopping is a bit more tricky because it seems that letting the program terminate naturally causes the recording to error. Since I don't know how long the program will run (somewhere between 20-30 hours), I can't just plug in a duration during startup. If there is a way to do the recording just using command line args, I'm interested in what args to use for the stopping part.

Here is what I tried:
-XX:StartFlightRecording=duration=5d,filename=my_recording.jfr
Part 2
The app is mine, so I'm happy to start/stop the recording programmatically too, if that will work. I tried this:
JVMFactory.getJVM().getDiagnosticCommand().execute("start_flightrecording", "name=myname,duration=0,filename=myfilename.jfr");
but it fails with this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jmapi in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
	at java.lang.Runtime.loadLibrary0(Runtime.java:823)
	at java.lang.System.loadLibrary(System.java:1028)
	at bea.jmapi.JVMImpl.<clinit>(JVMImpl.java:26)
	at com.bea.jvm.JVMFactory$1.run(JVMFactory.java:39)
	at com.bea.jvm.JVMFactory$1.run(JVMFactory.java:37)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.bea.jvm.JVMFactory.createJVM(JVMFactory.java:36)
	at com.bea.jvm.JVMFactory.getJVM(JVMFactory.java:29)
	at RunTests.main(RunTests.java:69)
The JRockit book warns about security manager errors (I don't know if this is a security manager error or just a different type of security error). My program is kind of like "HelloWorld.java", it doesn't run in a container or use any fancy frameworks. I tried adding a policy file, so now my batch file looks like this:
set PATH=D:\jrockit64-R28.0.1\bin;%PATH%
set JAVA_HOME=D:\jrockit64-R28.0.1
set JVM_ARGS=-Djava.security.manager -Djava.security.policy=TestDW.policy
java %JVM_ARGS% -jar TestDW.jar 4 21 "2010-05-01 10:00:00 GMT"
pause
and my TestDW.policy file looks like this:
grant { 
	permission com.bea.jvm.ManagementPermission "createInstance";
};
but that isn't working either and I get this error:
Exception in thread "Main Thread" java.security.AccessControlException: access denied (java.lang.RuntimePermission setFactory)
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
	at java.security.AccessController.checkPermission(AccessController.java:546)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
	at java.lang.SecurityManager.checkSetFactory(SecurityManager.java:1612)
	at java.net.URL.setURLStreamHandlerFactory(URL.java:1081)
	at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:46)
(I created my 'Runnable JAR' file in eclipse)

Any tips on how to start the recording through code would be helpful (or links on the web or page numbers in the JRockit book).

Thank you!
Bill
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on Nov 14 2012
Added on Oct 17 2012
1 comment
1,226 views