com.arsdigita.util
Class CallTracer

java.lang.Object
  extended bycom.arsdigita.util.CallTracer

public class CallTracer
extends Object

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.

Version:
$Revision $1 $ $Date: 2004/04/07 $
Author:
jorris@redhat.com

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

CallTracer

public CallTracer(Class theClass,
                  int frequency)
Creates a call tracer for a given class.

Parameters:
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.

CallTracer

public CallTracer(Class theClass,
                  int frequency,
                  int level)
Creates a call tracer for a given class.

Parameters:
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

trace

public void trace()
Records the caller of the method that called trace().


getCaller

public static String getCaller()
Utility method to get the caller of a method

Returns:
The file listing where the method was called from

getCaller

public static String getCaller(int level)
Utility method to get the caller of a method

Parameters:
level - The level of the caller. 1 - immediate parent, 2 - grandparent, etc...
Returns:
The file listing where the method was called from


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC