Correlation between line numbers and probes

30 views
Skip to first unread message

Nikola Veber

unread,
Aug 14, 2020, 4:01:24 AM8/14/20
to JaCoCo and EclEmma Users
Hi,

I have tried to figure this out by debugging during report generation, but without much luck.

Can you suggest a way to get a correlation between source line numbers and probe "ids"?

I would like to have something like 
line x -> depends on probes [0, 2, 7] 
(or the other way around)


Cheers,
Nikola

Marc Hoffmann

unread,
Aug 14, 2020, 5:43:24 AM8/14/20
to JaCoCo and EclEmma Users
Hi Nikola,

there is no simple relationship between probes and line numbers. Probes are inserted based on the control flow in methods. Line numbers depend on your source code formatting and the compiler.

That’s why JaCoCo needs the original class files to reconstruct coverage data from probes. The algorithm is documented here: https://www.jacoco.org/jacoco/trunk/doc/flow.html

So my recommendation is to use JaCoCo based tools or the JaCoCo Java API to create line coverage. Here are some code examples: https://www.jacoco.org/jacoco/trunk/doc/api.html

Regards,
-marc



--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/0e5fc174-1e86-4f1b-a70e-2670506baa9bn%40googlegroups.com.

Nikola Veber

unread,
Aug 14, 2020, 5:59:45 AM8/14/20
to jac...@googlegroups.com
Hi Marc,

thanks for the quick reply!

I am aware of the process (class files + source files + exec = line-level coverage report). My attempt was to tweak the html report generator to give me the data I need, but was unable to understand how to connect the dots..
Do you have any pointers for me, where to find the specific code which does the correlation between inserted probes and the source code? (as this needs to happen somehow, in order to generate the report...)


Best regards,
Nikola




You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/Gf8B6MwehNo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/5FF45787-D124-4D49-AF30-A25A8F58AEE1%40mountainminds.com.

Marc Hoffmann

unread,
Aug 14, 2020, 6:09:05 AM8/14/20
to jac...@googlegroups.com
Hi Nikola,

not sure what yoe exactly want to do. But if you want to get line-by-line coverage information JaCoCo provides the interface ISourceNode.

This ReportGenerator Example shows how to generate the JaCoCo coverage model.

Regards,
-marc


Nikola Veber

unread,
Aug 14, 2020, 9:26:36 AM8/14/20
to jac...@googlegroups.com
Hi Marc,

thanks for bringing me back to that example! 

In essence, I want to combine git blame with code coverage, in order to figure out how much "new code" is untested.
A crude way would be parsing the HTML report, but I was hoping to find a more elegant solution.
For that, I need to align the source-code lines with the coverage data. I failed last time, but today I got a step further by examining the example more closely.

What I still need to figure out: 
In BundleCoverage -> Packages -> Classes -> lines, there is an array of coverage information for what seems to correspond to course lines. 

Also interesting are  BundleCoverage -> Packages -> Classes -> methods. The offset field of each method seems to denote the line number of the first line of method code. Some lines are null, which I assume are the whitespaces.

Would it be safe to assume that the "lines" array in the method represents all source lines after the start of the method (=offset)?
Basically, is the assumption that offset + lines[i] == source line number?


Thanks!
Nikola


Marc Hoffmann

unread,
Aug 14, 2020, 9:52:39 AM8/14/20
to jac...@googlegroups.com
Aha, in this case you can also use the JaCoCo XML report which provides line by line coverage data. See for example: https://www.jacoco.org/jacoco/trunk/coverage/jacoco.xml

It is basically the same structure as the API.

If you want to related it to git change sets I I would recommend to Navigate BundleCoverage —> Packages —> SourceFiles —> Lines. Methods can be tricky as they can overlap (e.g. in case of anonymous inner classes, lambdas) and a single source file can result in many classes.

Regards,
-marc

Nikola Veber

unread,
Aug 14, 2020, 9:58:46 AM8/14/20
to jac...@googlegroups.com
Aaah, perfect! 

I oversaw the offset field in sourceFiles part! (and was confused, that the number of lines doesn't match the number of source lines... )
For the "ease of use", I guess the XML will be the preferred way.

Thanks a lot for the help!!

Have a nice weekend!
Nikola

Reply all
Reply to author
Forward
0 new messages