|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.util.CallTracer
CallTracer is a utility class for tracing calls to methods in a class. This is a poor man's OptimizeIT or JProbe type of tool. Use to figure out where methods are being called from and with what frequency. To use, do something like:
Class Foo { private static CallTracer s_trace = new CallTracer(Foo.class, 100); public foo() { s_trace.trace(); // work.... } public bar() { s_trace.trace(); // work.... } }
In this example, the CallTracer will independently track calls to foo() and bar(), and send a report to the log every 100 calls of: every caller of foo (or bar) and it's count.
The CallTracer _will not_ log unless DEBUG level in log4j is set for the class being traced.
Obviously, using CallTracer can impose a signifigant overhead.
See bug 113696 for an example of how this class can be used.
Constructor Summary | |
CallTracer(Class theClass,
int frequency)
Creates a call tracer for a given class. |
|
CallTracer(Class theClass,
int frequency,
int level)
Creates a call tracer for a given class. |
Method Summary | |
static String |
getCaller()
Utility method to get the caller of a method |
static String |
getCaller(int level)
Utility method to get the caller of a method |
void |
trace()
Records the caller of the method that called trace(). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CallTracer(Class theClass, int frequency)
theClass
- The class we want to track methods on.frequency
- The number of hits for each method before
the system dumps the callers & counts to the log.public CallTracer(Class theClass, int frequency, int level)
theClass
- The class we want to track methods on.frequency
- The number of hits for each method before
the system dumps the callers & counts to the log.level
- The caller level to log at. The default is one, meaning the
immediate caller of the method being traced. Setting the
level higher will trace the caller's caller's ....etc instead.
Default should be used in most instances.Method Detail |
public void trace()
public static String getCaller()
public static String getCaller(int level)
level
- The level of the caller. 1 - immediate parent, 2 - grandparent, etc...
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |