From owner-freebsd-current Fri Mar 10 01:11:56 1995 Return-Path: current-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id BAA10675 for current-outgoing; Fri, 10 Mar 1995 01:11:56 -0800 Received: from ref.tfs.com (ref.tfs.com [140.145.254.251]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id BAA10667; Fri, 10 Mar 1995 01:11:52 -0800 Received: (from phk@localhost) by ref.tfs.com (8.6.8/8.6.6) id BAA03127; Fri, 10 Mar 1995 01:11:47 -0800 From: Poul-Henning Kamp Message-Id: <199503100911.BAA03127@ref.tfs.com> Subject: Basic Block Profiling in the kernel To: current@FreeBSD.org Date: Fri, 10 Mar 1995 01:11:46 -0800 (PST) Cc: faq@FreeBSD.org Content-Type: text Content-Length: 2012 Sender: current-owner@FreeBSD.org Precedence: bulk To use basic-block profiling on the kernel follow these steps: 0. Recompile & install src/gnu/usr.bin/cc src/usr.sbin/kernbb 1. Compile your kernel. The source files you want to profile must be compiled with "-g -a" in CFLAGS. 3. "strip -x kernel", install and reboot 4. Run the machine through its paces, and torture it as you want to excercise the code. 5. Run the "kernbb" program: kernbb > /some/where the output can be up to a couple of megabytes on the format: ../../ddb/db_aout.c 108 X_db_sym_init 4027583916 3108 The fields are: source file (relative to /sys/compile/ line number function address in decimal number of times executed. 6. You can use this tcl program to merge the counts into the source: sort /some/where | tcl merge.tcl > /some/place/else you can grep on funtions and filenames to limit the output: grep comwakeup /some/where | sort | tcl merge.tcl > /some/place/else Here is the code I use: merge.tcl #!/usr/local/bin/tcl # change to your kernel compile directory set dir "/sys/compile/FLAGMOSE" set line "----------------------------------------------" set m 0 set f "" while 1 { set i "" set j [gets stdin b] if {[lindex $b 0] != $f} { if {$f != ""} { set p [open $dir/$f] set k 0 puts "" puts [string range $line 1 [string length $f]] puts $f puts stderr "doing $f" puts [string range $line 1 [string length $f]] for {set i 1} {$i <= $m || $k >= 0} {incr i} { set x "" catch {set x $lno($i)} set lno($i) "" set k [gets $p l] puts [format "%5u|%-20s|%s" $i $x $l] } close $p } set m 0 set f [lindex $b 0] } else { set l [lindex $b 1] append lno($l) "[lindex $b 4] " if {$l > $m} {set m $l} } if {$j < 0} break } -- Poul-Henning Kamp -- TRW Financial Systems, Inc. 'All relevant people are pertinent' && 'All rude people are impertinent' => 'no rude people are relevant'