Jacoco file size is 0

124 views
Skip to first unread message

jk

unread,
Mar 4, 2019, 12:21:49 AM3/4/19
to JaCoCo and EclEmma Users
Hi All,

I'm a newbie to Jacoco. I needed to perform some code coverage in our webapp. The webapp is shipped as a war file running on tomcat application server. Since I don't have the build information for the webapp as well the source repository for it, the on-fly looked most viable option for me.

I have defined the following in setenv.sh file:
JACOCO_OPTS="-javaagent:/portal/bin/jacoco/lib/jacocoagent.jar=destfile=JACOCO_EXEC_FILE,output=file,append=false"

CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}

when i start the webapp i do the file being created when i do browse the site and shutdown catalina.sh i still the file size as 0

root@xxx-xxxx:/xxxxxxx/bin# ./shutdown.sh
Using CATALINA_BASE: /xxxxxx
Using CATALINA_HOME: /xxxxxx
Using CATALINA_TMPDIR: /xxxxxx/xxxx
Using JRE_HOME: /usr
Using CLASSPATH: /xxxxxxx/bin/bootstrap.jar:/portal/bin/tomcat-juli.jar
-rw-r----- 1 root root 0 Mar 3 16:07 JACOCO_EXEC_FILE
drwxr-x--- 3 root root 4096 Mar 3 16:13 .


i'm using the following versions:
Server version: Apache Tomcat/8.5.29
Server built: Mar 5 2018 13:11:12 UTC
Server number: 8.5.29.0
OS Name: Linux
OS Version: 4.4.0-116-generic
Architecture: amd64
JVM Version: 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12
JVM Vendor: Oracle Corporation

The Jacoco version used is :
jacoco/0.8.3/jacoco-0.8.3.zip
I would appreciate of any insight into how to resolve the issue.

Thanks,
jk

jk

unread,
Mar 4, 2019, 1:30:08 AM3/4/19
to JaCoCo and EclEmma Users
Hi All,

I was able to generate the dump after looking around a bit i replaces the CATALINE_OPTS with the JAVA_OPTS, so now i do see the file being created but 

JACOCO_OPTS="-javaagent:/xxxxx/bin/jacoco/lib/jacocoagent.jar=destfile=JACOCO_EXEC_FILE,output=file,append=false"

-rwxr-xr-x 1 root root    442 Mar  3 16:44 setenv.sh

-rw-r----- 1 root root   2086 Mar  3 16:47 JACOCO_EXEC_FILE


But now i need to create the report from the file. I would greatly appreciate if someone could help me on it. I tried the following:


java -jar <path to jacoco.jar> report JACOCO_EXEC_FILE --classfiles ../webapps/ROOT/WEB-INF/classes/  -html . -name output.html


It did generate the output.html but everything was 0% . I did minimalistic testing on website so it may be due to that. I'll try to do more exhaustive tests to check.


I would appreciate if someone could comment if i'm on the right track or if i should try something else.


Thanks,

jk.

Jitendra Kumar

unread,
Mar 4, 2019, 2:00:52 AM3/4/19
to JaCoCo and EclEmma Users
Hi JK,

pre-requsites:

downloa 

jacoco-0.8.3.zip

0.8.3

2019/01/23

3.7 MB

d4f07cb98bbf2305dbd16ee3012d7321


extract and navigate to lib directory, jacococli.jar will be there in lib dir.

The most important thing while generating HTML report from the *.exec file is providing correct src and class files path so exec file can map the consumption of code and give you report HTML.
for that you run like below command:

java -jar <path to jacoco directory>/lib/jacococli.jar report <exec file path>  --classfiles <TOMCAT_HOME>/webapps/dummy/WEB-INF/classes/ --sourcefiles /opt/dummy/web-inf/classes/  --html /tmp/report

run command like above. you will get html report for sure.


Thanks,

Jiten

Evgeny Mandrikov

unread,
Mar 4, 2019, 7:28:41 AM3/4/19
to JaCoCo and EclEmma Users
 
On Sunday, March 3, 2019 at 9:21:49 PM UTC-8, jk wrote:

shutdown catalina.sh i still the file size as 0



JaCoCo creates an empty file at startup to ensure that location is writable.
So please make sure that you do not just kill Tomcat, but terminate it gracefully with execution of all shutdown hooks.

Konteya Joshi

unread,
Mar 4, 2019, 9:49:12 AM3/4/19
to jac...@googlegroups.com
Hi Jiten,

Thanks for your reply.

One question : sourcefiles parameter is that the location of the .java files?

I’m asking as I don’t have the access to the product code. Is it possible to generate the report for. Just the class files using —classfiles.

Thanks,
Jk.

--
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/DZNqIGaoPKQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/277a9bf5-66a7-4179-a933-a9867a797af9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Konteya Joshi

unread,
Mar 4, 2019, 9:52:43 AM3/4/19
to jac...@googlegroups.com
Hi Evgeny,

Thanks for the response.

I was able to resolve the 0 sized issue which I updated in the follow up comment.

For some reason I couldn’t update the heading of the issue my question is related to the generation of the html report from 
--
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/DZNqIGaoPKQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.

Evgeny Mandrikov

unread,
Mar 4, 2019, 10:00:52 AM3/4/19
to JaCoCo and EclEmma Users

On Monday, March 4, 2019 at 3:49:12 PM UTC+1, jk wrote:
One question : sourcefiles parameter is that the location of the .java files?

 Yes

I’m asking as I don’t have the access to the product code. Is it possible to generate the report for. Just the class files using —classfiles.

Yes - as you can see in documentation ( https://www.jacoco.org/jacoco/trunk/doc/cli.html ) "--sourcefiles" is optional parameter.

Jitendra Kumar

unread,
Mar 4, 2019, 10:58:13 AM3/4/19
to JaCoCo and EclEmma Users
Hi JK,

The answer is YES, but you will not get a meaningful report.
Assume in your application you have just accessed login page and assume LoginPage.java is executed, along with that some more java src consumed from LoginPage.java, so once .class files generated you will be able to generate the report without using the java source code of your project but .class & source mapping will not happen meant which code snippet is consumed (green highlighted) and which part is not even accessed or executed means may be dead code (red highlighted). 

ultimately without the source, you will not be able to find dead code/un accessed code from your source code files for which you are using jacoco.

Thanks,
Jiten
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.

Konteya Joshi

unread,
Mar 6, 2019, 2:18:16 AM3/6/19
to jac...@googlegroups.com
Hi All,

Thanks Jitender and Evgeny!

This is a follow question. Issue i'm seeing is the code coverage for all the packages is all 0%
java -jar jacoco/lib/jacococli.jar report JACOCO_EXEC_FILE --classfiles ~/1/ --html report 

After which i see the pakage structure created in output directory along with index.html and jacoco-session.html. However when i view the index.html the coverage is 0% for all
image.png


Note in the command above ~/1 is the directory where i have copied all the .class files. Since i don't which class files are used i copied all the class files for WEB-INF to 1 as follows:

cd /xxxxxx/webapps/ROOT/WEB-INF/classes/com


find . -type f -name "*class" -print0| xargs -0 -I {} cp {} ~/1/


I would appreciate your help.

Thanks,
JK.


Jitendra Kumar

unread,
Mar 6, 2019, 4:21:51 AM3/6/19
to JaCoCo and EclEmma Users
Hi JK,

I need some inputs from you.

steps: 

1. Startup your tomcat/container and perform some operations on a web application so some of the class files consumed by some random operation like login etc.
2. Shutdown tomcat gracefully - /<tomcat server dir>/bin/shutdown.sh/bat etc.
3. now verify the size of generated jacoco.exec file in your case <JACOCO_EXEC_FILE>

Now run "java -jar jacoco/lib/jacococli.jar report JACOCO_EXEC_FILE --classfiles ~/1/ --html report" command 

some more input like below:

while running above command what you are getting in the console I mean how many class files getting consumed.

[INFO] Loading execution data file JACOCO_EXEC_FILE.
[INFO] Analyzing <????> classes.

how many class files ?? and if possible share your exec file that would be great to solve the issue.

Thanks,
Jitendra

Jitendra Kumar

unread,
Mar 6, 2019, 4:36:10 AM3/6/19
to JaCoCo and EclEmma Users
According to the command only JACOCO_EXEC_FILE file having an issue, meaning it is not containing proper data or something.

-Jitendra

Jitendra Kumar

unread,
Mar 6, 2019, 4:38:00 AM3/6/19
to JaCoCo and EclEmma Users
If EXEC file is not proper, in that case, it will always generate 0% code coverage for sure.

-Jitendra

Evgeny Mandrikov

unread,
Mar 6, 2019, 5:53:00 AM3/6/19
to JaCoCo and EclEmma Users


On Wednesday, March 6, 2019 at 8:18:16 AM UTC+1, jk wrote:
This is a follow question. Issue i'm seeing is the code coverage for all the packages is all 0%
java -jar jacoco/lib/jacococli.jar report JACOCO_EXEC_FILE --classfiles ~/1/ --html report 

After which i see the pakage structure created in output directory along with index.html and jacoco-session.html. However when i view the index.html the coverage is 0% for all

This also has already been answered many times in this mailing list:

the general advice is to check the "Sessions" page ( link from "index.html" is in the right upper corner and points to "jacoco-session.html" ), which contains information about exec file
classes not listed on this page either have not been executed or have not been seen by the JaCoCo agent
classes listed here, but without link - different version of the class was used at runtime than at report generation time

Konteya Joshi

unread,
Mar 6, 2019, 5:00:00 PM3/6/19
to jac...@googlegroups.com
Thanks Jitendra and Evgeny for your input.

Please find my comments as it will help in answering the questions :
1) Contents of setup.sh :
JACOCO_OPTS="-javaagent:/portal/bin/jacoco/lib/jacocoagent.jar=destfile=jacoco.exec,output=file,append=true"
#set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=1024m -javaagent:C:/Install/apache-tomcat-7.0.54/jacoco/jacocoagent.jar=destfile=C:/Install/apache-tomcat-7.0.54/jacoco/ST/jacoco.exec,append=false
#CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}"
JAVA_OPTS="${JAVA_OPTS} ${JACOCO_OPTS}"

After which i start the ./startup.sh for webserver (which start catalina.sh). I see the java process started:
root@portal-tb3:/portal/bin# ps -ef|grep java
root     29402     1 87 08:39 pts/0    00:01:17 /usr/bin/java -Djava.util.logging.config.file=/portal/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -javaagent:/portal/bin/jacoco/lib/jacocoagent.jar=destfile=jacoco.exec,output=file,append=true -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /portal/bin/bootstrap.jar:/portal/bin/tomcat-juli.jar -Dcatalina.base=/portal -Dcatalina.home=/portal -Djava.io.tmpdir=/portal/temp org.apache.catalina.startup.Bootstrap start

Following which i do some browsing on the site
Subsequently shutdown.sh(which calls catalina shutdown)
No matter how many test cases i run i always get the jacoco.exec file of the same size(which looks suspicious):
-rw-r----- 1 root root   2086 Mar  6 08:41 jacoco.exec

The contents of the jacoce.exec file are cryptice looks like its a proprietary format , adding a screenshot here:

Screen Shot 2019-03-06 at 1.51.05 PM.png



Subsequently i generate the report from the exec file:
java -jar jacoco/lib/jacococli.jar report jacoco.exec --classfiles /webapps/ROOT/WEB-INF/classes/ --html report

[INFO] Loading execution data file /portal/bin/jacoco.exec.
[INFO] Analyzing 3394 classes.

The coverage report has the packages but the coverage is 0%.

As a troubleshooting i tried to copy the .class files form /webapps/ROOT/WEB-INF/classes/ to 1 and tried to generate a report from it , but i see the same results.

My hunch : Looks like there is some issue in generating the jacoco.exec, as i see the exec file of the same size 2086 bytes despite of how much tests i run or even with no tests.

I would appreciate your help in this issue.

Thanks,
Konteya.



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/f994b6f8-1bbe-413a-8050-c5550065d65c%40googlegroups.com.

Konteya Joshi

unread,
Mar 6, 2019, 5:22:13 PM3/6/19
to jac...@googlegroups.com
One more data point, didn't mention it in my last email. In Jacoce session i don't see the webapp specific packages but generic java packages:

This coverage report is based on execution data from the following sessions:

SessionStart TimeDump Time
portal-tb3-9520fd64Mar 6, 2019 7:13:24 AMMar 6, 2019 7:13:24 AM

Execution data for the following classes is considered in this report:

ClassId
org.apache.catalina.LifecycleStated852263a2396f00f
org.apache.catalina.core.NamingContextListener452717f152912d7c
org.apache.catalina.core.StandardServera7539e87b0244e61
org.apache.catalina.deploy.NamingResourcesImpl2f3f2a5bb2334e34
org.apache.catalina.security.SecurityClassLoad73724d336975ef8e
org.apache.catalina.security.SecurityConfig20b1920b1c4845b0
org.apache.catalina.startup.Bootstrap761d4791c592d74a
org.apache.catalina.startup.Catalina3f3b3bcb21c7df6e
org.apache.catalina.startup.CatalinaProperties0a403607de81c2b1
org.apache.catalina.startup.ClassLoaderFactory637589ae074b37b0
org.apache.catalina.startup.ClassLoaderFactory.2f884fbe3ffea9504
org.apache.catalina.startup.ClassLoaderFactory.Repository64e04a8157026e9a
org.apache.catalina.startup.ClassLoaderFactory.RepositoryType0512519c8a94741f
org.apache.catalina.util.LifecycleBase462c20e1e81adf7d
org.apache.catalina.util.LifecycleMBeanBase581fb22432fd3a3d
org.apache.juli.logging.DirectJDKLog7ad56dd398c4a76e
org.apache.juli.logging.LogFactoryd816f6f12317a8e5
org.apache.tomcat.util.ExceptionUtils8f45b5cc6c246f81
org.apache.tomcat.util.IntrospectionUtilsad77a79a2458fa82
org.apache.tomcat.util.digester.ArrayStack710ed28fbfdd5d18
org.apache.tomcat.util.digester.Digesterefdd845ab94fb176
org.apache.tomcat.util.digester.Digester.SystemPropertySourcebb86c4e6ddcdbb24
org.apache.tomcat.util.digester.ObjectCreateRuleb3bc8f955478c572
org.apache.tomcat.util.digester.Rule0b92708415dbc6d9
org.apache.tomcat.util.digester.RulesBasefa98b7be8cd3adbf
org.apache.tomcat.util.digester.SetNextRule9d43f39c54fbaa21
org.apache.tomcat.util.digester.SetPropertiesRule8a71a46200ae5d2a
org.apache.tomcat.util.res.StringManager7c3e9ecbdd9b53b0
org.apache.tomcat.util.res.StringManager.144bb08d6a97f529b

Thanks,
JK

Jitendra Kumar

unread,
Mar 6, 2019, 11:00:16 PM3/6/19
to JaCoCo and EclEmma Users


Hi JK,

Edit your setup.sh file as below:

JACOCO_OPTS=" -javaagent:<jacoco path>/jacoco/lib/jacocoagent.jar=destfile=<jacoco path>/jacoco/jacoco.exec,append=true,includes=a.b.c.d.*"

 

CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}"


set to Catalina opts not in java opts: why? check below link.


"https://stackoverflow.com/questions/11222365/catalina-opts-vs-java-opts-what-is-the-difference"


and do the same thing again and check.


-Jitendra

Jitendra Kumar

unread,
Mar 6, 2019, 11:23:37 PM3/6/19
to JaCoCo and EclEmma Users
perform some operation on your web app so some class coverage can happen.

Evgeny Mandrikov

unread,
Mar 7, 2019, 7:32:54 AM3/7/19
to JaCoCo and EclEmma Users

On Wednesday, March 6, 2019 at 11:00:00 PM UTC+1, jk wrote: 
The contents of the jacoce.exec file are cryptice looks like its a proprietary format , adding a screenshot here

Please note for future that binary files can be sent as attachments.

On Wednesday, March 6, 2019 at 11:22:13 PM UTC+1, jk wrote:
One more data point, didn't mention it in my last email. In Jacoce session i don't see the webapp specific packages but generic java packages


classes not listed on this page either have not been executed or have not been seen by the JaCoCo agent

And Jitendra is right - in your current setup classes of application are not seen by agent, because JVM that executes application doesn't use agent

On Thursday, March 7, 2019 at 5:00:16 AM UTC+1, Jitendra Kumar wrote:

Edit your setup.sh file as below:

JACOCO_OPTS=" -javaagent:<jacoco path>/jacoco/lib/jacocoagent.jar=destfile=<jacoco path>/jacoco/jacoco.exec,append=true,includes=a.b.c.d.*"

 

CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}"


set to Catalina opts not in java opts: why? check below link.


"https://stackoverflow.com/questions/11222365/catalina-opts-vs-java-opts-what-is-the-difference"


Nice catch, Jitendra !

Please note that specification of "append=true" is redundant, because this is default.
And please be careful with option "includes", because it limits scope of classes that will be processed by agent, and it also has good default value "includes=*".


Regards,
Evgeny

Konteya Joshi

unread,
Mar 7, 2019, 1:43:41 PM3/7/19
to jac...@googlegroups.com
Hi,

Thanks Jitendra and Evgeny for your help and support.

I tried to run with the CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}" but after which the jacoco.exec file generated is of 0 size.

Thanks.
JK.

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

Jitendra Kumar

unread,
Mar 7, 2019, 2:54:20 PM3/7/19
to JaCoCo and EclEmma Users
Hi JK,

Below things might help.
JVM shutdown hook dump data to exec file. for more info - http://www.eclemma.org/jacoco/trunk/doc/faq.html , section <Can I collect coverage information without stopping the JVM?>

-Jitendra

Evgeny Mandrikov

unread,
Mar 7, 2019, 3:18:41 PM3/7/19
to JaCoCo and EclEmma Users

On Thursday, March 7, 2019 at 7:43:41 PM UTC+1, jk wrote:

I tried to run with the CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}" but after which the jacoco.exec file generated is of 0 size.

Using examples that come with Tomcat as following:

java -version

openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)


cat <<END >./apache-tomcat-8.5.29/bin/setenv.sh
CATALINA_OPTS="\${CATALINA_OPTS} -javaagent:/tmp/j/jacoco-0.8.3/lib/jacocoagent.jar=destfile=/tmp/j/jacoco.exec"
END

./apache-tomcat-8.5.29/bin/catalina.sh start


./apache-tomcat-8.5.29/bin/catalina.sh stop 60

I just got non zero file:

ls -l jacoco.exec

-rw-r----- 1 evgeny.mandrikov wheel 38463 Mar  7 20:53 jacoco.exec

That includes information about execution of HelloWorldExample :

java -jar jacoco-0.8.3/lib/jacococli.jar execinfo jacoco.exec | grep HelloWorldExample

f4baf7db7add6fb6   19 of  19   HelloWorldExample

Among many other class files:

java -jar jacoco-0.8.3/lib/jacococli.jar execinfo jacoco.exec | wc -l

703

And got following report:

java -jar jacoco-0.8.3/lib/jacococli.jar report jacoco.exec --classfiles apache-tomcat-8.5.29/webapps/examples/WEB-INF/classes/ --html report


report.png



Jitendra Kumar

unread,
Mar 7, 2019, 10:31:41 PM3/7/19
to JaCoCo and EclEmma Users
Wonderful interpretation Evgeny, sort & sweet, I don't think so anything is left to explain.

Konteya Joshi

unread,
Mar 8, 2019, 11:28:23 AM3/8/19
to jac...@googlegroups.com
Thanks Jitendra and Evgeny for answering my questions. You guys are very helpful and supportive.

I would give example project a try and investigate more into it my issue, would update if find anything interesting specific to my issue.

Thanks,
JK

--
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/DZNqIGaoPKQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages