A bit of history
BTrace origins go back more than 10 years and it shows that the modus operandi at that time was to have one JVM at a time and do all the experiments and debugging on that single JVM.The standard workflow for BTrace dynamic attach was decided to be:
- Identify the JVM to attach to
- Attach to that JVM and deploy the probe(s)
- Stay connected until you are satisfied with the results
Time to fix
- 'Detach client' client command
In addition to 'Exit' option in the BTrace CLI it is now possible to detach from the running session.
Upon detaching a unique probe ID is displayed which can be used to later reconnect to that probe.
- 'List probes' client command
This command will list any probes which were deployed and the clients left them detached.
- List probes from command line
Use btrace -lp <pid> to list the probes in detached mode in a particular JVM - Reconnect to a detached probe
Use btrace -r <probe id> <pid> to reconnect to a detached probe and start receiving probe data.
The detached probes are maintaining a circular buffer for the latest data so you can get a bit of history after reconnecting as well. - Attach a probe and disconnect immediately
Useful shortcut for scripting BTrace deployments when the probe is deployed and the client disconnects immediately.
Use btrace <btrace options> -x <pid> <probe file> to run in this mode.
Upon disconnecting the probe ID is printed out so it can be eg. processed and stored.
New possibilities
./bin/btrace -r $(./bin/btrace -lp anagrams.jar | fgrep AllMethods1 | cut -f2 -d' ') anagrams.jar