I am trying to get Line Execution Count in the report

469 views
Skip to first unread message

Andy Bazhgin

unread,
Nov 9, 2014, 3:02:40 PM11/9/14
to jac...@googlegroups.com
Hello.. I spent a few hours trying to get Line Execution Count to be added to the report (as specified in this issue: https://github.com/jacoco/jacoco/issues/89).

I was unable to get the correct amount of times a line gets executed.

I used this project as the template to run my test:

The resulting numbers were like this: https://github.com/nenick/android-gradle-template

This is a method inside my MainActivity.java file.
```
    public void testFunc() {
intCOV 2 intMIS 0 brCOV 0 brMIS 0       int myvar = 1 + 1;
intCOV 7 intMIS 0 brCOV 2 brMIS 0       for(int i=0; i < 11; i++) {
intCOV 10 intMIS 0 brCOV 0 brMIS 0          System.out.println("Count is: " + i);
intCOV 4 intMIS 0 brCOV 0 brMIS 0           int more = myvar + i;
        }
```

intCOV means instructions covered, brCOV means branches covered, MIS means missed..

Well I have one test inside of my AppUnitTests (MainActivityTests.java) file which calls the method activity.testFunc() (actually the code is view.testFunc()).

so it looks like the code 'int myvar = 1 + 1' is just one line that should have a coverage count of 1, but the instruction coverage is 2... its like that for all other pieces of code...

So this leads me to believe that Jacoco counts instructions... is there any way to also collect the line being executed (what instructions are on the same line --> they would mutually increment the line count by 1)

Or is this impossible? Could someone give a small reason why this is 'out of scope' or so hard to implement? Is it just the way that jacoco is designed that it is impossible to collect the line exe count?

Many thanks



By the way, the above report was made with this small change to jacoco:
```
+++ b/org.jacoco.report/src/org/jacoco/report/internal/html/page/SourceHighlighter.java
@@ -103,6 +103,13 @@ final class SourceHighlighter {
 
                final String lineId = "L" + Integer.toString(lineNr);
                final ICounter branches = line.getBranchCounter();
+         final ICounter instructions = line.getInstructionCounter();
+         pre.span().text(
+                 "intCOV " +  Integer.toString(instructions.getCoveredCount()) +
+                 " intMIS " + Integer.toString(instructions.getMissedCount()) +
+                 " brCOV " +  Integer.toString(branches.getCoveredCount()) +
+                 " brMIS " + Integer.toString(branches.getMissedCount())
+         );
```



My final question is, is there a way in the code to get "How many instructions are in the current ILine from within the Source Highlighter (or anywhere else in the code.) ? Does such a  thing exist in the code?

If I can get the # of instructions in a line, I can divide the amount of covered instructions by the # of instructions per line to get the line execution count.



many thanks

Marc R. Hoffmann

unread,
Nov 9, 2014, 3:25:23 PM11/9/14
to jac...@googlegroups.com
Hi,

in the context of JaCoCo 'instructions' means bytecode instructions. Each source line with executable code maps to at least one instruction. As Java bytecode is very low-level, typically multiple instructions may be required to compile a single line of source code.

JaCoCo also evaluates line coverage if class files have been compiled with debug information. With the API as well as the XML report you can determine the execution status of everyl line (executed, not executed, partly executed).

Issue 89 refers to execution count (how many times a line has been executed). The primary purposes of a code coverage tool is to identify untested code. The use cases for executions counting typically come from performance profiling which is out of scope for JaCoCo (especiall as the implementation would add significant performance penalties).

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.
For more options, visit https://groups.google.com/d/optout.

Andrei

unread,
Nov 9, 2014, 3:30:38 PM11/9/14
to jac...@googlegroups.com
Marc, I will check out what jacoco provides for line coverage, but I am looking for the # of times a line has been executed. It is something that I would like to see in code coverage. If I cant get that with jacoco I might have to go with cobertura as it does provide exactly those numbers in the reports.

I understand that this is more of a performance profiling thing... but if I went with a performance profiling tool and profiled my unit test runs, then wouldnt that turn the performance profiler into a code coverage tool also?





Regards,

Andy

--
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/Y93VdRmvruM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.

Andrei

unread,
Nov 9, 2014, 3:32:35 PM11/9/14
to jac...@googlegroups.com
Marc, by the way... lets assume that I will always be running my unit tests in debug mode. Would it then be possible to get the # of time a line has been executed? Or is it possible to get the # of instructions a line has so I can calculate that on my own?





Regards,

Andy

Marc R. Hoffmann

unread,
Nov 9, 2014, 3:35:26 PM11/9/14
to jac...@googlegroups.com
Hi Andy,

as far as I know Cobertura provides line execution count - at the price of bigger runtime overhead that JaCoCo.

Profiling has very different objectives and you need more information like execution time. JaCoCo has a clear focus on low-impact code coverage analysis and will not try to become a profiler. There are excellent tools for this on the market.

Cheers,
-marc

Marc R. Hoffmann

unread,
Nov 9, 2014, 3:38:22 PM11/9/14
to jac...@googlegroups.com
Hi Andy,

I wrote "JaCoCo also evaluates line coverage if class files have been compiled with debug information".

This means: No need to run it in debug mode. You won't get execution count with JaCoCo in any case.

Regards,
-marc

Andrei

unread,
Nov 9, 2014, 3:40:13 PM11/9/14
to jac...@googlegroups.com
By running in debug mode, I meant compiling all of the source code with debug information.

Im starting to think that implementing this is not something I can do by myself.





Regards,

Andy

Andrei

unread,
Nov 9, 2014, 4:41:58 PM11/9/14
to jac...@googlegroups.com
Dear Marc, maybe you can stop me from working on this too much before I waste too much time. I do not understand why this is not possible with jacoco because it counts how many instructions were executed, and it also has a notion of a line counter and many uses of a ILine interface, so why cant it put the two together?

Also, could you estimate how much effort would be needed to implement this? I want to use jacoco because it is updated more often then cobertura and it seems to have a more active community.

I understand it would hinder performance, but maybe we can come up with a patch for people who want this feature but dont care about performance.

Thanks





Regards,

Andy

Marc R. Hoffmann

unread,
Nov 9, 2014, 5:36:56 PM11/9/14
to jac...@googlegroups.com
Hi Andy,

looks like we're not yet on the same page: JaCoCo determines for every instruction whether it was executed or not. JaCoCo does not count how many times a particular instruction was executed. See the difference?

Regards,
-marc
-- 

Andrei

unread,
Nov 9, 2014, 6:08:50 PM11/9/14
to jac...@googlegroups.com
Oh, yes now I see the difference. Well in that case, would is not be easy to also count how many times every instructions gets executed in the same place where it counts if it was executed?





Regards,

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