A simple java trace utility
- JDK 1.6 or above
- mvn verify , it will start jspy at port 8585
- open http://localhost:8585, it will show all the currently running VMs on left panel.
- Click on any vmid, it will do an automatic attach and show classloader information
- To trace all classes in a jar, select "show class locations", choose the jar or folder with the classes and click "Start Profiling"
- Under the "Start Profiling" button, we can now see a tree structure with running methods
- we can attach to multiple vms or quickly switch between vms and other fun stuff
- cd jspy-core
- mvn clojure:repl
- (use 'com.imaginea.jspy.spy)
- (def server (start-server))
- connect to http://localhost:8585 (in case of port conflicts use jetty.port system property)
The Apache Software License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0.txt
Depends on java profiling interface and embedded javascript engine to give maximum support for interactive profiling.
- If http port 8585 is already bound to some other process, use jetty.port system property
- If JAVA_HOME is not set, edit tools-home in project.clj
- agent.path and base.commands.path are two other system properties which are used in profiling. agent.path points to the jar location built from the src in jspy-profiler, base.commands.path points to the folder location for the basic commands to get more information from the vm, default location is jspy-core/src/main/resources/commands/ (we need the trailing slash)
curl 'http://localhost:8585/vms'
curl 'http://localhost:8585/vms/attach' -H 'Accept: application/json' -H 'Content-Type: application/json' --data-binary '{"vmId":"21506"}' --compressed -X POST
curl 'http://localhost:8585/vms/command' -H 'Accept: application/json' -H 'Content-Type: application/json' --data-binary '{"vmId":"23608", "command":"dumpThreadNames()"}' --compressed -X POST
curl 'http://localhost:8585/vms/response' -H 'Accept: application/json' -H 'Content-Type: application/json' --data-binary '{"vmId":"23608"}' --compressed -X GET
curl 'http://localhost:8585/vms/detach' -H 'Accept: application/json' -H 'Content-Type: application/json' --data-binary '{"vmId":"23608"}' --compressed -X GET -X POST
in case you like the stack and need the dump of it, run these commands on your browser dev-tool, creates a save function in console, dumps all data from stack as json string, saves that to file console.json (function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
var bigStr = JSON.stringify( d3.select("svg").selectAll("g.node").data(), function( key, value) { if( key == 'parent') { return value.id;} else {return value;} }, ' ')
console.save(bigStr)