This discussion is archived
4 Replies Latest reply: Jul 3, 2013 3:18 AM by PetrNidl RSS

Parsing jrockit flight recorder files programmatically

749732 Newbie
Currently Being Moderated
Hi all,

i am trying to develop a small/custom application to process the .jfr files from multiple jrockit JVM (the JRMC is not friendly enough
when processing multiple files and can't automate some typical issue/problem checking)

i refer to the API document here: http://docs.oracle.com/cd/E15289_01/apirefs.40/e26998/com/jrockit/mc/flightrecorder/FlightRecording.html

e.g.

---------------
FlightRecording recording = FlightRecording.createFromFile(new File("path_to_recording.jfr"));

//more code below

---------------

i add several .jar files in the classpath (jars in folder missioncontrol/plugins) for compilation.

When i try to run the application, i get the following error.

can anybody help to show me how to setup the environment/classpath so as to run an application for reading the .jfr file?

thank you.
--------------------------------------

Begin task: Starting reading eventsReading chunk

Parsing events
java.lang.ExceptionInInitializerError
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
     at java.lang.Class.newInstance0(Class.java:355)
     at java.lang.Class.newInstance(Class.java:308)
     at com.jrockit.mc.flightrecorder.provider.bcel.BCELUtilities.createEventClassLoader(BCELUtilities.java:37)
     at com.jrockit.mc.flightrecorder.provider.EventType.<clinit>(EventType.java:45)
     at com.jrockit.mc.flightrecorder.provider.Producer.createEventType(Producer.java:99)
     at com.jrockit.mc.flightrecorder.internal.parser.synthetic.EventTypeFactory.create(EventTypeFactory.java:29)
     at com.jrockit.mc.flightrecorder.internal.parser.synthetic.ProducerFactory.create(ProducerFactory.java:135)
     at com.jrockit.mc.flightrecorder.internal.parser.synthetic.ProducerFactory.createProducers(ProducerFactory.java:101)
     at com.jrockit.mc.flightrecorder.internal.parser.binary.MetadataParser.read(MetadataParser.java:37)
     at com.jrockit.mc.flightrecorder.internal.parser.binary.MainParser.read(MainParser.java:70)
     at com.jrockit.mc.flightrecorder.internal.parser.binary.MainParser.read(MainParser.java:49)
     at com.jrockit.mc.flightrecorder.provider.RepositoryBuilder.createRepository(RepositoryBuilder.java:63)
     at com.jrockit.mc.flightrecorder.provider.RepositoryBuilder.build(RepositoryBuilder.java:52)
     at com.jrockit.mc.flightrecorder.internal.JRockitFileProvider.createRepositoryFromFile(JRockitFileProvider.java:26)
     at com.jrockit.mc.flightrecorder.spi.FileProvider.createRepository(FileProvider.java:43)
     at com.jrockit.mc.flightrecorder.FlightRecording.<init>(FlightRecording.java:69)
     at com.jrockit.mc.flightrecorder.FlightRecording.createFromFile(FlightRecording.java:108)
     at test.FileParser.main(FileParser.java:18)
Caused by: java.lang.NullPointerException
     at com.sun.org.apache.bcel.internal.classfile.ClassParser.<init>(ClassParser.java:101)
     at com.jrockit.mc.flightrecorder.provider.bcel.Repository.lookupClass(Repository.java:34)
     at com.jrockit.mc.flightrecorder.provider.bcel.EventClassLoader.<clinit>(EventClassLoader.java:52)
     ... 22 more

--------------------------------------

Edited by: user12050693 on Nov 15, 2012 1:10 AM
  • 1. Re: Parser jrockit flight recorder files programmatically
    Hirt Guru Moderator
    Currently Being Moderated
    Interesting that we post the Mission Control internal API documentation externally. ;) Anyways, for that to work outside of a Mission Control environment, you will need the plug-in jar from a 5.2 version of Mission Control or later. If you are working for Oracle, you can contact me about where to get builds. If you are not, you will need to wait for Mission Control 5.2 to get released. :)
  • 2. Re: Parser jrockit flight recorder files programmatically
    749732 Newbie
    Currently Being Moderated
    Hi hirt,

    i am not working for oracle, but my company is a client of oracle, that purchase and use many oracle products.

    can i access to the builds?

    thank you.
  • 3. Re: Parser jrockit flight recorder files programmatically
    Hirt Guru Moderator
    Currently Being Moderated
    No, sorry. But 5.2 is not that far off in the future now. :)

    Kind regards,
    Marcus
  • 4. Re: Parsing jrockit flight recorder files programmatically
    PetrNidl Newbie
    Currently Being Moderated

    I had the same problem today, so I went deeper and found out that there's a problem in retrieving the resource stream, it can be overridden by loading your class (and all reflected JRockit classes) with class loader like this:

     

     

    import java.io.InputStream;

    import java.net.URL;

    import java.net.URLClassLoader;

     

     

    public class CorrectedClassLoader extends URLClassLoader {

     

        public CorrectedClassLoader(URL[] urls, ClassLoader parent) {

            super(urls, parent);

        }

      

        public CorrectedClassLoader(URL[] urls) {

            super(urls);

        }

     

        @Override

        public InputStream getResourceAsStream(String name) {

            InputStream is = super.getResourceAsStream(name);

            if (is == null && name.startsWith("/")) {

                name = name.substring(1);

                is = super.getResourceAsStream(name);

            }

            return is;

        } 

    }

     

    I don't know why the system class loader won't find the resources with "/" prefix but this solved my problem.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points