Tool Where to
Find It
What It Does
truss /usr/bin The SVr4 version of trace. This tool prints out the system calls that an
executable makes. Use it to see what a binary is doing, and why it's stuck
or failing. This is a great help!
ps /usr/bin Displays process characteristics.
ctrace Comes with
compiler
Modifies your source to print lines as they are executed. A great tool for
small programs!
debugger Comes with
compiler
Interactive debugger.
file /usr/bin Tells you what a file contains (e.g., executable, data, ASCII, shell script,
archive, etc.).
Table 6-4. Tools to Help with Performance Tuning
Tool Where to Find
It
What It Does
collector Comes with
debugger
(SunOS only) Collects runtime performance data under the control
of the debugger.
analyzer Comes with
debugger
(SunOS only) Analyzes collected performance data.
gprof /usr/ccs/bin Displays the call-graph profile data (identifies the compute-
intensive functions).
prof /usr/ccs/bin Displays the percentage of time spent in each routi ne.
tcov Comes with
compiler
Displays a count of how often each statement is executed (identifies
the compute-intensive loops within a function).
time /usr/bin/time Displays the total real and CPU time used by a program.
If you're working on the OS kernel, most of the runtime tools are not available to you, because the
kernel does not run as a user process. The compiletime tools, like lint, work, but otherwise we have to
use the stone knives and flint axes: putting nonrandom patterns in memory to see when they are
overwritten (two favorites are the hex constants dead-beef and abadcafe), using printf 's or
their equivalent, and logging trace information.
Software Dogma
Debugging the Ker nel with grep
A kernel "panics", or comes to an abrupt halt, when it detects a situation that "cannot" arise.
For example, it finds a null pointer when looking for some essential data. Since there is no
way it can recover from this, the safest course is to halt the processor before more data
disappears. To solve a panic, you must first consider what happened that could possibly