Appendix D. Sample Perl Kstat Utilities
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 ...
Get Solaris™ Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.