The --profile option (profiling)
This option enables the profiling of AWK programs, that is, it generates a pretty-printed version of the program in a file. By default, the profile is created in a file named awkprof.out. The optional file argument allows you to specify a different filename for the profile file. No space is allowed between -p and the filename, if a filename is supplied:
-p[file]
--profile[=file]
The profile file created contains execution counts for each statement in the program in the left margin, and function call counts for each function. In the next example, we will create a file with a name sample and redirect the output of the AWK command to /dev/null:
$ awk --profile=sample \
'BEGIN { print "**header**" }
{ print }
END{ print "**footer**" }' cars.dat > /dev/null
This same action can also be performed as follows:
$ awk -psample \
'BEGIN { print "**header**" }
{ print }
END{ print "**footer**" }' cars.dat > /dev/null
To view the content of profile, we execute the cat command, as follows:
$ cat sample
# gawk profile, created Thu Sep 14 17:20:27 2017
# BEGIN rule(s)
BEGIN {
1 print "**header**"
}
# Rule(s)
12 {
12 print $0
}
# END rule(s)
END {
1 print "**footer**"
}
The –pretty-print option: It is the same profiling option discussed in the preceding section:
-o[file]
--pretty-print[=file]