Hi,
I am a Java developer who uses Eclipse every day in my job. I am
interested in contributing towards the development of some interesting
new features which I think would fit into the TPTP project. However, I
would like to get some feedback to help me improve my ideas before I
take this any further.
The two technologies which I have been playing with are the Java
Instrumentation API and ASM2 Bytecode processing library.
*
http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html
* http://asm.ow2.org/
My ideas are all in the area of execution trace recording/processing.
_Recording
_Using a combination of the Java Instrumentation API and ASM2 an Agent
can be used to rewrite class files to capture data about the code which
is executed. This should be stored as efficiently as possible in memory
and streamed to disk as the amount of data becomes too large. I have
implemented a basic prototype Agent that instruments Classfiles to write
trace output to a text file to show which lines of code were executed.
Here is some example output.
Added tracing to: gb.trace.test.TraceExample
No trace added to: gb.trace.agent.output.StdOutWriter
Mon Jan 18 10:00:46 GMT 2010: Branch:TraceExample.java:workMethod:24
Mon Jan 18 10:00:46 GMT 2010: Branch:TraceExample.java:workMethod:31
Mon Jan 18 10:00:46 GMT 2010: Exit:TraceExample.java:workMethod:33
Mon Jan 18 10:00:47 GMT 2010: Branch:TraceExample.java:workMethod:24
Mon Jan 18 10:00:47 GMT 2010: Branch:TraceExample.java:workMethod:31
Mon Jan 18 10:00:47 GMT 2010: Exit:TraceExample.java:workMethod:33
I have enjoyed playing with the Java Instrumentation API and ASM2 as it
feels like a very powerful thing to be able to rewrite Java class files
at startup but also at runtime.
_Processing_
In this section I will refer to a recording as an Execution Trace
Recording (ETR). I have made up this term. There are a number of
interesting things you could do with an ETR.
_-- Textual Trace__
_Output a single line of text listing the timestamp and line number for
each basic block (function, if/else etc) which was executed (See example
above).
_-- Graphical Trace
_Sometimes when trying to work out how some code works I find myself
stepping through the code to see which lines get hit. I could do this
automatically by running a code coverage tool but I don't just want to
know binary executed/not-executed information. I really want to know
what lines were executed and in which order. At a simple level I would
be happy with a list of function calls. It would be even better if I
could drill down into each function call to see which lines were
executed. It would also be good to be able to display the function calls
of multiple threads side by side. This would be a difficult UI to make
usable in situations with many threads. It may be sufficient to allow
particular threads to be added to a multi thread comparison view.
Another point is that I may only be interested in which parts of a
function were executed for a particular invocation of a function. This
would be really easy if I could start/stop the ETR recording while the
target application is still running. The use case I am imaging is
setting a break point part way through a JUnit test in Eclipse, pressing
a "Start Recording" button while the test is suspended, resuming
execution until another breakpoint is hit and pressing a "Stop
recording" button while the test is once again suspended. This kind of
runtime addition/removal of instrumentation is definitely possible with
the Java Instrumentation API (within limits).
_-- JUnit Integration
_Runtime Class rewriting would allow a test to include arbitrary checks
about whether particular bits of code were executed during a test. I am
imagining an API along the lines of
assertFunctionCalled("my.class.name","functionName"). This would be
useful for automated integration tests of large blocks of code where a
single return value could be returned as a result of multiple different
execution paths within the code under test.
_Summary_
These ideas are all pretty vague at this stage. I would love to hear
some feedback on the following points.
* Are these good ideas?
* Do you know of any commercial/open source products implementing
any of this?
* Does TPTP already enable any of this?
* Do these ideas fit into the current plans for TPTP?
* Do you have any suggestions to improve these ideas?
I look forward to hearing from you.
Thanks
MartinHR
_______________________________________________
tptp-tracing-profiling-tools-dev mailing list
tptp-tracing-profiling-tools-dev@eclipse.org
https://dev.eclipse.org/mailman/listinfo/tptp-tracing-profiling-tools-dev