org.cdlib.xtf.crossQuery
Class TimeProfilingListener

Object
  extended by TimeProfilingListener
All Implemented Interfaces:
EventListener, TraceListener

public class TimeProfilingListener
extends Object
implements TraceListener

Used to keep track of the current instruction being executed, and to keep track of time spent in each one.

Author:
Martin Haye

Nested Class Summary
static class TimeProfilingListener.ProfileInstr
           
static class TimeProfilingListener.ProfileTime
           
 
Field Summary
private  ThreadLocal<LinkedList<TimeProfilingListener.ProfileInstr>> stack
          Stack of instructions, used to keep track of what XSLT instruction is being processed.
private  ThreadLocal<HashMap<TimeProfilingListener.ProfileInstr,TimeProfilingListener.ProfileTime>> timeMap
          Keeps a count of how many nodes are accessed by each instruction.
 
Constructor Summary
TimeProfilingListener()
           
 
Method Summary
private  void addTime(TimeProfilingListener.ProfileInstr instr, long selfTime)
          Add time to a given instruction
private  void clearStack()
          Clear the stack, and put the global entry at the top of it.
 void close()
          Called when finished processing the stylesheet.
 void endCurrentItem(Item currentItem)
          Unused
 void enter(InstructionInfo instruction, XPathContext context)
          Record the instruction being entered, so that subsequent times can be attributed to it.
 TimeProfilingListener.ProfileTime[] getTimes()
          Gets a list of all the times, sorted by ascending time.
 void leave(InstructionInfo instruction)
          Called when an instruction is exited.
 void open()
          Called when the stylesheet begins execution, but before any instructions.
 void printProfile()
          Prints the results of a trace run, to Trace.info().
 void startCurrentItem(Item currentItem)
          Unused
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

private ThreadLocal<LinkedList<TimeProfilingListener.ProfileInstr>> stack
Stack of instructions, used to keep track of what XSLT instruction is being processed. Must be thread-local, since the same stylesheet may be in use by multiple threads at one time.


timeMap

private ThreadLocal<HashMap<TimeProfilingListener.ProfileInstr,TimeProfilingListener.ProfileTime>> timeMap
Keeps a count of how many nodes are accessed by each instruction. Must be thread-local, since the same stylesheet may be in use by multiple threads at one time.

Constructor Detail

TimeProfilingListener

public TimeProfilingListener()
Method Detail

open

public void open()
Called when the stylesheet begins execution, but before any instructions.

Specified by:
open in interface TraceListener

close

public void close()
Called when finished processing the stylesheet. We finish up the profile.

Specified by:
close in interface TraceListener

clearStack

private void clearStack()
Clear the stack, and put the global entry at the top of it.


enter

public void enter(InstructionInfo instruction,
                  XPathContext context)
Record the instruction being entered, so that subsequent times can be attributed to it.

Specified by:
enter in interface TraceListener

addTime

private void addTime(TimeProfilingListener.ProfileInstr instr,
                     long selfTime)
Add time to a given instruction


leave

public void leave(InstructionInfo instruction)
Called when an instruction is exited. Subsequent times get applied to the instruction that was previously active.

Specified by:
leave in interface TraceListener

startCurrentItem

public void startCurrentItem(Item currentItem)
Unused

Specified by:
startCurrentItem in interface TraceListener

endCurrentItem

public void endCurrentItem(Item currentItem)
Unused

Specified by:
endCurrentItem in interface TraceListener

getTimes

public TimeProfilingListener.ProfileTime[] getTimes()
Gets a list of all the times, sorted by ascending time. The act of getting the times clears out the table, so that a fresh profile can be made of the next run.


printProfile

public void printProfile()
                  throws IOException
Prints the results of a trace run, to Trace.info().

Throws:
IOException