org.javasimon.callback.calltree
Class CallTreeCallback

java.lang.Object
  extended by org.javasimon.callback.CallbackSkeleton
      extended by org.javasimon.callback.calltree.CallTreeCallback
All Implemented Interfaces:
Callback

public class CallTreeCallback
extends CallbackSkeleton

Callback which logs the call tree when the main call is bigger than specified threshold. This callback can give good results only if interceptors/filters have been placed a different level of the application (web/business/data tiers for instance).

Call tree looks like this:

 org.javasimon.web.Controller.execute 123ms
        org.javasimon.business.FirstService.work 75ms, 75%
                org.javasimon.data.FirstDAO.findAll 50 ms, 82%
                org.javasimon.data.SecondDAO.findByRelation 20ms, 10%, 3
        org.javasimon.business.SecodeService.do 10ms, 5%
 

Since:
3.2
Author:
gquintana
See Also:
CallTree

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javasimon.callback.Callback
Callback.Event
 
Field Summary
static String ATTR_NAME_LAST
          Simon attribute name used to store last significant call tree.
private  LogTemplate<Split> callTreeLogTemplate
          Log template used for printing call tree.
private  Long logThreshold
          Duration threshold used to trigger logging and remembering.
private  ThreadLocal<CallTree> threadCallTree
          Call tree of current thread.
 
Constructor Summary
CallTreeCallback()
          Default constructor.
CallTreeCallback(LogTemplate<Split> callTreeLogTemplate)
          Constructor with log template.
CallTreeCallback(long threshold)
          Constructor with logging duration threshold.
 
Method Summary
private  CallTree getCallTree()
          Returns call tree for current thread.
static CallTree getLastCallTree(Stopwatch stopwatch)
          Returns last call tree stored in stopwatch attributes.
 Long getLogThreshold()
          Returns log threshold when callTreeLogTemplate is a SplitThresholdLogTemplate.
private  CallTree initCallTree()
          Initializes the call tree for current thread.
private  void initLogThreshold(Long threshold)
          Configures callTreeLogTemplate with a SplitThresholdLogTemplate.
 void onRootStopwatchStop(CallTree callTree, Split split)
          When stopwatch corresponding to root tree node is stopped, this method is called.
 void onStopwatchStart(Split split)
          Stopwatch start event.
 void onStopwatchStop(Split split, StopwatchSample sample)
          Stopwatch stop event.
private  void removeCallTree()
          Removes call tree for current thread.
 void setLogThreshold(Long logThreshold)
          Sets log threshold.
 
Methods inherited from class org.javasimon.callback.CallbackSkeleton
cleanup, initialize, onCounterDecrease, onCounterIncrease, onCounterSet, onManagerClear, onManagerMessage, onManagerWarning, onSimonCreated, onSimonDestroyed, onSimonReset, onStopwatchAdd, onStopwatchAdd
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadCallTree

private final ThreadLocal<CallTree> threadCallTree
Call tree of current thread.


callTreeLogTemplate

private LogTemplate<Split> callTreeLogTemplate
Log template used for printing call tree.


ATTR_NAME_LAST

public static final String ATTR_NAME_LAST
Simon attribute name used to store last significant call tree.

See Also:
Constant Field Values

logThreshold

private Long logThreshold
Duration threshold used to trigger logging and remembering.

Constructor Detail

CallTreeCallback

public CallTreeCallback()
Default constructor.


CallTreeCallback

public CallTreeCallback(long threshold)
Constructor with logging duration threshold.

Parameters:
threshold - Threshold

CallTreeCallback

public CallTreeCallback(LogTemplate<Split> callTreeLogTemplate)
Constructor with log template.

Parameters:
callTreeLogTemplate - Log template
Method Detail

initLogThreshold

private void initLogThreshold(Long threshold)
Configures callTreeLogTemplate with a SplitThresholdLogTemplate.


getLogThreshold

public Long getLogThreshold()
Returns log threshold when callTreeLogTemplate is a SplitThresholdLogTemplate.


setLogThreshold

public void setLogThreshold(Long logThreshold)
Sets log threshold. Configure callTreeLogTemplate with a SplitThresholdLogTemplate.


getCallTree

private CallTree getCallTree()
Returns call tree for current thread.

Returns:
Thread call tree

initCallTree

private CallTree initCallTree()
Initializes the call tree for current thread.

Returns:
Created call tree

removeCallTree

private void removeCallTree()
Removes call tree for current thread.


onStopwatchStart

public void onStopwatchStart(Split split)
Stopwatch start event. Duration of all callbacks is included into the split time! StopwatchSample valid for the moment after the start is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchStart in interface Callback
Overrides:
onStopwatchStart in class CallbackSkeleton
Parameters:
split - started Split

onStopwatchStop

public void onStopwatchStop(Split split,
                            StopwatchSample sample)
Stopwatch stop event. This action is executed after the split time is calculated and does not affect the measuring. StopwatchSample valid for the moment after the stop is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchStop in interface Callback
Overrides:
onStopwatchStop in class CallbackSkeleton
Parameters:
split - stopped Split
sample - stopwatch sampled after the stop

onRootStopwatchStop

public void onRootStopwatchStop(CallTree callTree,
                                Split split)
When stopwatch corresponding to root tree node is stopped, this method is called. Logs call tree when split is longer than threshold.

Parameters:
callTree - call tree to log
split - stopped split

getLastCallTree

public static CallTree getLastCallTree(Stopwatch stopwatch)
Returns last call tree stored in stopwatch attributes.

Parameters:
stopwatch - Stopwatch
Returns:
Last call tree or null if any


Copyright © 2013. All Rights Reserved.