org.cdlib.xtf.lazyTree
Class ProfilingListener

Object
  extended by ProfilingListener
All Implemented Interfaces:
EventListener, TraceListener

public class ProfilingListener
extends Object
implements TraceListener

Used to keep track of the current instruction being executed, and to keep track of counts for each one.

Author:
Martin Haye

Nested Class Summary
static class ProfilingListener.ProfileCount
          Simple data structure to keep track of counts.
 
Field Summary
private static ProfilingListener.ProfileCount emptyInstr
          Dummy used for counting nodes when no instruction is specified
private  ThreadLocal tlCountMap
          Keeps a count of how many nodes are accessed by each instruction.
private  ThreadLocal tlInstructionStack
          Stack of instructions, used to keep track of what XSLT instruction is being processed.
 
Constructor Summary
ProfilingListener()
           
 
Method Summary
 void bumpCount(int nodeNum)
          Increases the count by one for the current instruction.
 void close()
          Unused
 void endCurrentItem(Item currentItem)
          Unused
 void enter(InstructionInfo instruction, XPathContext context)
          Record the instruction being entered, so that subsequent counts can be attributed to it.
private  HashMap getCountMap()
          Get a thread-local count map
 ProfilingListener.ProfileCount[] getCounts()
          Gets a list of all the counts, sorted by ascending count.
private  LinkedList getInstructionStack()
          Get a thread-local instruction stack
 void leave(InstructionInfo instruction)
          Called when an instruction is exited.
 void open()
          Unused
 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

tlInstructionStack

private ThreadLocal tlInstructionStack
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.


emptyInstr

private static final ProfilingListener.ProfileCount emptyInstr
Dummy used for counting nodes when no instruction is specified


tlCountMap

private ThreadLocal tlCountMap
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

ProfilingListener

public ProfilingListener()
Method Detail

open

public void open()
Unused

Specified by:
open in interface TraceListener

close

public void close()
Unused

Specified by:
close in interface TraceListener

getInstructionStack

private LinkedList getInstructionStack()
Get a thread-local instruction stack


getCountMap

private HashMap getCountMap()
Get a thread-local count map


enter

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

Specified by:
enter in interface TraceListener

leave

public void leave(InstructionInfo instruction)
Called when an instruction is exited. Subsequent counts 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

bumpCount

public void bumpCount(int nodeNum)
Increases the count by one for the current instruction.


getCounts

public ProfilingListener.ProfileCount[] getCounts()
Gets a list of all the counts, sorted by ascending count. The act of getting the counts 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