/usr/share/cricket/util/perfInfo.pl is in cricket 1.0.5-20.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | #!/usr/bin/perl -w
# -*- perl -*-
# Cricket: a configuration, polling and data display wrapper for RRD files
#
# Copyright (C) 1998 Jeff R. Allen and WebTV Networks, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
BEGIN {
my $programdir = (($0 =~ m:^(.*/):)[0] || "./") . "..";
eval "require '$programdir/cricket-conf.pl'";
eval "require '/usr/local/etc/cricket-conf.pl'"
unless $Common::global::gInstallRoot;
$Common::global::gInstallRoot ||= $programdir;
}
use lib "$Common::global::gInstallRoot/lib";
use strict;
use Win32::PerfLib;
use Getopt::Long;
my ($counter,$pr) = ({},{});
my $server;
my ($object,$cname,$ctype,$instance,$debug) = 0;
my %rcounter;
&GetOptions(
"s|server=s" => \$server,
"o|object=s" => \$object,
"c|counter=s" => \$cname,
"i|instance=s" => \$instance,
"d|debug=i" => \$debug,
"h|help" => \&Help,
);
Win32::PerfLib::GetCounterNames($server, $counter);
if(!defined($server)) {
$server = ".";
}
if(! $object || ! $counter) {
warn "Error: -o|-c must be defined!\n";
&Help;
}
print "* Setting server to $server\n";
foreach my $k (keys %{$counter}) {
$rcounter{lc($counter->{$k})} = $k;
}
my $pl = new Win32::PerfLib($server);
$pl->GetObjectList($rcounter{$object}, $pr) || die "Can't get counters from $server because of: $!\n";
$pl->Close();
print "* Getting counter type(s) for $cname\n";
foreach my $level2 (keys %{$pr->{'Objects'}}) {
if($pr->{'Objects'}->{$level2}->{'NumInstances'} > 0) {
if(defined($instance)) {
print "\t* Traversing multiple counters for $cname\n";
foreach my $level4 (keys %{$pr->{'Objects'}->{$level2}->{'Instances'}}) {
my $ir = $pr->{'Objects'}->{$level2}->{'Instances'}->{$level4};
foreach my $level5 (keys %{$ir->{'Counters'}}) {
my $cr = $ir->{'Counters'}->{$level5};
my $saneCounter = $counter->{$cr->{'CounterNameTitleIndex'}};
my $saneInstance = $ir->{'Name'};
print "\t\t\t* Debug: $saneCounter->$saneInstance\n" if($debug == 1);
if(lc($saneCounter) eq lc($cname)) {
if(lc($saneInstance) eq lc($instance)) {
$ctype = Win32::PerfLib::GetCounterType($cr->{'CounterType'});
print "\t\t* Found!\n";
print "\t\t* $cname->$instance is counter: $ctype\n";
}
}
}
}
} else {
print "\t* Counter has multiple instances, ignoring because --instances not set\n";
}
}
foreach my $level4 (keys %{$pr->{'Objects'}->{$level2}->{'Counters'}}) {
my $cr = $pr->{'Objects'}->{$level2}->{'Counters'}->{$level4};
my $saneCounter = $counter->{$cr->{'CounterNameTitleIndex'}};
print "\t\t\t* Debug: $saneCounter\n" if ($debug == 1);
if(lc($saneCounter) eq lc($cname)) {
$ctype = Win32::PerfLib::GetCounterType($cr->{'CounterType'});
print "\t\t* Found!\n";
print "\t\t* $cname is counter type: $ctype\n";
getFormula($ctype);
}
}
}
sub getFormula {
my ($cdef) = @_;
print <<EOF;
Formulas are from MSDN - subject to change. Author of this program takes no
responsibilities for inaccurate information!
Symbols:
TB Time base. If TB is not used in the calculation, then it indicates the
units of the raw data.
B The base value used for calculating performance data types that require
base.
EOF
if($cdef eq "PERF_100NSEC_MULTI_TIMER") {
extractFormula($cdef, "Timer sampling of multiple but similar items. Result is an average sampling among the items. The number of items it the base data.", "CounterData", "100NsTime", "100Ns", "8", "%", "100*((X1-X0)/(Y1-Y0))/B1");
} elsif ($cdef eq "PERF_100NSEC_MULTI_TIMER_INV") {
extractFormula($cdef, "The inverse of the timer for multiple but similar items. Used when the objects are not in use.", "CounterData", "100NsTime", "100Ns", "8", "%", "100*(B1-((X1-X0)/(Y1-Y0)))/B1");
} elsif ($cdef eq "PERF_100NSEC_TIMER") {
extractFormula($cdef, "Timer for when the object is in use.", "CounterData", "100NsTime", "100Ns", "8", "%", "100*(X1-X0)/(Y1-Y0)");
} elsif ($cdef eq "PERF_100NSEC_TIMER_INV") {
extractFormula($cdef, "Timer for when the object is not in use.", "CounterData", "100NsTime", "100Ns", "8", "%", "100*(1-(X1-X0)/(Y1-Y0))");
} elsif ($cdef eq "PERF_AVERAGE_BASE") {
extractFormula($cdef, "Use of the base data in the computation of time or count averages. See PERF_AVERAGE_TIMER and PERF_AVERAGE_BULK", "N/A", "N/A", "N/A", "4", "N/A", "N/A");
} elsif ($cdef eq "PERF_AVERAGE_BULK") {
extractFormula($cdef, "A count that usually gives the bytes per operation when divided by the number of operations.", "CounterData", "N/A", "N/A", "8", "No suffix", "(X1-X0)/(B1-B0)");
} elsif ($cdef eq "PERF_AVERAGE_TIMER") {
extractFormula($cdef, "A timer that usually gives the time per operation when divided by the number of operations.", "CounterData", "N/A", "PerfFreq", "4", "Sec", "((X1-X0)/TB)/(B1-B0)");
} elsif ($cdef eq "PERF_COUNTER_100NS_QUEUELEN_TYPE") {
extractFormula($cdef, "Queue-length space-time product using a 100-nanosecond time base.", "CounterData", "PerfTime", "PerfFreq", "8", "No suffix", "(TB(X1-X0))/(Y1-Y0)");
} elsif ($cdef eq "PERF_COUNTER_BULK_COUNT") {
extractFormula($cdef, "Used to count byte transmission rates.", "CounterData", "PerfTime", "PerfFreq", "8", "/Sec", "(X1-X0)/((Y1-Y0)/TB)");
} elsif ($cdef eq "PERF_COUNTER_COUNTER") {
extractFormula($cdef, "Rate of counts. This is the most common counter.", "CounterData", "PerfTime", "PerfFreq", "4", "/Sec", "(X1-X0)/((Y1-Y0/TB)");
} elsif ($cdef =~ /^(PERF_COUNTER_DELTA|PERF_COUNTER_LARGE_DELTA)$/) {
extractFormula($cdef, "Difference between two counters", "CounterData", "N/A", "N/A", "4", "No suffix", "X1-X0");
} elsif ($cdef eq "PERF_COUNTER_LARGE_QUEUELEN_TYPE") {
extractFormula($cdef, "Counter per time interval. Typically used to track number of items queued or waiting.", "CounterData", "PerfTime", "PerfFreq", "8", "No suffix", "(X1-X0)/(Y1-Y0)");
} elsif ($cdef =~ /^(PERF_COUNTER_RAWCOUNT|PERF_COUNTER_LARGE_RAWCOUNT)$/) {
extractFormula($cdef, "Intantaneous counter value.", "CounterData", "N/A", "N/A", "8", "No suffix", "X");
} elsif ($cdef =~ /^(PERF_COUNTER_RAWCOUNT_HEX|PERF_COUNTER_LARGE_RAWCOUNT_HEX)$/) {
extractFormula($cdef, "Intantaneous counter value intended to be displayed as a hexadecimal number.", "CounterData", "N/A", "N/A", "8", "No suffix", "X");
} elsif ($cdef eq "PERF_COUNTER_MULTI_BASE") {
extractFormula($cdef, "Used as the base data for the MULTI counters. It defines the number of similar items sampled. See PERF_COUNTER_MULTI_TIMER, PERF_COUNTER_MULTI_TIMER_INV, PERF_100NSEC_MULTI_TIMER, and PERF_100NSEC_MULTI_TIMER_INV.", "N/A", "N/A", "N/A", "8", "N/A", "N/A");
} elsif ($cdef eq "PERF_COUNTER_MULTI_TIMER") {
extractFormula($cdef, "Timer sampling of multiple but similar items. Result is an average sampling among the items. The number of items is in the base data.", "CounterData", "PerfTime", "PerfFreq", "8", "%", "100*((X1-X0/((Y1-Y0)/TB))/B1");
} elsif ($cdef eq "PERF_COUNTER_MULTI_TIMER_INV") {
extractFormula($cdef, "The inverse of the timer for multiple but similar items. Used when the objects are not in use.", "CounterData", "PerfTime", "PerfFreq", "8", "%", "100*(B1-((X1-X0/((Y1-Y0)/TB)))/B1");
} elsif ($cdef eq "PERF_COUNTER_NODATA") {
extractFormula($cdef, "There is no data for this counter.", "0", "N/A", "N/A", "0", "N/A", "0");
} elsif ($cdef eq "PERF_COUNTER_OBJECT_TIME_QUEUELEN_TYPE") {
extractFormula($cdef, "Queue-length space-time product using an object-speific time base.", "CounterData", "ObjectTime", "ObjectSpecific", "8", "No suffix", "(X1-X0)/(Y1-Y0)");
} elsif ($cdef eq "PERF_COUNTER_QUEUELEN_TYPE") {
extractFormula($cdef, "Count per time interval. Typically used to track number of items queued or waiting.", "CounterData", "PerfTime", "PerfFreq", "4", "No suffix", "(X1-X0)/(Y1-Y0)");
} elsif ($cdef eq "PERF_COUNTER_TIMER") {
extractFormula($cdef, "The most common timer.", "CounterData", "PerfTime", "PerfFreq", "8", "%", "100*(X1-X0)/(Y1-Y0)");
} elsif ($cdef eq "PERF_COUNTER_TIMER_INV") {
extractFormula($cdef, "The inverse of the timer. Used when the object is not in use.", "CounterData", "PerfTime", "PerfFreq", "8", "%", "100*(1-(X1-X0)/(Y1-Y0))");
} elsif ($cdef eq "PERF_ELAPSED_TIME") {
extractFormula($cdef, "The data is the start time of the item being measured. For display, subtract the start time from the snapshot time to yield the elapsed time. the PerfTime member of the PERF_OBJECT_TYPE structure contains the sample time. Use the PerfFreq member of the PERF_OBJECT_TYPE structure to convert the time into seconds.", "CounterData", "PerfTime", "PerfFreq", "8", "Sec", "(Y-X)/TB");
} elsif ($cdef =~ /^(PERF_RAW_BASE|PERF_LARGE_RAW_BASE)$/) {
extractFormula($cdef, "Used as a base data for PERF_RAW_FRACTION. The CounterData holds the denominator of the fraction value. Check that this value is greater than zero before dividing.", "N/A", "N/A", "N/A", "8", "N/A", "N/A");
} elsif ($cdef eq "PERF_OBJ_TIME_TIMER") {
extractFormula($cdef, "64-bit timer in object-spcific units.", "CounterData", "PerfTime", "ObjectSpecific", "8", "%", "(X1-X0)/(Y1-Y0)");
} elsif ($cdef eq "PERF_RAW_FRACTION") {
extractFormula($cdef, "Instantaneous value, to be divided by the base data. See PERF_RAW_BASE", "CounterData", "N/A", "N/A", "4", "%", "100*X/B");
} else {
print "$cdef is unsupported/undocumented in this release.\n";
}
}
sub extractFormula {
my ($cdef, $desc, $x, $y, $tb, $size, $suff, $calc) = @_;
format STDOUT =
Platform SDK
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cdef
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$desc
Element Value
X @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$x
Y @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$y
Time base @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$tb
Data size @<< bytes
$size
Display suffix @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$suff
Calculation @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$calc
=end
.
write;
}
sub Help {
print <<EOF;
$0 v1.0 by Adam Meltzer <ameltzer\@microsoft.com>
Syntax: $0 <-s|-o|-c> [-i|-d|-h]
Accepts the following options:
[opt] -s|--server Server name to fetch counters from (defaults to .>
[req] -o|--object Object to fetch counters from (ie: System, Processor)
[req] -c|--counter Name of counter (ie: % Processor Time)
[opt] -i|--instance Instance name (ie: _Total)
[opt] -d|--debug 0 = off, 1 = on
[opt] -h|--help You are here.
EOF
exit 1;
}
|