Profiling
When gawk is built and
installed, a separate program named pgawk (profilinggawk) is built and
installed with it. The two programs behave identically; however,
pgawk runs more slowly since it
keeps execution counts for each statement as it runs. When it is
done, it automatically places an execution profile of your program
in a file named awkprof.out.
(You can change the filename with the --profile
option.)
The execution profile is a “prettyprinted” version of your program with execution counts listed in the left margin. For example, after running this program:
$pgawk '/bash$/ { nusers++ }>END { print nusers, "users use Bash." }' /etc/passwd16 users use Bash.
The execution profile looks like this:
# gawk profile, created Mon Nov 1 14:34:38 2004
# Rule(s)
35 /bash$/ { # 16
16 nusers++
}
# END block(s)
END {
1 print nusers, "users use Bash."
}If sent SIGUSR1, pgawk prints the profile and an awk function call stack trace, and then
keeps going. Multiple SIGUSR1
signals may be sent; the profile and trace will be printed each
time. This facility is useful if your awk program appears to be looping, and you
want to see if something unexpected is being executed.
If sent SIGHUP, pgawk prints the profile and stack trace,
and then exits.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access