A collector for RxFiddle to run inside a JVM. The plugin consists of several pieces:
- AST parser which logs the structure of in-source Observables.
- ByteCode instrumentation (BCI) which inserts logging of the creation of, subscription on and data flow through Observables.
- (WebSocket) server emitting all collected events
The ByteCode instrumentation appends logic before and after each method call returning an Observable. This logs the creation of the Observable sequences. Next the ClassVisitors map all subscribe, onNext, onError and onComplete calls.
Create the agent jar by running:
gradle jar
To run the ByteCode instrumentation as an agent start with the following JVM arguments:
-javaagent:build/libs/rxfiddle-java-collector-0.1-SNAPSHOT.jar
This JVM argument can be added to specific Gradle tasks. In samples/simple the argument is configured in build.gradle to always run:
# samples/simple/build.gradle
task(runJavaExecNormal, dependsOn: 'classes', type: JavaExec) {
main = "rxfiddle.samples.simple.Main"
classpath = sourceSets.main.runtimeClasspath
jvmArgs '-javaagent:../../build/libs/rxfiddle-jvm-collector-0.1-SNAPSHOT.jar'
}
so you can just run the following and see the debug output on the command line:
cd samples/simple
gradle run
For references see:
- ScalaDays 2015 Amsterdam presentation by Tal Weiss on BCI
- Jon Bell's blog about Java ByteCode and JVMTI
- Jon Bell's examples on github on using ASM
- One day optimise by using JavaAssist