SLAX Debugger, Profiler, and callflow
The libslax distribution includes the SLAX debugger and profiler. These tools enable you to trace the execution and analyze the performance of SLAX scripts.
SLAX Debugger, Profiler, and callflow Overview
The Junos OS CLI and the libslax distribution include the SLAX debugger (sdb), which you can use to trace the execution of SLAX scripts. The SLAX debugger enables you to step through script execution, pause script execution at defined breakpoints, and review the value of script variables at any point.
The SLAX debugger operation and command syntax resemble that of the GNU Project Debugger (GDB). Many of the sdb commands follow their GDB counterparts, to the extent possible. Table 1 lists the SLAX debugger commands and a brief description of each command.
The SLAX debugger includes a profiler that can report information about the activity and
performance of a script. The profiler is automatically enabled when you start the
debugger. The profiler tracks script execution until the script terminates. At any
point, you can display or clear profiling information, and you can temporarily enable or
disable the profiler. The SLAX debugger callflow command enables
printing of informational data when you enter or exit levels of the script.
Command |
Description |
|---|---|
|
|
Add a breakpoint to the script at the current line of execution. Optionally specify [file:]line or a template name to create a breakpoint at that position. |
|
|
Enable or disable callflow tracing. You can explicitly specify the
|
|
|
Continue running the script until it reaches the next breakpoint. If the script has no defined breakpoints, the script runs in its entirety. Optionally, specify [file:]line or a template name. When you include the optional argument, script execution continues until it reaches a breakpoint or the specified line number or template name, whichever comes first. |
|
|
Delete one or all breakpoints. Breakpoints are numbered sequentially
as they are created. Omit the optional argument to delete all
breakpoints. Include the breakpoint number as an argument to delete
only the specified breakpoint. View currently active breakpoints
with the |
|
|
Finish executing the current template. |
|
|
Display the help message. |
|
|
Display information about the current script. The default command
lists all breakpoints in the script. Optionally specify the
|
|
|
List the contents of the current script. Optionally specify [file:]line or a template name from which point the debugger lists partial script contents. The output includes the filename, line number, and code. |
|
|
Execute the next instruction, stepping over any function or template calls. |
|
|
Execute the next instruction, stepping over any function or template calls or instruction hierarchies. |
|
|
Print the value of the XPath expression. |
|
|
Enable or disable the profiler. The profiler is enabled by default. Optional values:
|
|
|
Exit debugging mode. |
|
|
Reload the script. |
|
|
Restart script execution from the beginning of the script. |
|
|
Execute the next instruction, stepping into any function or template calls or instruction hierarchies. |
|
|
Show the backtrace of template calls. |
How to Use the SLAX Debugger, Profiler, and callflow
Invoke the SLAX Debugger
Both the Junos OS CLI and the SLAX processor include the SLAX debugger (sdb). You can use the SLAX debugger to trace the execution of SLAX scripts.
When you invoke the SLAX debugger, the command-line prompt changes to (sdb) to indicate that you are in debugging mode. For example:
sdb: The SLAX Debugger (version ) Type 'help' for help (sdb)
In the Junos OS CLI, you can only use the debugger with op scripts that you enable in the
configuration. To invoke the SLAX debugger in the CLI, issue the op
invoke-debugger cli operational mode command. Include the op script name and
any necessary script arguments.
user@host> op invoke-debugger cli script <argument-name argument-value>
The following example invokes the SLAX debugger for the op script
ge-interfaces.slax. The script has two parameters,
interface and protocol. The command supplies values
for both arguments.
user@host> op invoke-debugger cli ge-interfaces interface ge-0/2/0.0 protocol inet sdb: The SLAX Debugger (version ) Type 'help' for help (sdb)
To invoke the SLAX debugger when using the SLAX processor, issue the slaxproc
command with the --debug or -d option. Specify the
script file and any input or output files. If the script does not require an input file,
use the -E option to indicate an empty input document. If the
-i or --input argument has the value "‑", or if you do
not include the input option or an input file, standard input (stdin) is used. When using
stdin, press Ctrl+d to signal the end-of-file. The general syntax is:
$ slaxproc --debug [options] [script] [files]
The following example invokes the SLAX debugger for the script script1.slax. The input document is empty, and the output file is script1-output.xml.
$ slaxproc --debug -n script1.slax -o script1-output.xml -E sdb: The SLAX Debugger (version ) Type 'help' for help (sdb)
Use the SLAX Debugger (sdb)
To view the SLAX debugger help message, issue the help command at the (sdb) prompt. To display the help message for a single
command, issue help command, where command is the sdb command for which you want more information.
For example:
(sdb) help break break [loc] Add a breakpoint at [file:]line or template
The process for debugging a script varies depending on the script. A generic outline is presented here:
Use the SLAX Profiler
The SLAX debugger includes a profiler that can report information about the activity and
performance of a script. When you invoke the SLAX debugger, it automatically enables the
profiler. You can also disable or enable the profiler as needed. The profiler tracks
script execution until the script terminates. At any point, you can display or clear
profiling information. Additionally, starting in SLAX version 1.3, you can use the
slaxproc command with the profile and
profile-mode options to run the profiler directly on a script, without
invoking the debugger. For additional information, see Run the Profiler on a Script.
To access the profiler within the SLAX debugger, issue the profile command at
the SLAX debugger prompt, (sdb), and include any options. The profile command syntax
is:
(sdb) profile [options]
Table 2 lists
the profile command options. Issuing the profile command
with no additional options toggles the profiler on and off.
(sdb) profile Disabling profiler (sdb)
You can access the profiler help by issuing the help profile command at the (sdb) prompt.
Option |
Description |
|---|---|
clear |
Clear profiling information |
off |
Disable profiling |
on |
Enable profiling |
report [brief] |
Report profiling information |
To enable the profiler and print a report:
The profile report includes the following information:
Line—Source code line number.Hits—Number of times the line was executed.User—Number of microseconds of "user" time spent processing this line.U/Hit—Average number of microseconds of "user" time per hit.System—Number of microseconds of "system" time spent processing this line.S/Hit—Average number of microseconds of "system" time per hit.Source—Source code line.
This information not only shows how much time is spent during code execution, but it can also show which lines that the script executes. This information can help debug scripts where the execution does not match expectations.
Use the callflow Command
The SLAX debugger callflow command enables you to print informational data when
you enter or exit levels of the script.
To enable callflow and view callflow data for a script: