/usr/bin/condor_top.pl is in htcondor 8.6.8~dfsg.1-2.
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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | #!/usr/bin/perl -w
#
use strict;
use feature ':5.10';
use Fcntl;
use Getopt::Std;
#use warnings;
#Global variables
my @fileHashes;
my %selectedItems;
my %opts;
sub usage()
{
print "Usage: condor_top.pl [-nhs num] file1 file2
Calculate runtime statistics from two classads and display the top
results. The two input classads should be from the same daemon at
different times.
-h: Display this usage statement
-c num: Sort by column number 'num'\n";
exit;
}
sub HELP_MESSAGE()
{
usage();
}
sub VERSION_MESSAGE()
{
usage();
}
sub checkArgs()
{
my $num_args = $#ARGV + 1;
if ($num_args != 2)
{
usage();
}
}
sub parseKey
{
#Begin magical wizard voodoo (aka regular expressions)...
# Check to see that we have the proper number of arguements
if( (scalar (@_)) != 1)
{
die "ERROR: Unexpected number of arguments in 'parseKey()'\n";
}
#Store the key as a string
my $string = $_[0];
#Use reg ex to see if the key has "DC" at the beginning AND "Runtime"
#at the end
#if($string =~ /^DC/ && $string =~ /Runtime$/)
if($string =~ /Runtime$/)
{
#Remove "Runtime" from the end of the key
$string =~ s/Runtime//g;
return $string;
}
#If there isn't a match return an empty string
else
{
return "";
}
}
# Calculate the duty cycle used to determine the "health" of the system
sub dutyCycle
{
my $selectWaitTime = $fileHashes[1]{"DCSelectWaittime"} -
$fileHashes[0]{"DCSelectWaittime"};
my $pumpCycle_Count = $fileHashes[1]{"DCPumpCycleCount"} -
$fileHashes[0]{"DCPumpCycleCount"};
my $pumpCycle_Sum = $fileHashes[1]{"DCPumpCycleSum"} -
$fileHashes[0]{"DCPumpCycleSum"};
my $dDutyCycle = 0.0;
if($pumpCycle_Count)
{
if($pumpCycle_Sum > 1e-9)
{
$dDutyCycle = 1.0 - ($selectWaitTime / $pumpCycle_Sum);
}
}
return $dDutyCycle;
}
sub sortColumns
{
my ($col_num, %keyTable) = @_;
my @keys;
#$col_num--;
if($col_num == 6)
{
@keys = sort { $selectedItems{$b}[$col_num] cmp
$selectedItems{$a}[$col_num] } keys %keyTable;
}
else
{
@keys = sort { $selectedItems{$b}[$col_num] <=>
$selectedItems{$a}[$col_num] } keys %keyTable;
}
return @keys;
}
sub loadFiles()
{
#Variable declarations
my $handle;
checkArgs();
#Load file names
my @files = ($ARGV[0], $ARGV[1]);
#Load data into 2 hashtables
for(my $i = 0; $i < (scalar @files); $i++)
{
#Open file with read-only permissions
sysopen($handle,$files[$i], O_RDONLY) or
die "Couldn't open file $files[$i]";
#For each line, split components into key and value and
#store in hashtable
my @lines = <$handle>;
for(my $j = 2; $j < (scalar @lines); $j++)
{
my @strings = split(" = ",$lines[$j]);
#print "$strings[0] = $strings[1]";
$fileHashes[$i]{$strings[0]} = $strings[1];
}
close($handle);
}
}
sub generateHash()
{
#Initialize variables
my $countB = 0;
my $countA = 0;
my $runtimeB = 0;
my $runtimeA = 0;
my $max = 0;
my $overall_avg = 0;
my $inst_avg = 0;
my $delta_count = 0;
my $key = 0;
my $timeB = 0;
my $timeA = 0;
#For every key in the hash table...
foreach $key (keys(%{$fileHashes[0]}))
{
$key = parseKey($key);
#print "key=$key\n";
#If a key is not usable... or the key is not one of the
#following...
if($key ne "" || !($key eq "DCSocket" || $key eq "DCTimer"
|| $key eq "DCSignal" || $key eq "DCPipe"))
{
#Reset variables
$countB = 0;
$countA = 0;
$runtimeB = 0;
$runtimeA = 0;
$max = 0;
$overall_avg = 0;
$inst_avg = 0;
$delta_count = 0;
#Check to see if the item exists in the
#hashtable, set it to its var and remove
#any newline characters
if(defined($fileHashes[1]{$key}))
{
$countB = $fileHashes[1]{$key};
chomp($countB);
}
#print "key=$key count=$countB\n";
#Skip those which have 0 as a count as they don't
#have much useful info
if($countB == 0)
{
next;
}
#print "key=$key count=$countB\n";
if(defined($fileHashes[0]{$key}))
{
$countA = $fileHashes[0]{$key};
chomp($countA);
}
if(defined($fileHashes[0]{$key."Runtime"}))
{
$runtimeA = $fileHashes[0]{$key."Runtime"};
chomp($runtimeA);
}
if(defined($fileHashes[1]{$key."Runtime"}))
{
$runtimeB = $fileHashes[1]{$key."Runtime"};
chomp($runtimeB);
}
if(defined($fileHashes[1]{$key."RuntimeMax"}))
{
$max = $fileHashes[1]{$key."RuntimeMax"};
chomp($max);
}
if(defined($fileHashes[1]{$key."RuntimeAvg"}))
{
$overall_avg =
$fileHashes[1]{$key."RuntimeAvg"};
chomp($overall_avg);
}
if(defined($fileHashes[1]{"RecentStatsTickTime"}))
{
$timeB =
$fileHashes[1]{"RecentStatsTickTime"};
chomp($timeB);
}
if(defined($fileHashes[0]{"RecentStatsTickTime"}))
{
$timeA =
$fileHashes[0]{"RecentStatsTickTime"};
chomp($timeA);
}
#Check that we have the appropriate coponents and
#compute the instantaneous average
if($countA ne "" && $countB ne "" && $runtimeA ne ""
&& $runtimeB ne "")
{
my $denom = $countB - $countA;
if($denom != 0)
{
$inst_avg = ($runtimeB - $runtimeA)
/ ($countB - $countA);
}
}
#Check that we have the appropriate components
#and compute the normalized difference between the
#two data points
if($countA ne "" && $countB ne "")
{
my $minutes = ($timeB - $timeA) / 60;
if ($minutes) {
$delta_count= ($countB - $countA) / $minutes;
}
}
#Remove the first occurrence of "DC" from the
#item name
$key =~ s/^DC//g;
$selectedItems{$key} = [$runtimeB, $inst_avg, $overall_avg,
$delta_count, $countB, $max, $key];
}
}
}
#Print formatted health information
sub generateHealthTable()
{
if (exists $fileHashes[1]{"MonitorSelfSysCpuTime"}) {
my $str = sprintf("SysCpu: %9d UserCpu: %8d",
$fileHashes[1]{"MonitorSelfSysCpuTime"},
$fileHashes[1]{"MonitorSelfUserCpuTime"});
print("$str\n");
}
if (exists $fileHashes[1]{"MonitorSelfImageSize"}) {
my $str = sprintf("Memory: %9d RSS: %8d",
$fileHashes[1]{"MonitorSelfImageSize"},
$fileHashes[1]{"MonitorSelfResidentSetSize"});
print("$str\n");
}
my $dutyCycle = dutyCycle();
my $opsPerSec = "0";
if (exists $fileHashes[1]{"DCCommandsPerSecond_4m"}) { $opsPerSec = $fileHashes[1]{"DCCommandsPerSecond_4m"}; }
if (exists $fileHashes[1]{"DCCommandsPerSecond_20m"}) { $opsPerSec = $fileHashes[1]{"DCCommandsPerSecond_20m"}; }
if (exists $fileHashes[1]{"DCCommandsPerSecond_4h"}) { $opsPerSec = $fileHashes[1]{"DCCommandsPerSecond_4h"}; }
my $str = sprintf("Duty Cycle: %7.2f %% Ops/second: %9.3f", $dutyCycle*100.0,$opsPerSec);
print("$str\n\n");
}
#Print a formatted table listing statistics from 2 condor status data sets
sub generateTable()
{
my @keys;
my %notable_keys;
my $sort_col = 0;
my @cols = ("Runtime","Inst Avg","Avg","Count/Min","Count","Max","Item");
my $size = @cols;
#Verify arguments and apply column to sort by
if(exists($opts{'c'}))
{
if($opts{'c'} <= ((scalar @cols)) && $opts{'c'} <= 7)
{
$sort_col = $opts{'c'};
}
}
#If the -n command line argument has been given, display only the most
#notable items
if(exists($opts{'n'}))
{
#For each column except for "Item", add the top 5 items to a
#list to be printed and do not add an item if it already
#exists in the list.
for(my $i = 0; $i < $size - 1; $i++)
{
my @keys = sort { $selectedItems{$b}[$i] <=>
$selectedItems{$a}[$i] } keys %selectedItems;
for(my $k = 0; $k < 5; $k++)
{
if(!exists($notable_keys{$keys[$k]}))
{
$notable_keys{$keys[$k]} = "";
}
}
}
# Sorts hashtable by value in descending order
@keys = sortColumns($sort_col,%notable_keys);
}
else
{
# Sorts hashtable by value in descending order
@keys = sortColumns($sort_col,%selectedItems);
}
#Print column headers
my $str = sprintf("%9s%10s%7s%13s%11s%9s %s\n\n",$cols[0],$cols[1],
$cols[2],$cols[3],$cols[4],$cols[5],$cols[6]);
print($str);
#Print all "interesting" items in the generated list
foreach my $key (@keys)
{
$str = sprintf("%9.1f%10.3f%7.3f%13.2f%11.0f%9.3f %s\n",
$selectedItems{$key}[0],$selectedItems{$key}[1],
$selectedItems{$key}[2],$selectedItems{$key}[3],
$selectedItems{$key}[4],$selectedItems{$key}[5],
$selectedItems{$key}[6]);
print($str);
}
}
getopts('nc:h', \%opts);
if(exists($opts{'h'}))
{
usage();
}
loadFiles();
generateHash();
generateHealthTable();
generateTable();
|