Profile Programs in JAR Files

Help
2012-07-16
2013-04-17
  • Georg Hofferek
    Georg Hofferek
    2012-07-16

    Hi,

    I have a Java program that is bundled in a JAR file, and I want to profile the program. When I try to do so, I only get statistical information about the JAR-loader, etc., and nothing from my actual program. (See dump below.)

    It works fine, if I run the program from single class files instead of from the JAR.
    Can I somehow also profile it from the JAR file?

    Dump:

     Count    Total      Net   Total     Net  Location
     =====    =====      ===   =====     ===  =========
         1   1116.5    960.0   100.0    86.0  +--JarRsrcLoader:main (org.eclipse.jdt.internal.jarinjarloader)
         1     25.5     25.2     2.3     2.3  | +--JarRsrcLoader:getManifestInfo    (org.eclipse.jdt.internal.jarinjarloader)
         1      0.2      0.1     0.0          | | +--JarRsrcLoader$ManifestInfo:<init>      (org.eclipse.jdt.internal.jarinjarloader)
         1      0.1      0.1     0.0          | | | +--JarRsrcLoader$ManifestInfo:<init>    (org.eclipse.jdt.internal.jarinjarloader)
         1      0.1      0.1     0.0          | | +--JarRsrcLoader:splitSpaces      (org.eclipse.jdt.internal.jarinjarloader)
         1      0.1      0.1     0.0          | +--RsrcURLStreamHandlerFactory:<init>       (org.eclipse.jdt.internal.jarinjarloader)
         2      2.7      2.6     0.2     0.2  | +--RsrcURLStreamHandlerFactory:createURLStreamHandler       (org.eclipse.jdt.internal.jarinjarloader)
         1      0.1      0.1     0.0          | | +--RsrcURLStreamHandler:<init>    (org.eclipse.jdt.internal.jarinjarloader)
       127      3.4      3.4     0.3     0.3  | +--RsrcURLStreamHandler:parseURL    (org.eclipse.jdt.internal.jarinjarloader)
       188      5.2      4.5     0.5     0.4  | +--RsrcURLStreamHandler:openConnection      (org.eclipse.jdt.internal.jarinjarloader)
       188      0.8      0.8     0.1          | | +--RsrcURLConnection:<init>       (org.eclipse.jdt.internal.jarinjarloader)
       163    119.6    119.6    10.7    10.7  | +--RsrcURLConnection:getInputStream (org.eclipse.jdt.internal.jarinjarloader)
         1      0.1      0.1     0.0          | | +--RsrcURLStreamHandlerFactory:createURLStreamHandler     (org.eclipse.jdt.internal.jarinjarloader)
    
     
  • Andrew Wilcox
    Andrew Wilcox
    2012-07-16

    Hi,

    Being able to profile the contents of a JAR file depends on which classloader is used to load the JAR. Try this:

    1. Add this line to your main function (or some other appropriate place):

        System.out.println(java.lang.ClassLoader.getSystemClassLoader().getClass().getName());
        System.out.println(Thread.currentThread().getContextClassLoader().getClass().getName());

    2. If the output is:

        foo.Classloader
        bar.Classloader

    Then add this to your profile properties file:

        accept-class-loaders=foo.Classloader,bar.Classloader

    The assumes that you're using the default classloader filter.
    (see doc/profile-properties.html for more information on accept-class-loaders,
    see the JavaDoc in Controller.java for even more up-to-date information).

    Cheers,

    Andrew.