Search code examples
javaeclipseeclipse-plugineclipse-pdeeclipse-jdt

Eclipse plugin development: custom profiler (JDT )


I'm developing a code profiling for Java as Eclipse Plugin which will output the execution paths and code coverage information of Java code using JDT.

How can I extract information like which lines were executed during the execution to determine the execution paths and code coverage?

I'm looking into JDT CORE and JDT DEBUG but so far I wasn't able to find a way how I can track which lines were executed.


Solution

  • (This question seems very broad, so I provide an equally broad answer, hopefully you find it useful.)

    EclEmma is a Java Code Coverage plug-in for Eclipse. It uses a library called JaCoCo to provide the code coverage. Examining the source code of that open source project may be the best way to understand how to implement your own profiler (or perhaps contribute improvements back to EclEmma instead).

    The source repository for JaCoCo is on github: https://github.com/jacoco/jacoco, but the CoreTutorial is probably a good place to start.

    A key part of the tutorial is:

    // Together with the original class definition we can calculate coverage
    // information:
    final CoverageBuilder coverageBuilder = new CoverageBuilder();
    final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
    analyzer.analyzeClass(getTargetClass(targetName), targetName);
    

    Followed a little later by printing out some line information:

    printCounter("lines", cc.getLineCounter());