Reputation: 23
Hello and thank you in advance for your answers. I would like to know if there is any way to know (using ASM) which lines I've gone through and which ones I haven't on real time. In other words, a way in which, as soon as any method has finished executing, for each execution, I can inject an instrumentation instruction for it to print which lines it has or hasn't gone through
Upvotes: 1
Views: 400
Reputation: 1861
First you should create a class with a static method that logs the line number execution events. It would have a method like this:
public static void lineExecution(String filename, int lineNumber)
Put whatever logic you need. Capture the event in-memory and report at the end, or just write it to stdout.
When you are modifying the target classes with ASM, you need to decorate the visitSource
method in ClassVisitor
.
This method should capture the "source" parameter (the source file) for use later. Then, you need to return a custom MethodVisitor from visitMethod
with a decorated visitLineNumber
method. This method should insert a call to your static method:
ldc (whatever the value of "source" is)
ldc (whatever line number was passed in)
invokestatic LineExecutionMonitor.lineExecution
Thus, whenever a new line number is executed, the first thing that happens it that a call is made to your static method. There you can trace execution within the instrumented class.
Hope this helps.
Upvotes: 1