Profiling Your Own Code

This shows you how to add profiling to your own code.

Factory Methods and Interface-based objects

Normally you will have something like this in your code (eg in MyFactory.java) to retrieve a manager object:

public PersistenceManager getPersistenceManager()
{
    return new DefaultPersistenceManager();
}
                

To get a profiled manager object instead, use:

public PersistenceManager getPersistenceManager()
{
    return ObjectProfiler.getProfiledObject(PersistenceManager.class, new DefaultPersistenceManager());
}
                

Note that a side effect of this is that you will no longer be able to downcast to DefaultPersistenceManager. This is probably a good coding practice anyway, but it is something to be aware of.

Webwork 1.3

Use our modified webwork-050503-profiling.jar instead of your normal webwork.jar.

In your code

Simply add these lines around the code you wish to profile.

UtilTimerStack.push("some text");
//code that you want to profile
UtilTimerStack.pup("some text"); // this needs to be the same text as in push()
                

Turning in On and off

Using the URL

The servlet filter can be turned on or off using a single URL parameter. See the configuration doc for an example and how to set the parameter for your application.

Using code

If you want to do it in code, use:

UtilTimerStack.setActive(true)
Internally this sets the system property UtilTimerStack.ACTIVATE_PROPERTY to true.

Determining if profiling is on

In your code you can check if profiling is turned on using:

System.getProperty(UtilTimerStack.ACTIVATE_PROPERTY)

Setting the minimum time reported

You can also set the minimum time reported in the trace when profiling. You probably only want to profile methods that take more than 50ms, which is done like so:

System.setProperty(UtilTimerStack.MIN_TIME, "50");
Now only methods that take more than 50ms will be reported in the results.