How to set java VM arguments for Jacoco while using offline instrumentation

590 views
Skip to first unread message

aksa...@gmail.com

unread,
Nov 5, 2018, 5:00:55 PM11/5/18
to JaCoCo and EclEmma Users
Hello Team,

I am using the offline instrumentation of classes. I have couple of queries. Please help to resolve them

1. I have my pre-instrumented classes in folder "instrumented". Now, While running java application I am using below command :
java -cp .:instrumented:jacoco-0.8.1/lib/jacocoagent.jar Main.class server config.yml

How can I give VM arguments to configure Jacoco properties such as output, address and port ?
I have tried -Djacoco-agent.output=tcpserver,address=localhost,port=6301 and also
-Djacoco-agent.output=tcpserver -Djacoco-agent.address=localhost -Djacoco-agent.port=6301

But while dumping the coverage using jacococli.jar it gives error:
Connection to 127.0.0.1(6301) refused.

2. Also what is class path also has same application jar. So there are my instrumented classes and also classes that are non-instrumented in jar without which my Main class gives NoClassFound Error. Placing instrumented class in class path along with Jacoco agent jar will capture the coverage ?

Please help to resolve these queries

Evgeny Mandrikov

unread,
Nov 5, 2018, 7:09:18 PM11/5/18
to JaCoCo and EclEmma Users
Hi,

On Monday, November 5, 2018 at 11:00:55 PM UTC+1, aksa...@gmail.com wrote:
Hello Team,

I am using the offline instrumentation of classes. I have couple of queries. Please help to resolve them

1. I have my pre-instrumented classes in folder "instrumented". Now, While running java application I am using below command :
java -cp .:instrumented:jacoco-0.8.1/lib/jacocoagent.jar Main.class server config.yml

How can I give VM arguments to configure Jacoco properties such as output, address and port ?


This is described in documentation on page about offline instrumentation - https://www.jacoco.org/jacoco/trunk/doc/offline.html 
 

I have tried -Djacoco-agent.output=tcpserver,address=localhost,port=6301 and also


This is incorrect - not only "output", but all options should be passed to JVM with prefix "jacoco-agent."
 

-Djacoco-agent.output=tcpserver -Djacoco-agent.address=localhost -Djacoco-agent.port=6301


This seems correct, however
 

But while dumping the coverage using jacococli.jar it gives error:
Connection to 127.0.0.1(6301) refused.


Note that above documentation page says

"The first instrumented class loaded will trigger the initialization of the JaCoCo runtime. If no instrumented class is loaded the JaCoCo runtime will not get started at all."

This might explain why server can't be reached in case of class path specified as

".:instrumented:jacoco-0.8.1/lib/jacocoagent.jar"

if directory "." contains non-instrumented original classes, then they will be loaded first and instrumented classes will never be loaded - please refer to how class path and loading of classes work.

The best is to completely replace original classes by instrumented.
 

2. Also what is class path also has same application jar.

 

So there are my instrumented classes and also classes that are non-instrumented in jar


See above 
 

without which my Main class gives NoClassFound Error. Placing instrumented class in class path

along with Jacoco agent jar will capture the coverage ?


As stated in several places in documentation, including description of offline instrumentation:

"the preferred way for code coverage analysis with JaCoCo is on-the-fly instrumentation with the JaCoCo agent"

exactly because

"This simplifies code coverage analysis a lot as no pre-instrumentation and classpath tweaking is required."

so have you considered usage of

https://www.jacoco.org/jacoco/trunk/doc/agent.html

as

java -javaagent:jacoco-0.8.1/lib/jacocoagent.jar=output=tcpserver -cp . Main.class server config.yml

?

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