Section D.1. A Simple Kstat Walker


D.1. A Simple Kstat Walker

#!/usr/bin/perl -w # # kgrep - walk the Kstat tree, grepping names. # # This is a simple demo of walking the Kstat tree in Perl. The output # is similar to a "kstat -p", however an argument can be provided to # grep the full statistic name (joined by ":"). # # USAGE:    kgrep [pattern] #    eg,    kgrep hme0 use strict; use Sun::Solaris::Kstat; my $Kstat = Sun::Solaris::Kstat->new(); my $pattern = defined $ARGV[0] ? $ARGV[0] : "."; die "USAGE: kgrep [pattern]\n" if $pattern eq "-h"; # loop over all kstats foreach my $module (keys(%$Kstat)) {     my $Modules = $Kstat->{$module};     foreach my $instance (keys(%$Modules)) {         my $Instances = $Modules->{$instance};         foreach my $name (keys(%$Instances)) {             my $Names = $Instances->{$name};             foreach my $stat (keys(%$Names)) {                 my $value = $$Names{$stat};                 # print kstat name and value                 printf "%-50s %s\n", "$module:$instance:$name:$stat", $value                     if "$module:$instance:$name:$stat" =~ /$pattern/;             }         }     } } 





Solaris Performance and Tools(c) Dtrace and Mdb Techniques for Solaris 10 and Opensolaris
Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris
ISBN: 0131568191
EAN: 2147483647
Year: 2007
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net