#!/usr/bin/ksh # Program: Print Apache DTrace Module Function Time # # Author: Matty < matty91 at gmail dot com> # # Current Version: 0.1a # # Revision History: # Version 0.1a # # Last Updated: 12-09-2005 # # Purpose: Prints the execution time for each Apache module function. # # Installation: # Copy the shell script to a suitable location # # CDDL HEADER START # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at Docs/cddl1.txt # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # CDDL HEADER END # # Example: # $ moduletrace `pgrep httpd` mod_alias.so # Tracing Apache Module mod_alias.so (Control-C to stop) # Module Function Time # mod_alias.so alias_matches 432611 # mod_alias.so fixup_redir 551542 # mod_alias.so translate_alias_redir 763588 # mod_alias.so try_alias_list 964675 # # Total Time: 2712416 if [ $# -ne 2 ] then echo "Usage: $0 HTTPD_PID MODULE_NAME" echo " (e.g., $0 \`pgrep httpd\` mod_ssl)" 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 %-@d\n", @time); printa("\n%-20s %-@d\n", @total_time); }'