Changeset 29373
- Timestamp:
- Oct 11, 2010, 3:11:19 PM (16 years ago)
- Location:
- trunk/tools/czartool
- Files:
-
- 2 edited
-
CzarDb.pm (modified) (8 diffs)
-
Plotter.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/czartool/CzarDb.pm
r29281 r29373 43 43 SQL 44 44 45 46 if (!$query->execute) { 47 48 return 0; 49 } 45 if (!$query->execute) {return 0;} 50 46 51 47 ${$labels} = $query->fetchall_arrayref(); … … 242 238 ########################################################################### 243 239 # 244 # Gets time series data and stores it to temp file 245 # 246 ########################################################################### 247 sub createTimeSeriesData { 248 my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff, $dataFile, $isLog) = @_; 249 250 ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_t.dat"; 251 252 open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n"; 240 # Gets time min/max/diff for a given period 241 # 242 ########################################################################### 243 sub getTimeMinMaxDiff { 244 my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff) = @_; 253 245 254 246 my $query = $self->{_db}->prepare(<<SQL); 255 247 SELECT 256 MIN(processed), GREATEST(MAX(pending), MAX(faults), max(processed)-min(processed)) AS maxY,257 LEAST(MIN(pending), MIN(faults), max(processed)-min(processed)) AS minY,258 248 DATE_FORMAT(MAX(timestamp),'$self->{_dateFormat}'), 259 249 DATE_FORMAT(MIN(timestamp),'$self->{_dateFormat}'), … … 266 256 if (!$query->execute) {return 0;} 267 257 268 my $minProcessed = undef; 269 my ($_maxY, $_minY, $_timeDiff); 270 ($minProcessed, $_maxY, $_minY, ${$maxX}, ${$minX}, $_timeDiff) = $query->fetchrow_array(); 271 272 if ($_maxY > ${$maxY}) {${$maxY} = $_maxY;} 273 if ($_minY < ${$minY}) {${$minY} = $_minY;} 258 my ($_timeDiff); 259 (${$maxX}, ${$minX}, $_timeDiff) = $query->fetchrow_array(); 260 274 261 if ($_timeDiff > ${$timeDiff}) {${$timeDiff} = $_timeDiff;} 275 262 263 return 1; 264 } 265 266 267 ########################################################################### 268 # 269 # Gets time series data and stores it to temp file 270 # 271 ########################################################################### 272 sub createTimeSeriesData { 273 my ($self, $label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff, $dataFile, $isLog, $showCleanup) = @_; 274 275 my $query = $self->{_db}->prepare(<<SQL); 276 SELECT 277 MIN(processed) 278 FROM $stage 279 WHERE label LIKE '$label' 280 AND timestamp >= '$fromTime' AND timestamp <= '$toTime'; 281 SQL 282 283 if (!$query->execute) {return 0;} 284 my $minProcessed = scalar $query->fetchrow_array(); # TODO remove 276 285 if (!defined $minProcessed) {return 0;} 286 287 $self->getTimeMinMaxDiff($label, $stage, $fromTime, $toTime, $minX, $maxX, $timeDiff); 277 288 278 289 $query = $self->{_db}->prepare(<<SQL); 279 290 SELECT 280 DATE_FORMAT(timestamp, '$self->{_dateFormat}'), pending, faults, processed -$minProcessed291 DATE_FORMAT(timestamp, '$self->{_dateFormat}'), pending, faults, processed 281 292 FROM $stage 282 293 WHERE label LIKE '$label' … … 287 298 $query->execute; 288 299 289 # loop round results 300 ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_t.dat"; 301 open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n"; 302 303 my $lastProcessed = -1; 304 my $processed = 0; 290 305 while (my @row = $query->fetchrow_array()) { 291 my ($timestamp, $pending, $faults, $processed) = @row; 306 my ($timestamp, $pending, $faults, $thisProcessed) = @row; 307 308 if ($showCleanup) { 309 310 $processed = $thisProcessed - $minProcessed; 311 } 312 elsif($lastProcessed != -1 && $thisProcessed > $lastProcessed) { 313 314 $processed = $processed + ($thisProcessed - $lastProcessed); 315 } 292 316 293 317 if ($isLog) { … … 303 327 304 328 print GNUDAT "$timestamp $pending $faults $processed\n"; 329 $lastProcessed = $thisProcessed; 305 330 } 306 331 … … 365 390 sub countProcessedPendingAndFaults { 366 391 my ($self, $label, $stage, $fromTime, $toTime, $processed, $pending, $faults) = @_; 367 368 392 369 393 my $query = $self->{_db}->prepare(<<SQL); … … 379 403 (${$pending}, ${$faults}) = $query->fetchrow_array(); 380 404 381 $query = $self->{_db}->prepare(<<SQL); 382 SELECT 383 MAX(processed) - MIN(processed) 384 FROM $stage 385 WHERE label LIKE '$label' 386 AND timestamp >= '$fromTime' AND timestamp <= '$toTime'; 387 SQL 388 $query->execute; 389 (${$processed}) = $query->fetchrow_array(); 405 ${$processed} = $self->countProcessed($label, $stage, $fromTime, $toTime); 406 407 return 1; 390 408 } 391 409 … … 510 528 print GNUDAT "$timestamp $available\n"; 511 529 } 530 512 531 close(GNUDAT); 513 532 514 533 return $dataFile; 515 534 } 516 ########################################################################### 517 # 518 # Determines how much has been processed in the provided interval of time 519 # (format: 1 HOUR, 1 MINUTE 1 DAY etc) 520 # 521 ########################################################################### 522 sub countProcessed { # TODO use time not interval 523 my ($self, $label, $stage, $interval) = @_; 535 536 ########################################################################### 537 # 538 # TODO implement isLog 539 # 540 ########################################################################### 541 sub createProcessingRateData { 542 my ($self, $stage, $label, $startDay, $endDay, $interval, $dataFile, $isLog) = @_; 543 544 my $startTime = $startDay; 545 my $endTime; 546 my $quit = 0; 547 my $processed; 548 my $pending; 549 my $faults; 550 my $timestamp; 551 ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_r.dat"; 552 open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n"; 553 my $cleanupCarry = 0; 554 while(1) { 555 556 if (!$self->isBefore($startTime, $endDay)) {last;} 557 $endTime = $self->addInterval($startTime, $interval); 558 print "NNN $startTime, $endTime\n"; 559 $self->countProcessedPendingAndFaults($label, $stage, $startTime, $endTime, \$processed, \$pending, \$faults); 560 $timestamp = $self->getFormattedDate($endTime); 561 print GNUDAT "$timestamp $processed 0 0\n"; 562 print "FILE $timestamp $processed 0 0\n"; 563 564 $startTime = $endTime; 565 } 566 567 close(GNUDAT) or print "* Problem closing gnuplot data file for rate plot for '$label' '$stage'\n" 568 } 569 570 ########################################################################### 571 # 572 # Gets count of processed stuff in a given time period 573 # 574 ########################################################################### 575 sub countProcessed { 576 my ($self, $label, $stage, $begin, $end) = @_; 524 577 525 578 my $query = $self->{_db}->prepare(<<SQL); 526 579 SELECT 527 MAX(processed) - MIN(processed)528 FROM $stage 580 processed 581 FROM $stage 529 582 WHERE label LIKE '$label' 530 AND timestamp > (now() - INTERVAL $interval); 531 SQL 532 $query->execute; 533 534 return scalar $query->fetchrow_array(); 535 } 536 583 AND timestamp >= '$begin' 584 AND timestamp < '$end' 585 SQL 586 $query->execute; 587 588 my $processedArray = $query->fetchall_arrayref(); 589 590 my $processed; 591 my $thisCount = -1; 592 my $lastCount = -1; 593 my $count = 0; 594 foreach $processed ( @{$processedArray} ){ 595 596 ($thisCount) = @{$processed}; 597 598 if ($thisCount > $lastCount && $lastCount != -1) {$count = $count + ($thisCount - $lastCount);} 599 print "thisCount = $thisCount lastCount=$lastCount processed=$count\n"; 600 $lastCount = $thisCount; 601 } 602 603 return $count; 604 } 537 605 538 606 ########################################################################### -
trunk/tools/czartool/Plotter.pm
r29121 r29373 33 33 ########################################################################### 34 34 sub createImageFileName { 35 my ($self, $label, $stage, $suffix, $isLog ) = @_;35 my ($self, $label, $stage, $suffix, $isLog, $isRate) = @_; 36 36 37 37 my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; … … 55 55 ########################################################################### 56 56 # 57 # Plots a time series of processing rate for all stages for this label TODO duplication below. combine 58 # 59 ########################################################################### 60 sub createRateTimeSeries { 61 my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $isLog) = @_; 62 63 my $minX = 999999999; 64 my $maxX = -9999999999; 65 my $timeDiff = -1; 66 67 my $stages = undef; 68 69 if (!$selectedStage) {$stages = \@allStages;} 70 else {$stages = ["$selectedStage"]}; 71 72 $self->{_czarDb}->getTimeMinMaxDiff($label, $selectedStage, $beginTime, $endTime, \$minX, \$maxX, \$timeDiff); 73 74 my $divX; 75 my $timeFormat; 76 $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat); 77 78 print "$beginTime, $endTime | $divX $minX $maxX $timeFormat\n"; 79 80 my %gnuplotFiles; 81 my $stage = undef; 82 my $gnuplotFile = undef; 83 my $outputFile = createImageFileName($self, $label, $selectedStage, "r", $isLog); 84 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 85 use FileHandle; 86 GP->autoflush(1); 87 print GP 88 "set term $self->{_outputFormat};" . 89 "set output \"$outputFile\";" . 90 "set title \"'$label', '$selectedStage' during '$beginTime' to '$endTime'\";" . 91 #"set xdata time;" . 92 "set timefmt \"$self->{_dateFormat}\";" . 93 "set format x \"$timeFormat\";" . 94 "set xtics \"$minX\", $divX, \"$maxX\";" . 95 # "set xrange [\"$minX\":\"$maxX\"];" . 96 "set grid;" . 97 "set boxwidth;" . 98 "set style data histogram;" . 99 "set style histogram rowstacked;" . 100 "set style fill solid border -1;" . 101 "set ylabel \"Exposures processed per $interval\";" . 102 "set boxwidth 0.75;" . 103 "plot "; 104 105 my $first = 1; 106 foreach $stage (@{$stages}) { 107 108 if ($self->{_czarDb}->createProcessingRateData( 109 $stage, 110 $label, 111 $beginTime, 112 $endTime, 113 $interval, 114 \$gnuplotFile, 115 $isLog)) { 116 117 $gnuplotFiles{$stage} = $gnuplotFile; 118 119 if (!$first) { print GP ","; } 120 print GP "'$gnuplotFile' using 2:xtic(1) title \"$stage\" "; 121 $first = 0; 122 } 123 } 124 125 print GP ";\n"; 126 close GP; 127 } 128 ########################################################################### 129 # 57 130 # Plots a time series for all stages for this label 58 131 # 59 132 ########################################################################### 60 133 sub createTimeSeries { 61 my ($self, $label, $selectedStage, $beginTime, $endTime, $isLog) = @_; 62 63 my ($minX, $maxX, $minY, $maxY, $timeDiff); 64 $minX = 999999999; 65 $maxX = -9999999999; 66 $minY = 999999999; 67 $maxY = -99999999; 68 $timeDiff = 0; 134 my ($self, $label, $selectedStage, $beginTime, $endTime, $isLog, $showCleanup) = @_; 135 136 my $minX = 999999999; 137 my $maxX = -9999999999; 138 my $timeDiff = 0; 69 139 70 140 my $stages = undef; … … 85 155 \$minX, 86 156 \$maxX, 87 \$minY,88 \$maxY,89 157 \$timeDiff, 90 158 \$gnuplotFile, 91 $isLog)) { 159 $isLog, 160 $showCleanup)) { 92 161 93 162 $gnuplotFiles{$stage} = $gnuplotFile; … … 118 187 $maxX, 119 188 $minX, 120 $maxY,121 $minY,122 189 $timeDiff, 123 190 $isLog); … … 161 228 close(GNUDAT); 162 229 163 plotHistogram($self, $inputFile, $outputFile, $label, $beginTime, $endTime, $maxY); 230 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 231 use FileHandle; 232 GP->autoflush(1); 233 234 if ($maxY == 0) {$maxY = 1;} 235 else {$maxY = $maxY*1.1;} 236 237 print GP 238 "set term $self->{_outputFormat};" . 239 "set output \"$outputFile\";" . 240 "set title \"'$label', '$beginTime' to '$endTime'\";" . 241 "set grid;" . 242 "set boxwidth;" . 243 "set yrange [\"0\":\"$maxY\"];" . 244 "set style data histogram;" . 245 "set style histogram rowstacked;" . 246 "set style fill solid border -1;" . 247 "set ylabel \"Exposures\";" . 248 "set boxwidth 0.75;" . 249 "plot '$inputFile' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" . 250 "\n"; 251 252 close GP; 164 253 unlink($inputFile); 165 254 } 166 167 255 168 256 ########################################################################### … … 239 327 ########################################################################### 240 328 sub plotTimeSeries { 241 my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $ maxY, $minY, $timeDiff, $isLog) = @_;329 my ($self, $gnuplotFiles, $outputFile, $label, $fromTime, $toTime, $maxX, $minX, $timeDiff, $isLog) = @_; 242 330 243 331 my $timeFormat = undef; … … 346 434 close GP; 347 435 unlink($gnuplotFile); 348 }349 350 ###########################################################################351 #352 # Plots a histogram of processed stuff353 #354 ###########################################################################355 sub plotHistogram {356 my ($self, $inputFile, $outputFile, $label, $fromTime, $toTime, $maxY) = @_;357 358 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";359 use FileHandle;360 GP->autoflush(1);361 362 if ($maxY == 0) {$maxY = 1;}363 else {$maxY = $maxY*1.1;}364 365 print GP366 "set term $self->{_outputFormat};" .367 "set output \"$outputFile\";" .368 "set title \"'$label', '$fromTime' to '$toTime'\";" .369 "set grid;" .370 "set boxwidth;" .371 "set yrange [\"0\":\"$maxY\"];" .372 "set style data histogram;" .373 "set style histogram rowstacked;" .374 "set style fill solid border -1;" .375 "set ylabel \"Exposures\";" .376 "set boxwidth 0.75;" .377 "plot '$inputFile' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" .378 "\n";379 380 close GP;381 436 } 382 437
Note:
See TracChangeset
for help on using the changeset viewer.
