Package com.singularsys.jep.misc
Class MonitoringEvaluator
java.lang.Object
com.singularsys.jep.standard.FastEvaluator
com.singularsys.jep.misc.MonitoringEvaluator
- All Implemented Interfaces:
Evaluator,GenericVisitor<Object,,Void, EvaluationException> JepComponent,Serializable
- Direct Known Subclasses:
XMonitoringEvaluator
A subclass of FastEvaluator that monitors the number of times
each function, operator, variable, and constant is called during evaluation.
It can be configured to record the time spent in each call.
The time for each function is measured from the
the time the
visitFun(Node) method is called to the time it returns.
The instance time is the time spent minus the times for each child.- Since:
- Jep 4.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA class to hold the count and times of function/operator/variable/constant calls.static interfaceFunctional interface for functions to be measured.static enumThe type of monitoring to perform. -
Field Summary
Fields inherited from class com.singularsys.jep.standard.FastEvaluator
trapInfinity, trapNaN, trapNullValues, trapUnsetValues -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the call counts for functions, operators, variables, and constants.Main entry point, evaluates a node and returns and object with the value of the node.formatTabbedTable(String str) Returns a map of constant values to the number of times they were called during evaluation.Returns a map of function names to the number of times they were called during evaluation.Gets a light-weight instance suitable for using in multiple threads.intReturns the maximum depth of the evaluation tree during evaluation.Returns a map of nodes to the number of times they were called during evaluation.intReturns a map of operator names to the number of times they were called during evaluation.longReturns the total instance time spent in all function/operator/variable/constant calls during evaluation.Returns a map of variable names to the number of times they were called during evaluation.voidInitialize the component.Print the call table sizing columns to fitPrint the call tree sizing columns to fitmeasure(String name, Node node, MonitoringEvaluator.GetWithException<Object> sup) Measure the time spent executing the supplied function.visitConstant(Node node) protected ObjectVisits a function/operator node.Methods inherited from class com.singularsys.jep.standard.FastEvaluator
eval, isTrapInfinity, isTrapNaN, isTrapNullValues, isTrapUnsetValues, makeException, nodeAccept, setTrapInfinity, setTrapNaN, setTrapNullValues, setTrapUnsetValues, visit, visit, visit, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.jep.GenericVisitor
makeException, visit, visitChildren
-
Constructor Details
-
MonitoringEvaluator
Constructor. Measuring time can slow down the evaluation by half.- Parameters:
measureTime- one ofMonitoringEvaluator.Type.MEASURE_TIMEorMonitoringEvaluator.Type.DO_NOT_MEASURE_TIME
-
-
Method Details
-
formatTabbedTable
-
evaluate
Description copied from interface:EvaluatorMain entry point, evaluates a node and returns and object with the value of the node.- Specified by:
evaluatein interfaceEvaluator- Overrides:
evaluatein classFastEvaluator- Parameters:
node- node to evaluate- Returns:
- value after evaluation
- Throws:
EvaluationException- if errors occur during evaluation;
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Overrides:
initin classFastEvaluator- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Overrides:
getLightWeightInstancein classFastEvaluator- Returns:
- a new FastEvaluator
-
getFunctionCallCounts
Returns a map of function names to the number of times they were called during evaluation.- Returns:
- a map where keys are function names and values record counts and times.
-
getOperatorCallCounts
Returns a map of operator names to the number of times they were called during evaluation.- Returns:
- a map where keys are operator names and values record counts and times.
-
getVariableCallCounts
Returns a map of variable names to the number of times they were called during evaluation.- Returns:
- a map where keys are variable names and values record counts and times.
-
getConstantCallCounts
Returns a map of constant values to the number of times they were called during evaluation.- Returns:
- a map where keys are constant values and values record counts and times.
-
getNodeCallCounts
Returns a map of nodes to the number of times they were called during evaluation.- Returns:
- a map where keys are nodes and values record counts and times.
-
clear
public void clear()Clears the call counts for functions, operators, variables, and constants. -
getCallTable
-
justifiedCallTable
Print the call table sizing columns to fit- Returns:
-
justifiedCallTree
Print the call tree sizing columns to fit- Returns:
-
visitConstant
- Overrides:
visitConstantin classFastEvaluator- Throws:
EvaluationException
-
visitVar
- Overrides:
visitVarin classFastEvaluator- Throws:
EvaluationException
-
visitFun
Description copied from class:FastEvaluatorVisits a function/operator node. This is the most visited method for most expression evaluations. Keeping it fast is important.- Overrides:
visitFunin classFastEvaluator- Parameters:
node-- Throws:
EvaluationException
-
measure
public Object measure(String name, Node node, MonitoringEvaluator.GetWithException<Object> sup) throws EvaluationException Measure the time spent executing the supplied function. Useful when execution happens via a different path that might not otherwise be recorded.MonitoringEvaluator mev = new MonitoringEvaluator(); Object value = mev.measure("calcValue", ()-> calcValue()); // the function to be measured- Parameters:
name- the name of the function to record results undernode- the node to record results forsup- the function to execute, typically() -> calcValue()- Returns:
- the result of executing the supplied function
- Throws:
EvaluationException
-
getNumCalls
public int getNumCalls() -
getTotalInstanceTime
public long getTotalInstanceTime()Returns the total instance time spent in all function/operator/variable/constant calls during evaluation. This will be slightly less than the total time spent in evaluation.- Returns:
-
getMaxDepth
public int getMaxDepth()Returns the maximum depth of the evaluation tree during evaluation.- Returns:
- the maximum depth of the evaluation tree
-
getCallTree
-