Profiler Class
The Profiler is used to analyze your application in order to determine where you could use the most optimization. The profiler class is where all interaction with the Profiler takes place. You use it to create step nodes and render the output.
Constructor
Profiler
-
[parser=null]
Parameters:
-
[parser=null]
Parser optionalOptional to pass in existing Parser
Item Index
Methods
Methods
addDuration
-
time
Add node duration to the {@link Profiler::$childDurations} variable
Parameters:
-
time
Numberduration of the child node in microseconds
addQueryDuration
-
time
Increment the total query time
This method is used by the {@link ProfilerGhostNode} to increment the total query time for the page execution. This method should never be called in userland. There is zero need to.
Parameters:
-
time
Numberamount of time the query took to execute in microseconds.
Returns:
Current amount of time (in microseconds) used to execute sql queries.
calculateThreshold
()
protected
Calculate the time cut-off for a trivial step. Utilizes the {@link Profiler::$trivialThreshold} value to determine how fast a step must be to be regarded "trivial"
disable
()
Disable the profiler
enable
()
Enable the profiler
end
-
nodeName
-
nuke
End a step by name, or end all steps in the current tree.
Parameters:
-
nodeName
Stringends the first-found step with this name. (Note: a warning is generated if it's not the current step, because this is probably unintentional!)
-
nuke
Booleandenotes whether you are intentionally attempting to terminate the entire step-stack. If true, the warning mentioned is not generated.
Returns:
|ProfilerNode|ProfilerGhostNode returns null if you ended the top-level step node, or the parent to the ended node, or a ghost node if the profiler is disabled.
getGlobalDuration
()
Number
Get the global script duration
Returns:
Duration of the script (in milliseconds, 1 significant digit)
getGlobalStart
()
Number
Get the global start time
Returns:
Start time of the script from unix epoch (milliseconds, 1 significant digit)
getMemUsage
-
[unit='']
Get the global memory usage in KB
Parameters:
-
[unit='']
String optionala metric prefix to force the unit of bytes used (B, K, M, G)
getTotalQueryTime
()
Number
Get the total amount of query time
Returns:
Total time used to execute sql queries (milliseconds, 1 significant digit)
isEnabled
()
Boolean
Check to see if the profiler is enabled
Returns:
True if profiler is enabled, false if disabled
isTrivial
-
node
Determines if a node is trivial
Parameters:
-
node
ProfilerNodeThe node to investigate
Returns:
True if a node is trivial, false if not
render
-
[showDepth=-1]
Render the profiler output
Parameters:
-
[showDepth=-1]
Int optionalthe depth of the step tree to traverse when rendering the profiler output. -1 to render the entire tree
Returns:
The render of the profiler to include on your page
setTrivialThreshold
-
threshold
Set the Percentile Boundary Threshold. This is used to set the percentile boundary for when a node is considered trivial or not. By default, .75 is used. This translates to the fastest 25% of nodes being regarded "trivial". This is a sliding scale, so you will always see some output, regardless of how fast your application runs.
Parameters:
-
threshold
Numberthe threshold to use as the percentile boundary
sqlEnd
()
Stop profiling the current SQL call
sqlStart
-
query
Start a new sql query
This method is used to tell the profiler to track an sql query. These are treated differently than step nodes
Parameters:
-
query
Stringthe query that you are running (used in the output of the profiler so you can view the query run)
Returns:
returns an instance of the {@link ProfilerGhostNode} if profiler is enabled, or {@link ProfilerGhostNode} if disabled
start
-
nodeName
Start a new step. This is the most-called method of the profiler.
It initializes and returns a new step node.
Parameters:
-
nodeName
Sstringname/identifier for your step. is used later in the output to identify this step
Returns:
returns an instance of a {@link ProfilerNode} if the profiler is enabled, or a {@link ProfilerGhostNode} if it's disabled
Properties
childDurations
Array
protected
Global tracker for step times. Keeps track of how long each node took to execute. This is used to determine what is a "trivial" node, and what is not.
depthCount
Int
protected
Tracks the current tree depth
enabled
Boolean
protected
Used to identify when the profiler has been enabled. If false no profiling data is stored, in order to reduce the overhead of running the profiler
ghostNode
ProfilerGhostNode
protected
A lightweight shell node used to return when the profiler is disabled.
globalEnd
Number
protected
Time the profiler 'ends'. This is populated just before rendering output (see {@link Profiler::render()})
globalStart
Number
protected
Time the profiler was included. This is used to calculate time-from-start values for all methods as well as total running time.
parser
Parser
The parser instance
profilerKey
String
protected
Used to identify when some methods are accessed internally versus when they're used externally (as an api or so)