Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Profiling application running in Eclipse without Tomcat and saving profile data to separate files

Help
2013-10-13
2013-10-13
  • Jim Showalter
    Jim Showalter
    2013-10-13

    GOAL STATEMENT:

    We make a bunch of external service calls. We want to group them into a single omnibus call (to minimize over-the-wire chatter).

    We want to use profiling to identify calls we missed.

    We have two flavors of service--domestic (US) and global.

    We run the test twice, once with the region set to US, once with it set to a non-US country.

    We want to do this in Eclipse, and not while running in Tomcat.

    We just want to run a simple JUnit test that makes HttpClient calls to the external services, and dump profile info at four places in the code: global main, global stragglers (calls we missed), US main, US stragglers.

    Because we aren't running in Tomcat, we don't have a listener, so we can't use the client JAR to start/stop profile. Instead, we need to control profiling programmatically, from our test.

    PROBLEM STATEMENT:

    We have been unable to get the profile files to output when we programmatically start/stop JIP.

    We expect to see four files.

    We only see one file, the last one of the run, which we suspect is output simply because of the shutdown hook.

    The other three files, and their profile data, are lost.

    We do not see the dreaded "Warning: a request has been made to start the profiler but no classes have been instrumented."

    We need help getting the Eclipse config set up correctly. We suspect we are close to having it working.

    RELEVANT PARTS OF JIP PROPERTIES FILE:

    profiler=off
    remote=off
    ClassLoaderFilter.1=com.mentorgen.tools.profile.instrument.clfilter.CustomMultiClassLoaderFilter
    accept-class-loaders-byname=org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader,sun.misc.Launcher$AppClassLoader
    file=C:/jip/out
    exclude=org.apache.xalan.xsltc \ javax \ com.sun \ com.ctc \ com.protomatter \ org.apache.catalina \ org.apache.naming \ org.apache.jasper \ org.apache.tomcat \ org.apache.coyote \ org.apache.log4j \ org.springframework \ org.jboss.resteasy \ oracle.jdbc \ oracle.net \ oracle.sql \ org.jboss.cache \ com.intuit.qbo.bl.misc.dao \ com.intuit.spc.wscommon.spctype \ com.oreilly.servlet \ org.apache.commons.codec \ org.apache.commons.logging \ org.apache.http \ org.apache.commons.io \ org.apache.commons.lang \ gnu.regexp \ org.json \ org.aspectj \ org.codehaus.stax2 \ org.codehaus.jackson \ com.ibm.icu \ oracle.security \ org.apache.axis.utils \ org.apache.commons.beanutils \ org.apache.commons.collections \ org.apache.commons.configuration \ org.apache.velocity \ org.jasypt \ org.owasp
    output=text

    RELEVANT ECLIPSE VM ARGS:

    -Dprofile.properties=C:/jip/target/classes/profile.properties
    -javaagent:C:/jip/target/jip-1.0-SNAPSHOT.jar (we Mavenized JIP)
    -XX:-UseSplitVerifier

    RELEVANT PARTS OF TEST CODE:

    // Dump out class loaders, to make sure we are using the correct class names in the JIP properties.
    System.out.println("CONTEXT: " + Thread.currentThread().getContextClassLoader().toString());
    System.out.println("SYSTEM : " + ClassLoader.getSystemClassLoader().toString());

    // Get current prefix (US vs. global) based on region.
    final String OUT_DIR = "C:/jip/out/";
    String prefix = null;
    if ((region == null) || (region.toInt() == Region.US_ID)) {
    prefix = "us";
    } else {
    prefix = "global";
    }

    // Make consolidated call and save profile data to file.
    String fileName = OUT_DIR + prefix + "_main";
    System.out.println("FILE: " + fileName);
    com.mentorgen.tools.profile.runtime.Profile.setFileName(fileName);
    com.mentorgen.tools.profile.runtime.Profile.start();
    do stuff here
    com.mentorgen.tools.profile.runtime.Profile.stop();

    // Make remaining (straggler) calls, and save profile data to different file.
    com.mentorgen.tools.profile.runtime.Profile.stop();
    fileName = OUT_DIR + prefix + "_stragglers";
    System.out.println("FILE: " + fileName);
    com.mentorgen.tools.profile.runtime.Profile.setFileName(fileName);
    com.mentorgen.tools.profile.runtime.Profile.start();
    do more stuff here
    com.mentorgen.tools.profile.runtime.Profile.stop();

    CONSOLE OUTPUT:

    profiler: off
    remote: off
    port: 15599
    thread-depth: -1
    thread.compact.threshold.ms: 1
    max-method-count: -1
    method.compact.threshold.ms: 1
    file: C:/jip/out
    track.object.alloc: on
    output: text
    debug: off
    profiler-class: com.mentorgen.tools.profile.runtime.Profile
    output-method-signatures: no
    clock-resolution: ms
    output-summary-only: no
    exclude:org.apache.xalan.xsltc javax com.sun com.ctc com.protomatter com.intuit.util.cache.QBNCacheHotDeployListener com.intuit.qbo.util.QBOPerformanceStats com.intuit.qbo.util.SessionStateManager com.intuit.util.Config com.intuit.util.Log com.intuit.qbo.ui.common.UICommonFunctions com.intuit.util.RequestScopedObject com.intuit.util.Util com.intuit.util.NullTimerFactory com.intuit.util.NullTimerImpl com.intuit.qbo.util.Jdk14LogHandler com.intuit.util.crypto com.intuit.sbn.logging com.intuit.html org.apache.catalina org.apache.naming org.apache.jasper org.apache.tomcat org.apache.coyote org.apache.log4j org.springframework org.jboss.resteasy oracle.jdbc oracle.net oracle.sql org.jboss.cache com.intuit.qbo.bl.misc.dao com.intuit.spc.wscommon.spctype com.oreilly.servlet org.apache.commons.codec org.apache.commons.logging org.apache.http org.apache.commons.io org.apache.commons.lang gnu.regexp org.json org.aspectj org.codehaus.stax2 org.codehaus.jackson com.ibm.icu oracle.security org.apache.axis.utils org.apache.commons.beanutils org.apache.commons.collections org.apache.commons.configuration org.apache.velocity org.jasypt org.owasp
    Class loaders by name:
    org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader,sun.misc.Launcher$AppClassLoader
    Accept ClassLoader: sun.misc.Launcher$AppClassLoader
    ClassLoaderFilter.1: com.mentorgen.tools.profile.instrument.clfilter.CustomMultiClassLoaderFilter
    Java Interactive Profiler: starting
    CONTEXT: sun.misc.Launcher$AppClassLoader@4a4854f6
    SYSTEM : sun.misc.Launcher$AppClassLoader@4a4854f6
    FILE: C:/jip/out/global_main
    FILE: C:/jip/out/global_stragglers
    CONTEXT: sun.misc.Launcher$AppClassLoader@4a4854f6
    SYSTEM : sun.misc.Launcher$AppClassLoader@4a4854f6
    FILE: C:/jip/out/us_main
    FILE: C:/jip/out/us_stragglers

    ONLY ONE OUTPUT FILE IN DIRECTORY:

    C:\jip\out>ls -al
    total 12668
    drwx------+ 1 Administrators Domain Users 0 Oct 13 12:38 .
    drwx------+ 1 Administrators Domain Users 0 Oct 13 12:26 ..
    -rwx------+ 1 Administrators Domain Users 12967456 Oct 13 12:38 us_stragglers.txt