public abstract class MethodTraceAspect
extends java.lang.Object
aop.xml file. That concrete aspect must define a pointcut for the abstract scope() method.
Although the tracing advice implementation is designed to introduce as little overhead as possible, the overhead is quite noticeable while data collection is active (less so while it is disabled). This overhead will be reflected in the collected data, and it should be taken into account when analyzing the results. Part of the overhead is due to the load-time weaving of this aspect with the classes it is measuring. This weaving is done once, when the target class is first loaded into the JVM. To minimize the impact of this one-time weave on the trace results, it is recommended to perform the work flow to be measured once before starting data collection, then perform it again with data collection turned on. However, this is not always possible, if what is being measured is the first-time execution of a code path, where future executions will be short-circuited by caching of various resources by the runtime.
Due to the aforementioned overhead which this feature introduces to running code, it is recommended not to enable this feature in production deployments.
Tracing is controlled by the enableDataCollection(boolean) method. When an active
tracing session is disabled, all data which has been collected up to that point is
post-processed and written to a CSV file, then discarded.
| Modifier and Type | Class and Description |
|---|---|
private static class |
MethodTraceAspect.BucketData
A class which organizes method trace data into specific buckets.
|
private static class |
MethodTraceAspect.ByTotalTime
A comparator which sorts trace data objects into descending order by total elapsed time.
|
private static class |
MethodTraceAspect.Call
Representation of a method invocation which identifies the caller and the callee methods,
optimized for use as a hash map key.
|
private static interface |
MethodTraceAspect.ElapsedTimeable
An interface with one method to return elapsed time.
|
private static class |
MethodTraceAspect.MethodIdentifier
A wrapper for a method, optimized for use as a hash map key.
|
private static class |
MethodTraceAspect.TraceBucket
Trace data for a single analysis bucket, including the trace data itself and an aggregate
of all the traces' own times.
|
private static class |
MethodTraceAspect.TraceData
Data structure containing invocation count and aggregate elapsed time for a method call.
|
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String[] |
buckets
Package "buckets" for data post-processing
|
private static java.lang.ThreadLocal<java.util.Deque<MethodTraceAspect.TraceData>> |
callStack
Thread-local stack of trace data since entering the first join point in the traced code
|
private static java.lang.String |
CSV_FILE
Fixed name of CSV output file (written to current directory)
|
private static java.lang.String |
DATA_OUTPUT
The name of the folder where the trace data will be dumped to be used by the HTML UI
|
private static boolean |
enabled
Flag which controls data collection
|
private static CentralLogger |
LOG
Logger
|
private static java.lang.String |
METHOD_LIST_FILE
Fixed name of all methods list CSV output file (written to current directory)
|
private static java.lang.String |
SUMMARY_FILE
Fixed name of summary CSV output file (written to current directory)
|
private static java.lang.String |
TRACE_OUTPUT
The name of the folder in which the HTML UI artifacts will be generated
|
private static java.util.Map<MethodTraceAspect.Call,MethodTraceAspect.TraceData> |
traceData
Map of profile data by method signature
|
private static long |
traceStart
Start time of a trace session, in milliseconds
|
| Constructor and Description |
|---|
MethodTraceAspect() |
| Modifier and Type | Method and Description |
|---|---|
private static java.util.Map<MethodTraceAspect.MethodIdentifier,MethodTraceAspect.TraceData> |
aggregatePerMethod()
Retrieve a map between each tracked method and its trace data.
|
static void |
enableDataCollection(boolean enable)
Enable or disable data collection.
|
private static void |
exportHTML()
Routine used for generating a HTML UI used for better interpreting of the data.
|
private static void |
generateAux(java.util.List<java.lang.String> roots)
Helper method for HTML UI generation.
|
private static java.util.Map<MethodTraceAspect.MethodIdentifier,MethodTraceAspect.BucketData> |
getBucketsByRoot()
Utility method used by both HTML and CSV UI.
|
private static java.lang.String |
matchBucket(MethodTraceAspect.MethodIdentifier ident)
Attempt to match a method's declaring class with a data bucket identifier.
|
private static void |
processData()
Post-process the collected trace data and write the result to a CSV file.
|
abstract void |
scope()
An abstract pointcut which should be defined for load-time weaving inside a
concrete-aspect element within META-INF/aop.xml. |
java.lang.Object |
trace(org.aspectj.lang.ProceedingJoinPoint joinPoint)
The primary tracing advice which collects trace information about calls to the target
methods.
|
private static void |
writeAllMethods(java.io.BufferedWriter bw)
Utility method for dumping all the methods traces together with count and own time.
|
private static void |
writeGrandTotals(java.io.BufferedWriter bw,
int len,
long[] totals,
long grandTotalElapsed)
Utility method for CSV exporting of the data.
|
private static final CentralLogger LOG
private static java.lang.String TRACE_OUTPUT
private static java.lang.String DATA_OUTPUT
private static java.lang.String CSV_FILE
private static java.lang.String SUMMARY_FILE
private static java.lang.String METHOD_LIST_FILE
private static volatile boolean enabled
private static long traceStart
private static final java.util.Map<MethodTraceAspect.Call,MethodTraceAspect.TraceData> traceData
private static final java.lang.ThreadLocal<java.util.Deque<MethodTraceAspect.TraceData>> callStack
private static final java.lang.String[] buckets
public static void enableDataCollection(boolean enable)
enable - true to start data collection; false to stop it and process the
results.private static void exportHTML()
private static void generateAux(java.util.List<java.lang.String> roots)
throws java.io.IOException
roots - A list of all JS files we created containing information about multiple traced methods.
These should be dumped in the loader JS which ensures that the data is loaded in the
JS memory.java.io.IOExceptionprivate static java.util.Map<MethodTraceAspect.MethodIdentifier,MethodTraceAspect.BucketData> getBucketsByRoot()
private static void processData()
private static void writeAllMethods(java.io.BufferedWriter bw)
throws java.io.IOException
bw - The writter where this statistic should be written.java.io.IOExceptionprivate static java.util.Map<MethodTraceAspect.MethodIdentifier,MethodTraceAspect.TraceData> aggregatePerMethod()
private static void writeGrandTotals(java.io.BufferedWriter bw,
int len,
long[] totals,
long grandTotalElapsed)
throws java.io.IOException
bw - The writer where the grand totals shoudl be writtenlen - The number of bucketstotals - The total valuesgrandTotalElapsed - The grand total elapsedjava.io.IOExceptionprivate static java.lang.String matchBucket(MethodTraceAspect.MethodIdentifier ident)
ident - Method identifier.null.public abstract void scope()
concrete-aspect element within META-INF/aop.xml.public java.lang.Object trace(org.aspectj.lang.ProceedingJoinPoint joinPoint)
throws java.lang.Throwable
Data is collected safely across all threads on which calls to the traced methods are made.
The caller method is determined using a thread-local stack, which is cleared any time this advice is entered after data collection has been halted. Note that the relationship between caller and callee may represent an actual, direct invocation if both methods are crosscut by the defined pointcut. Otherwise, if intermediate method invocations are not crosscut, the recorded "caller" may actually represent some "ancestor" method further up the actual call stack. It is assumed that this potential "gap" between caller and callee is understood by and acceptable to the definer of the pointcut.
joinPoint - Join point which represents the method being traced.java.lang.Throwable - if an exception is thrown by the method being traced.