Matty
2005-Dec-11 00:46 UTC
[dtrace-discuss] Measuring Apache module function processing time
Howdy,
I wrote the following [1][2] DTrace script to measure Apache module
processing time, and was curious if there are better ways to go about
implementing this? I assume there are, and would love to get feedback.
Thanks for any insight,
- Ryan
--
UNIX Administrator
http://daemons.net/~matty
[1] Execution
$ moduletrace `pgrep httpd | head -1` mod_alias.so
Tracing Apache Module mod_alias.so (Control-C to stop)
^C
Module Function Time
mod_alias.so alias_matches 582737
mod_alias.so fixup_redir 602225
mod_alias.so translate_alias_redir 859978
mod_alias.so try_alias_list 1124218
Total Time: 3169158
[2] Script
$ cat moduletrace
#!/usr/bin/ksh
if [ $# -ne 2 ]
then
echo "Usage: $0 HTTPD_PID MODULE_NAME"
echo " (e.g., $0 \`pgrep httpd\` mod_ssl.so)"
exit 1
fi
apache_module=$2
/usr/sbin/dtrace -q -p $1 -n''
inline string APACHE_MODULE_NAME =
"''$apache_module''";
dtrace:::BEGIN
{
printf("Tracing Apache Module %s (Control-C to
stop)\n",APACHE_MODULE_NAME);
}
pid$target:::entry
/ probemod == APACHE_MODULE_NAME /
{
functions[probefunc] = 1;
self->ts = timestamp;
}
pid$target:::return
/ functions[probefunc] /
{
self->current_time = timestamp - self->ts;
@time[probemod, probefunc] = sum(self->current_time);
@total_time["Total Time:"] = sum(self->current_time);
}
dtrace:::END
{
printf("%-20s %-30s %-10s\n","Module",
"Function", "Time");
printa("%-20s %-30s %- at d\n", @time);
printa("\n%-20s %- at d\n", @total_time);
}''