How do I use jcoz?
mkst opened this issue · comments
Per title.
I've managed to compile the library, create the jar and compile the tests, but that is as far as I've got.
As part of my learning I've created a Dockerfile and tweaked the pom.xml which I'll raise a PR for if you guys are interested.
I am able to start the test.TestThreadSerial
class, e.g.
[ec2-user@monolith:~/mark/JCoz/bin]$ java -agentpath:$(readlink -f liblagent.so) test.TestThreadSerial -s
Iteration done
Iteration done
Iteration done
...
but trying to run the other (at the same time...) fails miserably trying to connect to localhost:
[ec2-user@monolith:~/mark/JCoz/bin]$ java -agentpath:$(readlink -f liblagent.so) test.JCozServiceTest
Exception in thread "main" com.vernetperronllc.jcoz.service.JCozException: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)
at com.vernetperronllc.jcoz.client.cli.RemoteServiceWrapper.<init>(RemoteServiceWrapper.java:54)
at com.vernetperronllc.jcoz.client.cli.RemoteServiceWrapper.<init>(RemoteServiceWrapper.java:64)
at test.JCozServiceTest.main(JCozServiceTest.java:41)
Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused (Connection refused)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:338)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:112)
at com.vernetperronllc.jcoz.client.cli.RemoteServiceWrapper.<init>(RemoteServiceWrapper.java:52)
... 2 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 more
I'm clearly missing something, but after reading the wiki/faq/readme files I'm none-the-wiser!
It’s probable that the wiki is stale. I’ll go through it when I’m back from Japan and make sure it’s accurate and up to date. Apologies that I can’t help you debug remotely - I’ll have to page a lot of this context back in.
Also interested in this. Thanks for your work on this project — it looks really promising!
Also interested in this, running on Fedora.
Hey @streetster, it looks like the issue may be that you haven't started a JCozService process. The JCozService (https://github.com/Decave/JCoz/blob/master/src/java/src/main/java/com/vernetperronllc/jcoz/service/JCozService.java) runs on the same host as the process you want to profile, and is used as the communication endpoint for the "client". So you've done the right thing by starting test.TestThreadSerial with the JCoz native agent, but you also need to start a JCozService to actually communicate with it over JNI, and then use a client (e.g. test.JCozServiceTest) which communicates with that to actually configure and start a profiling session, and consume the results. Note as well that you don't need to run the client or the service with the native agent - the native agent is only required for JVM processes you actually want to profile.
I realize this is quite complicated. Now that it's clear that people want this tool, I'm going to spend some time making it more clear and usable. Starting with adding context to the wiki, and improving our error messages and in-code documentation.
Steps (assuming you've build everything):
- Start up
service.JCozService
java -cp client-0.0.1-jar-with-dependencies.jar:/usr/local/openjdk-8/lib/tools.jar jcoz.service.JCozService > service.log &
- Start up
test.TestThreadSerial
java -cp client-0.0.1.jar:. -agentpath:$(readlink -f liblagent.so) test.TestThreadSerial -s > tts.log &
3a. Start up test.JCozServiceTest
java -cp client-0.0.1.jar:. test.JCozServiceTest | tee jcoz.log
OR
3b. Run cli (needs apt-get update && apt-get install -y procps
first as pgrep isnt in the docker image)
java -cp /usr/local/openjdk-8/lib/tools.jar:client-0.0.1-jar-with-dependencies.jar:. \
jcoz.client.cli.JCozCLI \
-c test.TestThreadSerial \
-l 38 \
-p $(pgrep -f test.TestThreadSerial) \
-s test
LGTM - the only clarification is: do you need to run test.JCozServiceTest with the agent? That test functions as a "client", and from what I recall should be able to communicate with test.TestThreadSerial over JNI without itself needing to be run with the agent.
Tested successfully and amended the comment:
pre-requisite docker build . -t jcoz
mark@carbon:~/github/JCoz$ docker run --rm -ti jcoz:latest bash
root@880e4a534d77:/jcoz# java -cp client-0.0.1.jar:/usr/local/openjdk-8/lib/tools.jar jcoz.service.JCozService > service.log &
[1] 6
root@880e4a534d77:/jcoz# java -cp client-0.0.1.jar:. -agentpath:$(readlink -f liblagent.so) test.TestThreadSerial -s > tts.log &
[2] 25
root@880e4a534d77:/jcoz# java -cp client-0.0.1.jar:. test.JCozServiceTest | tee jcoz.log
experiment selected=test.TestThreadSerial:75 speedup=0.6 duration=5002948241
progress-point name=end-to-end type=source delta=0
experiment selected=test.TestThreadSerial:81 speedup=0.0 duration=10002245662
progress-point name=end-to-end type=source delta=0