From owner-freebsd-current Sat May 25 17:12:29 2002 Delivered-To: freebsd-current@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id 135C837B401 for ; Sat, 25 May 2002 17:12:16 -0700 (PDT) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 60AB05307; Sun, 26 May 2002 02:12:12 +0200 (CEST) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: current@freebsd.org Subject: Mutex statistics script From: Dag-Erling Smorgrav Date: 26 May 2002 02:12:11 +0200 Message-ID: Lines: 49 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --=-=-= The attached script sorts the data from the debug.mutex.prof.stats sysctl variable according to the selected key (the default being the mutex name) The -g option causes the script to strip off the source file and line and accumulate totals for each mutex. The -r option reverses the sorting order. The (mutually exclusive) -a, -c, -m and -t options sort the results by the max, total, count or average column. Here's a list of the ten most frequently acquired mutices (over a period of 11 days), grouped by mutex name: des@des ~% mtxstat -gcr -l 10 max total count average name 1077094 3634841194 3021298899 1 process lock 200760 4475449899 2339885146 2 pool mutex 11075293 54743743699 2127442731 26 Giant 252 2151217659 1587924805 1 sellck 24594 1913632993 813816142 2 vnode interlock 442810 12872182712 716587273 18 filedesc structure 520 2038681691 480818216 4 PCPU 16 36114 156710765 187686674 0 bio queue 114 270322499 185453842 1 malloc 87 165913390 182277045 1 temp Sorted by total time held, a few minutes later: des@des ~% mtxstat -gtr -l 10 max total count average name 11075293 54762076072 2128355890 26 Giant 442810 12881479450 716922166 18 filedesc structure 200760 4475944044 2340324507 2 pool mutex 97625 4303676900 51655812 83 mntvnode 1077094 3636650031 3022817522 1 process lock 252 2152670298 1589143889 1 sellck 520 2038861358 480872541 4 PCPU 16 24594 1913699459 813846649 2 vnode interlock 8418 383692889 9040940 42 xl0 87 348538260 74251990 5 vnode_free_list IWBNI there was a way to record how many times each mutex was contested... DES -- Dag-Erling Smorgrav - des@ofug.org --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename=mtxstat Content-Transfer-Encoding: quoted-printable #!/usr/bin/perl -Tw #- # Copyright (c) 2002 Dag-Erling Co=EFdan Sm=F8rgrav # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer # in this position and unchanged. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # $Id$ # use strict; use Getopt::Std; sub usage() { print(STDERR "usage: mtxstat [-gr] [-a|c|m|t] [-l limit]\n"); exit(1); } MAIN:{ my %opts; # Command-line options my $key; # Sort key my $limit; # Output limit local *PIPE; # Pipe my $header; # Header line my @names; # Field names my %data; # Mutex data my @list; # List of entries getopts("acgl:mrt", \%opts) or usage(); if ($opts{'a'}) { usage() if ($opts{'c'} || $opts{'m'} || $opts{'t'}); $key =3D 'average'; } elsif ($opts{'c'}) { usage() if ($opts{'m'} || $opts{'t'}); $key =3D 'count'; } elsif ($opts{'m'}) { usage() if ($opts{'t'}); $key =3D 'max'; } elsif ($opts{'t'}) { $key =3D 'total'; } if ($opts{'l'}) { if ($opts{'l'} !~ m/^\d+$/) { usage(); } $limit =3D $opts{'l'}; } $ENV{'PATH'} =3D '/bin:/sbin:/usr/bin:/usr/sbin'; open(PIPE, "sysctl -n debug.mutex.prof.stats|") or die("open(): $!\n"); $header =3D ; chomp($header); @names =3D split(' ', $header); if (defined($key) && !grep(/^$key$/, @names)) { die("can't find sort key '$key' in header\n"); } while () { chomp(); my @fields =3D split(' ', $_, @names); next unless @fields; my %entry; foreach (@names) { $entry{$_} =3D ($_ eq 'name') ? shift(@fields) : 0.0 + shift(@fields); } if ($opts{'g'}) { $entry{'name'} =3D~ s/^(\S+)\s+\((.*)\)$/$2/; } my $name =3D $entry{'name'}; if ($data{$name}) { if ($entry{'max'} > $data{$name}->{'max'}) { $data{$name}->{'max'} =3D $entry{'max'}; } $data{$name}->{'total'} +=3D $entry{'total'}; $data{$name}->{'count'} +=3D $entry{'count'}; $data{$name}->{'average'} =3D $data{$name}->{'total'} / $data{$name}->{'count'}; } else { $data{$name} =3D \%entry; } } if (defined($key)) { @list =3D sort({ $data{$a}->{$key} <=3D> $data{$b}->{$key} } sort(keys(%data))); } else { @list =3D sort(keys(%data)); } if ($opts{'r'}) { @list =3D reverse(@list); } print("$header\n"); if ($limit) { while (@list > $limit) { pop(@list); } } foreach (@list) { printf("%12.0f %12.0f %12.0f %12.0f %s\n", $data{$_}->{'max'}, $data{$_}->{'total'}, $data{$_}->{'count'}, $data{$_}->{'average'}, $data{$_}->{'name'}); } } --=-=-=-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message