Jacoco Agent - Get Method Coverage from Jacoco Exec file

630 views
Skip to first unread message

wwaylo...@gmail.com

unread,
May 11, 2018, 5:46:55 PM5/11/18
to JaCoCo and EclEmma Users
Hi,

I'm using Jacoco as a Java agent to instrument classes to obtain coverage information. Currently, I can get the probe hit count of a given class. I followed the example from https://www.eclemma.org/jacoco/trunk/doc/examples/java/ExecDump.java to retrieve the number of probes hit for each class as recorded in a specified .exec file.

However, how can I get a finer granularity coverage report, specifically one that includes method information? Is it possible to associate the probe array with a set of methods?

I am able to get this information if I don't use Jacoco as a Java agent and make calls directly to the Jacoco.core.analysis package. However, if I need to use Jacoco as a Java agent, how could I get this same information?

Thank you!

wwaylo...@gmail.com

unread,
May 11, 2018, 6:10:13 PM5/11/18
to JaCoCo and EclEmma Users
I'm wondering if it's possible to instrument the classes by using Jacoco as a java agent but also collect the coverage information many times during run time by using an Analyzer instance?

Marc Hoffmann

unread,
May 12, 2018, 1:08:33 AM5/12/18
to jac...@googlegroups.com
Hi,

code coverage analysis with JaCoCo is a two step process:

1) Collect execution data at runtime (typically with the JaCoCo agent)
2) Create a detailed report (with the analyzer API or any of our tool
integrations like Ant, Maven, CLI, ...)

Regards,
-marc

Marc Hoffmann

unread,
May 12, 2018, 1:13:10 AM5/12/18
to jac...@googlegroups.com
The JaCoCo agent offers remote APIs (TCP socket, JMX) as well as a
runtime API:

https://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/package-summary.html

So yes, you could collect multiple dumps during execution and perform
analysis on it. E.g. with our Eclipse integration EclEmma this is
possible. You can dump execution data at any point in time while a
program is running:

https://www.eclemma.org/userdoc/coverageview.html

Regards,
-marc

wwaylo...@gmail.com

unread,
May 12, 2018, 1:19:56 AM5/12/18
to JaCoCo and EclEmma Users
Hi Marc!

Thank you for the reply!

The runtime API looks promising. It appears I can retrieve the IAgent instance and call getExecutionData().

However, that returns a byte array. To what could I pass this byte array to, to start analyzing the data and retrieving method coverage information?

Thank you!

Marc Hoffmann

unread,
May 12, 2018, 1:26:23 PM5/12/18
to jac...@googlegroups.com
The byte array is the content of the exec file that would be written.
With

new java.io.ByteArrayInputStream(array)

you can easily convert it to an InputStream that can be read by the
JaCoCo APIs.

Regards,
-marc
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages