|
Built-in Code Profiler |
Every switch below is a statement, so it can go in a program, and a console
command, typed at the >>> prompt. debug on
is the one the others depend on: it turns on the debugging mode that tracing,
statistics and breakpoints need, and it synchronizes terminal output so that
what you see is current when the program stops. A program runs slower in that
mode, which is why it is a switch and not the default.
run 'myprogram' loads the program and starts it clean
— debugging, tracing and statistics all off — so a switch typed before
it is forgotten. The console switches are for a program that is already there:
break), type
debug on or debug off — or any switch below
— and then go. The program continues from where it stopped,
in the new mode.run (no name): it runs the same
program again and keeps the mode.| Command | What it does |
|---|---|
debug on |
Turn on the debugging mode. Required by everything below. |
debug off |
Turn it off. This also turns tracing and statistics off. |
_debug |
Not a command: a system variable a program can test. It is 1 (true) while the debugging mode is on and 0 (false) when it is off. |
trace on |
Open the Program Trace window and log every statement as it runs:
the time, its MAIN.line label, and the source text. |
trace routine: on |
Log only the routines entered, one line each, indented two
spaces per level of call — an outline of the program's higher-level
logic. trace on switches back to every statement. |
trace off / trace routine: off |
Stop tracing and close the window. Closing the window does the same. |
stats on / stats off |
Start and stop the profiler's routine timers, described above. |
list stats |
Write the profile to myprogram_stats.txt. |
break |
A breakpoint in the source: under debug on the program
stops there and drops into the console. In a normal run it does nothing
(and the compiler warns, since it is not a loop exit). |
step / step 5 |
At a halt: run the next statement, or the next five, and stop again.
Esc is a one-tap step; F1
steps over a routine call, F3 steps out of the routine. |
go |
Resume the program from where it stopped. |
| alt/b | The key, not a command: halt the running program and drop into the
console at that statement. go continues. |
show all |
Dump every variable, array, table and cluster, the open files and the
call stack to myprogram_debug_time.txt. |
debug all / debug all "file.txt" |
The same dump from inside a program, to the default file or the one named. |
debug show x, y$ |
Dump just the variables listed. |
stop |
End the program. |
The two habits that pay off: put debug on and stats on
at the top of a program you are studying and list stats before it
ends, and for an unfamiliar application, once it is loaded, type
trace routine: on at the console and then a bare run
— the trace window then reads as an outline of what the application does.
_debug system variable
A program can ask whether the debugging mode is on: _debug is
1 (true) after debug on and 0 (false) after debug off,
and a program started with run 'myprogram' begins with it 0. It is
a true-or-false value, so it goes straight into an if:
Output:
Use it to keep diagnostic work out of a normal run without editing the program:
extra print lines, a debug show of the variables you
are watching, or a slower consistency check can sit behind
if _debug then and cost nothing until debug on is
given. At the console, print _debug answers the same question
— and after a halt, debug off then go lets the
program run on with _debug reading 0.
Profiling is a powerful built-in feature of Sheerpower that helps developers optimize performance by identifying routines that consume the most time and resources. By targeting bottlenecks, the profiler allows developers to concentrate their efforts where they will have the greatest impact, significantly improving overall efficiency.
By providing detailed insights into execution times and routine call frequencies, the profiler enables data-driven optimization, simplifies debugging, and minimizes trial-and-error in development. This results in faster, more cost-effective, and high-performing applications tailored to business needs. Profiling turns the often complex process of optimization into a precise and measurable task.
|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |