Profiling
When gawk is built and installed, a separate program named pgawk (profiling gawk) is built and installed with it. The two programs behave identically; however, pgawk runs more slowly because 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/passwd
16 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.
Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.