IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29834


Ignore:
Timestamp:
Nov 26, 2010, 10:33:29 AM (15 years ago)
Author:
eugene
Message:

merge updates from trunk

Location:
branches/eam_branches/ipp-20101103/tools
Files:
8 edited
9 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101103/tools/czarplot.pl

    r29580 r29834  
    88
    99use czartool::CzarDb;
     10use czartool::Gpc1Db;
    1011use czartool::Plotter;
     12use czartool::StageMetrics;
    1113
    1214my $czarDbName = "czardb";
     
    1416my $stage = undef;
    1517my $save_temps = undef;
    16 my $interval = undef;
     18my $timeinpast = undef;
    1719my $begin = undef;
    1820my $end = undef;
     
    2325my $timeSeries = undef;
    2426my $rate = undef;
     27my $magicMask = undef;
     28my $rateInterval = undef;
    2529my $deriv = undef;
    2630my $showCleanup = undef;
     
    2832my $savingToFile = undef;
    2933my $analysis = undef;
     34my $exposureId = undef;
    3035my $log = undef;
    3136
     
    3439        "label|l=s" => \$label,
    3540        "stage|s=s" => \$stage,
    36         "interval|i=s" => \$interval,
     41        "timeinpast|p=s" => \$timeinpast,
     42        "rateinterval|i=s" => \$rateInterval,
     43        "exposureid|x=s" => \$exposureId,
     44        "mask|m" => \$magicMask,
    3745        "begin|b=s" => \$begin,
    3846        "end|e=s" => \$end,
     
    5765    print "* UNKNKOWN: option                          @ARGV\n";
    5866}
     67if ($analysis && !$stage) {
     68    $quit = 1;
     69    print "* REQUIRED: choose a stage for analsis      -s <chip|cam|warp|etc>      (default=none)\n";}
    5970if (!$histogram) {
    6071    print "* OPTIONAL: plot histogram                  -h                          (default=off)\n";}
    6172if (!$timeSeries) {
    6273    print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";}
     74if (!$magicMask) {
     75    print "* OPTIONAL: plot magic mask for these times -m                          (default=off)\n";}
     76if (!$exposureId) {
     77    print "* OPTIONAL: set exposure ID for magic mask  -x                          (default=none)\n";}
    6378if (!$rate) {
    64     print "* OPTIONAL: plot timeseries of rate         -r                          (default=off)\n";}
     79    print "* OPTIONAL: plot histogram of rate          -r                          (default=off)\n";}
    6580if (!$deriv) {
    6681    $deriv = 0;
     
    7489if (!$log) {
    7590    $log = 0;
    76     print "* OPTIONAL: use log plots                   -g                          (default=$log\n";}
     91    print "* OPTIONAL: use log plots                   -g                          (default=$log)\n";}
    7792if (!$nebulous) {
    7893    print "* OPTIONAL: plot nebulous disk space        -n                          (default=off)\n";}
     
    8297if (!$stage) {
    8398    print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";}
    84 if (!$interval) {
    85     print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=none\n";}
     99if (!$timeinpast) {
     100    print "* OPTIONAL: choose time interval in past    -p <'1 hour'|'1 day'|etc>   (default=none\n";}
     101if (!$rateInterval) {
     102    print "* OPTIONAL: time interval for rate plot     -i <'1 hour'|'1 day'|etc>   (default=depends on time frame)\n";}
    86103if (!$begin) {
    87104    print "* OPTIONAL: choose a begin time             -b <datetime>               (default=6:35am this morning)\n";}
     
    98115
    99116# default values
    100 if (!$nebulous && !$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 0;}
     117if (!$rate && !$magicMask && !$nebulous && !$histogram && !$analysis && !$timeSeries) {$timeSeries = 1;}
    101118if (!$verbose) {$verbose = 0;}
    102119if (!$save_temps) {$save_temps = 0;}
     
    104121else {$savingToFile = 1;}
    105122
     123my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
    106124my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose, $save_temps);
    107125$czarDb->setDateFormat("%Y%m%d-%H%i%s");
     
    109127
    110128my $plotter = new czartool::Plotter(
     129        $gpc1Db,
    111130        $czarDb,
    112131        "%Y%m%d-%H%M%S",
     
    121140    $begin =  "$day 06:35";
    122141    $end = "$day 23:59";
     142        print "JKJKJK '$begin' '$end' \n";
     143
    123144}
    124145else {
     
    127148    if (!$begin) {
    128149
    129         if ($interval) {$begin = $czarDb->subtractInterval($end, $interval);}
     150        if ($timeinpast) {$begin = $czarDb->subtractInterval($end, $timeinpast);}
    130151        else {$begin =  strftime('%Y-%m-%d 06:35',localtime);}
    131152    }
     
    134155
    135156if ($rate) {
    136 
    137     if (!$interval) {$interval = "1 HOUR";}
    138     $plotter->createRateTimeSeries($label, $stage, $begin, $end, $interval, $log);
     157    $plotter->createRateTimeSeries($label, $stage, $begin, $end, $rateInterval, $log);
    139158    exit;
    140159}
     
    143162if ($nebulous && $timeSeries) {$plotter->plotStorageTimeSeries($begin, $end);}
    144163elsif ($nebulous) {$plotter->plotDiskUsageHistogram();}
     164if ($magicMask) {
     165   
     166    if ($exposureId) {$plotter->plotMagicMaskFractionForThisExposure($exposureId);}
     167    else {$plotter->plotMagicMaskFractionHistogram($begin, $end);}
    145168
     169}
    146170
    147171if($analysis) {
    148172
    149     my ($started, $finished, $stuck, $processed, $pending, $faults, $totalTime);
    150     $czarDb->runAnalysis($label, $stage, $begin, $end, \$started, \$finished, \$stuck, \$processed, \$pending, \$faults, \$totalTime);
    151 
    152     if (defined $started) {print "* Processing started at $started\n";}
    153     if (defined $finished) {print "* Processing finished at $finished and took $totalTime\n";}
    154     else {print "* Processing has not finished\n";}
    155     if (defined $stuck) {print "* Processing has been stuck since $stuck\n";}
    156     print "* $processed exposures have been processed, with $pending pending and $faults faults\n";
    157 
    158     print "*******************************************************************************\n";
     173    my $stageMetrics = new czartool::StageMetrics($stage, $label, $begin, $end);
     174    if ($czarDb->runAnalysis($stageMetrics)) {$stageMetrics->printMe();}
    159175}
  • branches/eam_branches/ipp-20101103/tools/czarpoll.pl

    r29583 r29834  
    1313use czartool::Plotter;
    1414use czartool::Burntool;
     15use czartool::DayMetrics;
     16
    1517
    1618my $period = 60;
     
    2729my $nebulous = new czartool::Nebulous($czarDb);
    2830my $pantasks = new czartool::Pantasks();
    29 my $plotter = new czartool::Plotter($czarDb, "%Y%m%d-%H%M%S", "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8", "/tmp", $save_temps); # TODO hardcoded font path
     31my $plotter = new czartool::Plotter($gpc1Db, $czarDb, "%Y%m%d-%H%M%S", "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8", "/tmp", $save_temps); # TODO hardcoded font path
    3032my $burntool = new czartool::Burntool();
     33
    3134
    3235$czarDb->setDateFormat("%Y%m%d-%H%i%s");
     
    107110    my $lastDay = strftime('%Y-%m-%d', localtime);
    108111    my $today = undef;
     112    my $doneMetricsToday = 1;
    109113
    110114    while (1) {
     
    118122                $czarDb->optimize();
    119123                $lastDay = $today;
     124                $doneMetricsToday = 0;
    120125        }
    121126
     
    124129        $end = $czarDb->getNowTimestamp();
    125130
     131        # if time now is after 06:35am, then create metrics for past 24 hours
     132        if (!$doneMetricsToday && $czarDb->isBefore($begin, $end)) {
     133       
     134                print "* Creating metrics for last 24 hours\n";
     135                # TODO hardcopded path needs to be in config
     136                my $dayMetrics = new czartool::DayMetrics($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0, $today);
     137                $dayMetrics->writeHTML();
     138
     139                $doneMetricsToday = 1;
     140        }
     141
     142        # if time now is before 06:35am, include data from previous day
    126143        if ($czarDb->isBefore($end, $begin)) {
    127144
     
    197214            chomp($label);
    198215            $plotter->createLogAndLinearTimeSeries($label,  $stage, $begin, $end);
    199         }
    200     }
     216            $plotter->createRateTimeSeries($label, $stage, $begin, $end, undef, 0);
     217        }
     218    }
     219
     220    my $allServerLabels = undef;
    201221
    202222    # create plots for each label for all stages
     
    205225
    206226        $plotter->createLogAndLinearTimeSeries($label, undef, $begin, $end);
     227        $plotter->createRateTimeSeries($label, undef, $begin, $end, undef, 0);
    207228        $plotter->createHistogram($label, $begin, $end);
    208 
    209         #routineChecks($label, "1 HOUR");
    210     }
    211     $plotter->createLogAndLinearTimeSeries("all_".$server."_labels", undef, $begin, $end);
    212     $plotter->createHistogram("all_".$server."_labels", $begin, $end);
     229    }
     230
     231    $allServerLabels = "all_".$server."_labels";
     232
     233    $plotter->createLogAndLinearTimeSeries($allServerLabels, undef, $begin, $end);
     234    $plotter->createRateTimeSeries($allServerLabels, undef, $begin, $end, undef, 0);
     235    $plotter->createHistogram($allServerLabels, $begin, $end);
    213236    foreach $stage (@stages) {
    214237
    215         $plotter->createLogAndLinearTimeSeries("all_".$server."_labels",  $stage, $begin, $end); # TODO must be a neater way...
     238        $plotter->createLogAndLinearTimeSeries($allServerLabels,  $stage, $begin, $end); # TODO must be a neater way...
     239        $plotter->createRateTimeSeries($allServerLabels, $stage, $begin, $end, undef, 0);
    216240    }
    217241}
  • branches/eam_branches/ipp-20101103/tools/czartool/CzarDb.pm

    r29582 r29834  
    66use strict;
    77
     8use File::Temp;
     9
    810my @stages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist"); # TODO put elsewhere
    911
    1012use base 'czartool::MySQLDb';
    1113our @ISA = qw(czartool::MySQLDb);    # inherits from MySQLDb
     14
     15use czartool::StageMetrics;
    1216
    1317###########################################################################
     
    4953    return 1;
    5054}
     55
     56###########################################################################
     57#
     58# Gets stdscience lables active in the provided time period
     59# TODO ugly hack to avoind getting update labels
     60#
     61###########################################################################
     62sub getStdscienceLabelsInTimePeriod {
     63    my ($self, $begin, $end, $labels) = @_;
     64
     65    my $query = $self->{_db}->prepare(<<SQL);
     66
     67    SELECT DISTINCT label
     68        FROM chip
     69        WHERE timestamp >= '$begin'
     70        AND timestamp <= '$end'
     71        AND label NOT LIKE '%_ud%'
     72        AND label NOT LIKE 'update%'
     73        AND label NOT LIKE 'all_%_labels'
     74SQL
     75
     76    if (!$query->execute) {return 0;}
     77
     78    ${$labels} = $query->fetchall_arrayref();
     79
     80    return 1;
     81}
     82
     83
    5184
    5285###########################################################################
     
    264297}
    265298
     299###########################################################################
     300#
     301# Returns the start and end times during one day for the provided label and start/end stages
     302#
     303###########################################################################
     304sub getDayTimings {
     305    my ($self, $label, $startStage, $endStage, $begin, $started, $finished, $timeTaken) = @_;
     306
     307    my $end = $self->addInterval($begin, "1 DAY");
     308
     309    my $startStageMetrics = new czartool::StageMetrics($startStage, $label, $begin, $end);
     310    my $endStageMetrics = new czartool::StageMetrics($endStage, $label, $begin, $end);
     311
     312    if (!$self->runAnalysis($startStageMetrics)) {return 0;}
     313    if (!$self->runAnalysis($endStageMetrics)) {return 0;}
     314
     315    ${$started} = $startStageMetrics->getStarted();
     316    ${$finished} = $endStageMetrics->getFinished100();
     317
     318    if (!${$started} || !${$finished}) {${$timeTaken} = undef;}
     319    else {${$timeTaken} = $self->diffTimes(${$finished}, ${$started});}
     320
     321    return 1;
     322}
    266323
    267324###########################################################################
     
    271328###########################################################################
    272329sub runAnalysis {
    273     my ($self,
    274             $label,
    275             $stage,
    276             $fromTime,
    277             $toTime,
    278             $_started,
    279             $_finished,
    280             $_stuck,
    281             $_processed,
    282             $_pending,
    283             $_faults,
    284             $_totalTime) = @_;
     330    my ($self, $stageMetrics) = @_;
     331
     332    if (!$stageMetrics) {return 0;}
     333
     334    my $stage = $stageMetrics->getStage();
     335    my $label = $stageMetrics->getLabel();
     336    my $fromTime = $stageMetrics->getStartTime();
     337    my $toTime = $stageMetrics->getEndTime();
     338
     339    $toTime = $self->addInterval($toTime, "20 MINUTE"); # TODO dodgy
    285340
    286341    my $query = $self->{_db}->prepare(<<SQL);
     
    293348SQL
    294349
    295     $query->execute;
    296 
    297350    my $lastProcessed = -1;
    298351    my $lastPending = -1;
     
    300353    my $lastTimestamp = undef;
    301354    my ($linearProcessed, $linearPending, $linearFaults);
     355
     356    # first, count toatl processed in time window so that we can find time of 50%, 75%, 90% etc
     357    $query->execute;
     358    my $totalProcessed = 0;
     359    my $firstRow = 1;
     360    while (my @row = $query->fetchrow_array()) {
     361        my ($thisTimestamp, $thisPending, $thisFaults, $thisProcessed) = @row;
     362
     363        # get linear values
     364        if($lastProcessed != -1 && $thisProcessed > $lastProcessed) {
     365           
     366            $totalProcessed = $totalProcessed + ($thisProcessed - $lastProcessed);
     367        }
     368
     369        $lastProcessed = $thisProcessed;
     370        if ($firstRow) {$stageMetrics->setInitialPending($thisPending); $firstRow = 0;}
     371    }
     372
     373    # nothing to do here
     374    if (!$totalProcessed) {return 1;}
     375
     376    my $percent25 = $totalProcessed * 0.25;
     377    my $percent50 = $totalProcessed * 0.5;
     378    my $percent75 = $totalProcessed * 0.75;
     379    my $percent90 = $totalProcessed * 0.9;
     380    my $percent95 = $totalProcessed * 0.95;
     381
    302382    my ($derivProcessed, $derivPending, $derivFaults);
    303     my $started = undef;
    304     my $finished = undef;
    305    
    306383    my $notProcessing = undef;
    307384    my $howLongNotProcessing = undef;
    308385    my $notProcessingLongerThanInterval = 0;
    309 
    310386    my $stuck = undef;
    311387    my $howLongStuck = undef;
    312388    my $stuckLongerThanInterval = 0;
    313 
    314389    my $stuffToDo = undef;
    315     my $interval = "00:20:00";
    316 
     390    my $interval = "00:20:00"; # TODO dodgy - see above
     391    my $started = undef;
     392    my $finished = undef;
     393   
     394    my ($have25, $have50, $have75, $have90, $have95, $have100) = 0;
     395
     396    # now, loop again, this time recording more data
     397    $query->execute;
    317398    $linearProcessed = 0;
     399    $lastProcessed = -1;
    318400    while (my @row = $query->fetchrow_array()) {
    319401        my ($thisTimestamp, $thisPending, $thisFaults, $thisProcessed) = @row;
     
    326408        $linearPending = $thisPending;
    327409        $linearFaults = $thisFaults;
     410
     411        if (!$have25 && $linearProcessed >= $percent25) {$stageMetrics->setFinished25($thisTimestamp); $have25 = 1;}
     412        if (!$have50 && $linearProcessed >= $percent50) {$stageMetrics->setFinished50($thisTimestamp); $have50 = 1;}
     413        if (!$have75 && $linearProcessed >= $percent75) {$stageMetrics->setFinished75($thisTimestamp); $have75 = 1;}
     414        if (!$have90 && $linearProcessed >= $percent90) {$stageMetrics->setFinished90($thisTimestamp); $have90 = 1;}
     415        if (!$have95 && $linearProcessed >= $percent95) {$stageMetrics->setFinished95($thisTimestamp); $have95 = 1;}
    328416
    329417        # get first derivative values
     
    363451                if (defined $notProcessing) {
    364452                   
    365                     if ($stuckLongerThanInterval) {
    366 
    367 #                        print "* $stage procesing was stuck for  $howLongStuck, from $stuck until $lastTimestamp\n";
    368                     }
    369                     if ($notProcessingLongerThanInterval) {
    370 
    371             #            print " * $stage not procesing for  $howLongNotProcessing, from $notProcessing until $thisTimestamp\n";
    372                     }
    373453                    $notProcessing = undef;
    374454                    $stuck = undef;
    375455                }
    376456                if (!defined $started) {
     457
    377458                    $started = $lastTimestamp;
    378459                    $finished = undef;
    379 #                    print "* $stage processing started at $started\n";
    380460                }
    381461            }
     
    418498    }
    419499
    420     ${$_processed} = $linearProcessed;
    421     ${$_pending} = $stuffToDo;
    422     ${$_faults} = $lastFaults;
     500    $stageMetrics->setProcessed($linearProcessed);
     501    $stageMetrics->setFinalPending($stuffToDo);
     502    $stageMetrics->setFaults($lastFaults);
     503
     504
     505    if (!defined $finished) {
     506
     507        $stageMetrics->setFinished25(undef);
     508        $stageMetrics->setFinished50(undef);
     509        $stageMetrics->setFinished75(undef);
     510        $stageMetrics->setFinished90(undef);
     511        $stageMetrics->setFinished95(undef);
     512        $stageMetrics->setFinished100(undef);
     513        $stageMetrics->setTotalTime($self->diffTimes($lastTimestamp, $started));
     514    }
    423515
    424516    if (defined $finished) {
    425         ${$_finished} = $finished;
    426         ${$_totalTime} = $self->diffTimes($finished, $started);
    427     }
    428 
    429     elsif(defined $started) {
    430    
    431         ${$_finished} = undef;
    432     }
    433    
     517
     518        $stageMetrics->setFinished100($finished);
     519        $stageMetrics->setTotalTime($self->diffTimes($finished, $started));
     520    }
     521
     522
    434523    if (!defined $started){
    435524   
    436         ${$_started} = undef;
     525        $stageMetrics->setStarted(undef);
    437526    }
    438527    else {
    439528   
    440         ${$_started} = $started;
     529        my $rate = ($stageMetrics->getProcessed()/$self->getTimeInSecs($stageMetrics->getTotalTime) ) * 3600.0;
     530        $stageMetrics->setRate($rate);
     531        $stageMetrics->setStarted($started);
    441532    }
    442533    if ($stuck && $stuckLongerThanInterval && !defined $finished) {
    443534
    444         ${$_stuck} = $stuck;
     535        $stageMetrics->setStuck($stuck);
    445536    }
    446537    else {
    447538   
    448         ${$_stuck} = undef;
     539        $stageMetrics->setStuck(undef);
    449540    }
    450541
     
    484575    $query->execute;
    485576
    486     ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_t.dat";
     577    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_".$stage."_t.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     578    $tmpFile->unlink_on_destroy( 0 );
     579    ${$dataFile} = $tmpFile->filename;
    487580    open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
    488581
     
    497590   
    498591    $linearProcessed = 0;
     592    my $someData = 0;
    499593    while (my @row = $query->fetchrow_array()) {
    500594        my ($thisTimestamp, $thisPending, $thisFaults, $thisProcessed) = @row;
     
    517611            my $timeDiff = $self->diffTimesInSecs($thisTimestamp, $lastTimestamp);
    518612               
    519             if ($thisProcessed >= $lastProcessed){
     613            if ($thisProcessed >= $lastProcessed && $timeDiff){
    520614                $derivProcessed = abs($thisProcessed - $lastProcessed)/$timeDiff;
    521615            }
     
    547641        else {print GNUDAT "$timestamp $linearPending $linearFaults $linearProcessed\n";}
    548642
     643        if ($linearPending > 0 || $linearFaults > 0 || $linearProcessed > 0) {$someData = 1;}
     644
    549645        $lastProcessed = $thisProcessed;
    550646        $lastPending = $thisPending;
     
    555651    close(GNUDAT) or print "* Problem closing gnuplot data file for plot for '$label' '$stage'\n";
    556652
    557     return 1;
     653    #return $someData;
    558654}
    559655
     
    637733###########################################################################
    638734sub createHostsData {
    639     my ($self, $limit) = @_;
    640 
    641     my $dataFile = "/tmp/czarplot_hosts_space.dat";
    642     open (GNUDAT, ">$dataFile");
     735    my ($self, $limit, $tmpFile) = @_;
     736
     737    open (GNUDAT, ">".$tmpFile->filename);
    643738
    644739    my $query = $self->{_db}->prepare(<<SQL);
     
    686781        print GNUDAT "\n";
    687782    }
     783
    688784    close(GNUDAT);
    689 
    690     return $dataFile;
    691785}
    692786
     
    714808###########################################################################
    715809sub createStorageTimeSeriesData {
    716     my ($self, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff) = @_;
    717 
    718     my $dataFile = "/tmp/czarplot_gnuplot_storage_timeseries.dat";
    719     open (GNUDAT, ">$dataFile");
     810    my ($self, $tmpFile, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff) = @_;
     811
     812    open (GNUDAT, ">".$tmpFile->filename);
    720813
    721814    my $query = $self->{_db}->prepare(<<SQL);
     
    753846
    754847    close(GNUDAT);
    755 
    756     return $dataFile;
    757848}
    758849
     
    763854###########################################################################
    764855sub createProcessingRateData {
    765     my ($self, $stage, $label, $startDay, $endDay, $interval, $dataFile, $isLog) = @_;
    766 
    767     my $startTime = $startDay;
     856    my ($self, $stage, $label, $begin, $end, $interval, $dataFile, $isLog) = @_;
     857
     858    my $startTime = $begin;
    768859    my $endTime;
    769860    my $quit = 0;
     
    772863    my $faults;
    773864    my $timestamp;
    774     ${$dataFile} = "/tmp/czarplot_gnuplot_".$label."_".$stage."_r.dat";
     865
     866    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_".$stage."_r.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     867    $tmpFile->unlink_on_destroy( 0 );
     868    ${$dataFile} = $tmpFile->filename;
     869
    775870    open (GNUDAT, ">${$dataFile}") or print "* Problem opening gnuplot data file for plot for '$label' '$stage'\n";
    776871    my $cleanupCarry = 0;
     872    my $someData = 0;
    777873    while(1) {
    778874
    779         if (!$self->isBefore($startTime, $endDay)) {last;}
     875
     876        #print "NNN $startTime, $end\n";
     877        if (!$self->isBefore($startTime, $end)) {last;}
    780878        $endTime = $self->addInterval($startTime, $interval);
    781879        $self->countProcessedPendingAndFaults($label, $stage, $startTime, $endTime, \$processed, \$pending, \$faults);
     
    783881        print GNUDAT "$timestamp $processed 0 0\n";
    784882
     883        if ($processed > 0 ) {$someData = 1;}
     884
    785885        $startTime = $endTime;
    786886    }
    787887
    788     close(GNUDAT) or print "* Problem closing gnuplot data file for rate plot for '$label' '$stage'\n"
     888    close(GNUDAT) or print "* Problem closing gnuplot data file for rate plot for '$label' '$stage'\n";
     889
     890    #return $someData;
    789891}
    790892
     
    15121614    $self->setRevision(12);
    15131615}
    1514 
    151516161;
    15161617
  • branches/eam_branches/ipp-20101103/tools/czartool/Gpc1Db.pm

    r28924 r29834  
    6060###########################################################################
    6161#
     62# Returns the number of science exposures taken 'last night' for a given day
     63#
     64# Notes:
     65#
     66# - 03:00 HST = 17:00 last night UTC
     67# - 17:00 HST = 07:00 this morning UTC
     68# - 'OBJECT' = science exposures
     69#
     70###########################################################################
     71sub countScienceExposuresFromLastNight {
     72    my ($self, $day) = @_;
     73
     74    my $begin = "$day 03";
     75    my $end = "$day 17";
     76
     77    my $query = $self->{_db}->prepare(<<SQL);
     78    SELECT COUNT(*)
     79        FROM summitExp
     80        WHERE dateobs > '$begin'
     81        AND dateobs < '$end' AND
     82        exp_type = 'OBJECT';
     83SQL
     84
     85    $query->execute;
     86return scalar $query->fetchrow_array();
     87}
     88
     89###########################################################################
     90#
     91# Returns the number of exposures between two dates that have been registered with chip
     92#
     93# Notes:
     94#
     95# necessary to convert times as rawExp.dateobs is in UTC
     96#
     97###########################################################################
     98sub getProcessedExposures {
     99    my ($self, $beginDate, $endDate, $expIds) = @_;
     100
     101    $beginDate = "$beginDate 03";
     102    $endDate = "$endDate 17";
     103
     104    my $query = $self->{_db}->prepare(<<SQL);
     105        SELECT rawExp.exp_id
     106        FROM chipRun, rawExp
     107        WHERE chipRun.exp_id = rawExp.exp_id
     108        AND rawExp.dateobs >= '$beginDate'
     109        AND rawExp.dateobs <= '$endDate';
     110SQL
     111
     112    $query->execute;
     113    ${$expIds} = $query->fetchall_arrayref();
     114
     115    return 1;
     116}
     117
     118###########################################################################
     119#
    62120# Returns count of faults for this stage and label
    63121#
     
    158216    }
    159217
    160 
    161218    $query->execute;
    162219    return scalar $query->fetchrow_array();
    163220}
     221
     222###########################################################################
     223#
     224# Returns magic mask fraction across all chips for a particular exposure
     225#
     226###########################################################################
     227sub getMagicMaskFraction {
     228        my ($self, $exp_id, $fracs) = @_;
     229
     230            my $query = $self->{_db}->prepare(<<SQL);
     231            SELECT component, streak_frac
     232                FROM magicDSFile 
     233                JOIN magicDSRun USING(magic_ds_id)
     234                JOIN camRun USING(cam_id)
     235                JOIN chipRun USING(chip_id)
     236                WHERE exp_id = $exp_id
     237                AND camRun.label LIKE "%nightlyscience"
     238                AND component LIKE "XY%";
     239SQL
     240    $query->execute;
     241    ${$fracs} = $query->fetchall_arrayref();
     242
     243    return 1;
     244}
     245
     246###########################################################################
     247#
     248# Returns average magic mask fraction across all chips for a particular exposure
     249#
     250###########################################################################
     251sub getAverageMagicMaskFraction {
     252        my ($self, $exp_id) = @_;
     253
     254            my $query = $self->{_db}->prepare(<<SQL);
     255            SELECT AVG(streak_frac)
     256                FROM magicDSFile 
     257                JOIN magicDSRun USING(magic_ds_id)
     258                JOIN camRun USING(cam_id)
     259                JOIN chipRun USING(chip_id)
     260                WHERE exp_id = $exp_id
     261                AND camRun.label LIKE "%nightlyscience"
     262                AND component LIKE "XY%";
     263SQL
     264    $query->execute;
     265    return scalar $query->fetchrow_array();
     266}
    1642671;
  • branches/eam_branches/ipp-20101103/tools/czartool/MySQLDb.pm

    r29436 r29834  
    6464    return $self->{_dbHost};                                                 
    6565}                                                                               
    66 ###########################################################################
    67 #
    68 # Adds the provided interval to the provided time
     66
     67###########################################################################
     68#
     69# Returns a date formatted wit hthe current formatting
    6970#
    7071###########################################################################
     
    8283###########################################################################
    8384#
     85# Returns a full MySQL formatted date
     86#
     87###########################################################################
     88sub getFullDate {
     89    my ($self, $time) = @_;
     90
     91    my $query = $self->{_db}->prepare(<<SQL);
     92    SELECT DATE_FORMAT('$time','%Y-%m-%d %H:%i:%s');
     93SQL
     94    $query->execute;
     95
     96    return scalar $query->fetchrow_array();
     97}
     98
     99###########################################################################
     100#
    84101# Adds the provided interval to the provided time
    85102#
     
    98115###########################################################################
    99116#
     117# Subtracts the provided interval from the provided time
     118#
     119###########################################################################
     120sub subtractInterval {
     121    my ($self, $time, $interval) = @_;
     122
     123      my $query = $self->{_db}->prepare(<<SQL);
     124          SELECT '$time' - INTERVAL $interval;
     125SQL
     126    $query->execute;
     127
     128return scalar $query->fetchrow_array();
     129}
     130
     131###########################################################################
     132#
     133# Formats a date/time string in a way suitable for TIMEDIFF calls
     134#
     135###########################################################################
     136sub formatTimeForDiff {
     137    my ($self, $time) = @_;
     138
     139    if (${$time} =~ m/^[0-9]{4}-[0-9]{2}-[0-9]{2}.*/) {${$time} = $self->getFullDate(${$time});}
     140    elsif(${$time} !~ m/^[0-9]+:[0-9]{2}:[0-9]{2}$/) {return 0;}
     141
     142    return 1;
     143}
     144
     145###########################################################################
     146#
    100147# Finds the difference of two times
     148#
     149# Should be able to handle most date/time formats
    101150#
    102151###########################################################################
     
    104153    my ($self, $time1, $time2) = @_;
    105154
    106       my $query = $self->{_db}->prepare(<<SQL);
     155    if (!$time1 || !$time2) {return 0;}
     156
     157    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
     158
     159    my $query = $self->{_db}->prepare(<<SQL);
    107160         SELECT TIMEDIFF('$time1','$time2');
     161SQL
     162
     163    $query->execute;
     164    return scalar $query->fetchrow_array();
     165}
     166
     167###########################################################################
     168#
     169# Returns the provided time in seconds
     170#
     171###########################################################################
     172sub getTimeInSecs {
     173    my ($self, $time) = @_;
     174
     175    if (!$time) {return 0;}
     176
     177      my $query = $self->{_db}->prepare(<<SQL);
     178         SELECT TIME_TO_SEC('$time');
    108179SQL
    109180
     
    120191    my ($self, $time1, $time2) = @_;
    121192
    122       my $query = $self->{_db}->prepare(<<SQL);
     193    if (!$time1 || !$time2) {return 0;}
     194    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
     195
     196    my $query = $self->{_db}->prepare(<<SQL);
    123197         SELECT TIME_TO_SEC(TIMEDIFF('$time1','$time2'));
    124198SQL
     
    146220###########################################################################
    147221#
    148 # Subtracts the provided interval from the provided time
    149 #
    150 ###########################################################################
    151 sub subtractInterval {
    152     my ($self, $time, $interval) = @_;
    153 
    154       my $query = $self->{_db}->prepare(<<SQL);
    155           SELECT '$time' - INTERVAL $interval;
    156 SQL
    157     $query->execute;
    158 
    159 return scalar $query->fetchrow_array();
    160 }
    161 
    162 ###########################################################################
    163 #
    164222# Returns whether time1 is before time2
    165223#
     
    168226    my ($self, $time1, $time2) = @_;
    169227
    170       my $query = $self->{_db}->prepare(<<SQL);
    171           SELECT '$time1' < '$time2';
    172 SQL
    173     $query->execute;
    174 
    175 return scalar $query->fetchrow_array();
     228    if (!$time1 || !$time2) {return 0;}
     229    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
     230
     231    my $query = $self->{_db}->prepare(<<SQL);
     232    SELECT TIME_TO_SEC(TIMEDIFF('$time1', '$time2'));
     233SQL
     234    $query->execute;
     235
     236    return (scalar $query->fetchrow_array() >= 0) ? 0 : 1;
    176237}
    177238
  • branches/eam_branches/ipp-20101103/tools/czartool/Plotter.pm

    r29618 r29834  
    44use warnings;
    55use strict;
     6
     7use File::Temp;
    68
    79my @allStages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
     
    1618    my $class = shift;
    1719    my $self = {
     20        _gpc1Db => shift,
    1821        _czarDb => shift,
    1922        _dateFormat => shift,
     
    5356}
    5457
     58
     59###########################################################################
     60#
     61# Figures out a suitable interval for rate plots
     62# Could use a function here, but instead we want to choose meaningful intervals
     63#
     64###########################################################################
     65sub getSuitableInterval {
     66    my ($self, $begin, $end, $interval) = @_;
     67
     68    my $timeDiff = $self->{_czarDb}->diffTimes($end, $begin);
     69
     70
     71    if ($self->{_czarDb}->isBefore($timeDiff, "00:00:01")) {return 0;}
     72    elsif ($self->{_czarDb}->isBefore($timeDiff, "03:00:00")) {${$interval} = "15 MINUTE";}
     73    elsif ($self->{_czarDb}->isBefore($timeDiff, "10:00:00")) {${$interval} = "30 MINUTE";}
     74    elsif ($self->{_czarDb}->isBefore($timeDiff, "24:00:00")) {${$interval} = "1 HOUR";} # under 1 day
     75    elsif ($self->{_czarDb}->isBefore($timeDiff, "36:00:00")) {${$interval} = "2 HOUR";} # under 1.5 days
     76    elsif ($self->{_czarDb}->isBefore($timeDiff, "48:00:00")) {${$interval} = "3 HOUR";} # under 2 days
     77    elsif ($self->{_czarDb}->isBefore($timeDiff, "72:00:00")) {${$interval} = "4 HOUR";} # under 3 days
     78    elsif ($self->{_czarDb}->isBefore($timeDiff, "96:00:00")) {${$interval} = "5 HOUR";} # under 4 days
     79    elsif ($self->{_czarDb}->isBefore($timeDiff, "144:00:00")) {${$interval} = "6 HOUR";} # under 6 days
     80    elsif ($self->{_czarDb}->isBefore($timeDiff, "168:00:00")) {${$interval} = "12 HOUR";} # under week
     81    elsif ($self->{_czarDb}->isBefore($timeDiff, "672:00:00")) {${$interval} = "1 DAY";} # under 2 week
     82    elsif ($self->{_czarDb}->isBefore($timeDiff, "2016:00:00")) {${$interval} = "1 WEEK";} # under 3 month
     83    else {${$interval} = "1 MONTH";}
     84
     85    return 1;
     86}
     87
    5588###########################################################################
    5689#
     
    6194    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $isLog) = @_;
    6295
    63     my $minX = 999999999;     
    64     my $maxX = -9999999999;
    65     my $timeDiff = -1;
    66 
     96    # stages
    6797    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 
     98    if (!$selectedStage) {
     99        $stages = \@allStages;
     100        $selectedStage = 'all_stages';
     101    }
     102    else {$stages = ["$selectedStage"]};
     103
     104    # interval
     105    if (!$interval && !$self->getSuitableInterval($beginTime, $endTime, \$interval)) {return 0;}
     106
     107    # set up files
    78108    my %gnuplotFiles;
    79109    my $stage = undef;
     
    89119        "set term $self->{_outputFormat};" .
    90120        "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\"];" .
    96121        "set boxwidth;" .
     122        "set xtic rotate by -90 scale 0;" .
    97123        "set style data histogram;" .
    98124        "set style histogram rowstacked;" .
     
    124150    print GP ";\n";
    125151    close GP;
    126 }                                                   
     152
     153    # now delete temp dat files
     154    foreach my $stage (keys %gnuplotFiles) {unlink($gnuplotFiles{$stage});}
     155
     156    return 1;
     157}
     158
    127159###########################################################################
    128160#
     
    168200    if ($numOfPlots == 0 ) {
    169201
    170         print "Warning: No plots could be generated for stage '$selectedStage' and label '$label' during time period '$beginTime', '$endTime'\n";
     202#        print "Warning: No plots could be generated for stage '$selectedStage' and label '$label' during time period '$beginTime', '$endTime'\n";
    171203        return;
    172204    }
     
    202234    my $outputFile = createImageFileName($self, $label, undef, "h", 0);
    203235
    204     my $inputFile = "/tmp/czarplot_gnuplot_".$label."_h.dat"; # TODO use stage not table
    205         open (GNUDAT, ">$inputFile");
     236    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_".$label."_h.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     237    open (GNUDAT, ">".$tmpFile->filename);
    206238
    207239    my ($processed, $pending, $faults);
    208240    my $stage = undef;
    209241    my $pendingMinusFaults = undef;
    210     my $maxY = 0;
    211     my $sum;
    212242    foreach $stage (@allStages) {
    213243
    214         $self->{_czarDb}->countProcessedPendingAndFaults(
     244        if (!$self->{_czarDb}->countProcessedPendingAndFaults(
    215245                $label,
    216246                $stage,
     
    219249                \$processed,
    220250                \$pending,
    221                 \$faults);
     251                \$faults)) {next;}
    222252
    223253        $pendingMinusFaults = $pending - $faults;
    224         print GNUDAT "$stage $faults $processed, $pendingMinusFaults\n";
    225         my $sum = $faults + $processed + $pendingMinusFaults;
    226         if ($sum > $maxY) {$maxY = $sum;}
     254        print GNUDAT "$stage $faults $processed $pendingMinusFaults\n";
    227255    }
    228256
     
    232260    use FileHandle;
    233261    GP->autoflush(1);
    234 
    235     if ($maxY == 0) {$maxY = 1;}
    236     else {$maxY = $maxY*1.1;}
    237 
    238262
    239263    if ($self->{_outputFormat} ne "X11") {print GP "set output \"$outputFile\";";}
     
    243267        "set grid;" .
    244268        "set boxwidth;" .
    245         "set yrange [\"0\":\"$maxY\"];" .
    246269        "set style data histogram;" .
    247270        "set style histogram rowstacked;" .
     
    249272        "set ylabel \"Exposures\";" .
    250273        "set boxwidth 0.75;" .
    251         "plot '$inputFile' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" .
     274        "plot '".$tmpFile->filename."' using 2:xtic(1) title \"Faults\" lt 1, '' using 3 title \"Processed\" lt 2, '' using 4 title \"Pending\" lt 7;" .
    252275        "\n";
    253276
    254277    close GP;
    255     unlink($inputFile);
    256278}
    257279
     
    295317    my ($self, $timeDiff, $divX, $timeFormat) = @_;
    296318
     319    # if less than a few mins of data, show 1 minute tics
     320    if ($timeDiff < 300) {
     321        ${$timeFormat} = "%H:%M";
     322        ${$divX} = 60;
     323    }
     324    # if less than a few mins of data, show 5 minute tics
     325    elsif ($timeDiff < 1800) {
     326        ${$timeFormat} = "%H:%M";
     327        ${$divX} = 300;
     328    }
     329    # if less than an hour of data, show 15 minute tics
     330    elsif ($timeDiff < 3600) {
     331        ${$timeFormat} = "%H:%M";
     332        ${$divX} = 900;
     333    }
    297334    # if less than a couple of hour's data plotted, show 30 mins tics
    298     if ($timeDiff < 7200) {
     335    elsif ($timeDiff < 7200) {
    299336        ${$timeFormat} = "%H:%M";
    300337        ${$divX} = 1800;
     
    376413
    377414    my $firstIn = 1;
    378     foreach my $stage (keys %$gnuplotFiles) {
     415    # loop through stages array so that they are ordered properly (not maintained in hash)
     416    foreach my $stage (@allStages) {
     417
     418        if(!$gnuplotFiles->{$stage}) {next;}
    379419        if (!$firstIn) {print GP ",";}
    380420
     
    398438
    399439    # now delete temp dat files
    400     foreach my $stage (keys %$gnuplotFiles) {
    401 
    402         unlink($gnuplotFiles->{$stage});
    403     }
     440    foreach my $stage (keys %$gnuplotFiles) {unlink($gnuplotFiles->{$stage});}
    404441}
    405442
     
    416453    my ($minX, $maxX, $minY, $maxY, $timeDiff);
    417454
    418     my $gnuplotFile = $self->{_czarDb}->createStorageTimeSeriesData($fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
     455    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_storage_timeseries.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     456    $self->{_czarDb}->createStorageTimeSeriesData($tmpFile, $fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
    419457
    420458    my $timeFormat = undef;
     
    440478        "set ylabel \"Available (TB)\";" .
    441479        "plot " .
    442         "'$gnuplotFile' using 1:2 title \"Available\" with lines lt 2 lw 2\n";
     480        "'".$tmpFile->filename."' using 1:2 title \"Available\" with lines lt 2 lw 2\n";
    443481
    444482    print GP "\n";
    445483    close GP;
    446     unlink($gnuplotFile);
    447484}
    448485
     
    458495        my $outputFile = "$prefix/czarplot_hosts_space.png";
    459496    my $limit = 97.0;
    460     my $inputFile = $self->{_czarDb}->createHostsData($limit);
     497    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_hosts_space.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     498    $self->{_czarDb}->createHostsData($limit, $tmpFile);
    461499
    462500    my $totalUsed = $self->{_czarDb}->getTotalClusterStorageAsPercentage();
     
    477515        "set ylabel \"Space (TB)\";" .
    478516        "set xtic rotate by -90 scale 0;" .
    479         "plot '$inputFile' " .
     517        "plot '".$tmpFile->filename."' " .
    480518        "using 2:xtic(1) t \"Used\" lt 7," .
    481519        "'' using 3 t \"Over $limit% used\" lt 1," .
     
    489527    close GP;
    490528}
     529
     530###########################################################################
     531#
     532# Generates 3D plot of magic mask fraction for provided exposure ID
     533#
     534###########################################################################
     535sub plotMagicMaskFractionForThisExposure {
     536    my ($self, $exp_id) = @_;
     537
     538    # set up file stuff
     539    my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; # TODO should be function for this
     540        my $outputFile = "$prefix/czarplot_single_exp_magic_mask_fraction.png";
     541    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_single_exp_magic_mask_fraction.XXXXX", DIR => '/tmp', SUFFIX => '.dat');
     542
     543    my $fracs;
     544    if (!$self->{_gpc1Db}->getMagicMaskFraction($exp_id, \$fracs)) {return 0;}
     545
     546    open (GNUDAT, ">".$tmpFile->filename);
     547
     548    print GNUDAT "0 0 0.0\n";
     549    foreach my $row ( @{$fracs} ) {
     550
     551        if (@{$row}[0] =~ m/XY([0-9])([0-9])/) {
     552            print GNUDAT "$1 $2 @{$row}[1]\n";
     553            if($1 == 0 && $2 == 6) {print GNUDAT "0 7 0.0\n";}
     554            if($1 == 6 && $2 == 7) {print GNUDAT "7 0 0.0\n";}
     555        }
     556    }
     557    print GNUDAT "7 7 0.0\n";
     558
     559
     560    close(GNUDAT);
     561
     562
     563    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     564    use FileHandle;
     565    GP->autoflush(1);
     566
     567    my $datFile = $tmpFile->filename;
     568
     569    if ($self->{_outputFormat} ne "X11") {print GP "set output \"$outputFile\";";}
     570    print GP <<PLOT;
     571
     572    set term $self->{_outputFormat}
     573    set title "Magic mask fraction for exposure $exp_id"
     574        set grid
     575        set size square
     576        set xrange [-0.5:7.5] reverse
     577        set yrange [-0.5:7.5] 
     578        unset key
     579        set palette rgb 22,13,10
     580        set ylabel "Y"
     581        set xlabel "X"
     582        set cbrange [0:1]
     583        set datafile missing "NaN"
     584        plot "$datFile" using 1:2:3  with image
     585PLOT
     586
     587    close GP;
     588
     589    return 1;
     590}
     591
     592
     593###########################################################################
     594#
     595# Plots mask fraction histogram for exposures taken between these dates
     596#
     597###########################################################################
     598sub plotMagicMaskFractionHistogram {
     599    my ($self, $begin, $end) = @_;
     600
     601    # get exposures between these dates
     602    my $exp_ids = undef;
     603    if (!$self->{_gpc1Db}->getProcessedExposures($begin, $end, \$exp_ids)) {return 0;}
     604    my $totalExp = @{$exp_ids};
     605    if ($totalExp < 1) {return 0;}
     606
     607    # set up file stuff
     608    my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; # TODO should be function for this
     609        my $histoOutputFile = "$prefix/czarplot_magic_mask_fraction_h.png";
     610    my $distOutputFile = "$prefix/czarplot_magic_mask_fraction_d.png";
     611    my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_magic_mask_fraction.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
     612
     613    # set up bins
     614    my %histogram;
     615    my @bins;
     616    my $interval = 0.05;
     617    my $min = 1.0;
     618    my $max = 1.0;
     619    for (my $n=0.0; $n<$max; $n += $interval){
     620
     621        push(@bins, $n);
     622        $histogram{$n} = 0;
     623    }
     624
     625    # get mask for each exposure, and bin
     626    my $mask = undef;
     627    my $expCount = 0;
     628    foreach my $row ( @{$exp_ids} ) {
     629
     630        $mask = $self->{_gpc1Db}->getAverageMagicMaskFraction(@{$row}[0]);
     631
     632        if (!$mask) {next;}
     633        $expCount++;
     634
     635        foreach my $bin (@bins) {
     636            if ($mask <= ($bin+$interval)) {
     637
     638                $histogram{$bin}++;
     639                last;
     640            }
     641        }
     642    }
     643
     644    # write data to GNUPLOT data file
     645    print "* Found mask values for $expCount exposures out of $totalExp\n";
     646    open (GNUDAT, ">".$tmpFile->filename);
     647    my $accum = 0;
     648    my $maxBin = 0;
     649    foreach my $bin (@bins) {
     650
     651        $accum += $histogram{$bin};
     652        if ($histogram{$bin} > $maxBin) {$maxBin = $histogram{$bin};}
     653        print GNUDAT "$bin $histogram{$bin} $accum\n";
     654    }
     655    close(GNUDAT);
     656
     657    # now plot
     658    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     659    use FileHandle;
     660    GP->autoflush(1);
     661
     662    $maxBin = $maxBin * 1.1;
     663    $accum = $accum * 1.1;
     664
     665    if ($self->{_outputFormat} ne "X11") {print GP "set output \"$histoOutputFile\";";}
     666    print GP
     667        "set term $self->{_outputFormat};" .
     668        "set title \"Magic mask fraction for $expCount exposures between '$begin' and '$end'\";" .
     669        "set grid;" .
     670        "set boxwidth;" .
     671        "set style data histogram;" .
     672        "set yrange [0:$maxBin];" .
     673        "set style histogram rowstacked;" .
     674        "set style fill solid border -1;" .
     675        "set ylabel \"Number of Exposures\";" .
     676        "set xlabel \"Magic Mask Fraction\";" .
     677        "set boxwidth 0.75;" .
     678        "set xtic rotate by -90 scale 0;" .
     679        "plot '".$tmpFile->filename."' using 2:xtic(1) notitle lt 1;" .
     680        "\n";
     681
     682    close GP;
     683
     684
     685    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     686    use FileHandle;
     687    GP->autoflush(1);
     688
     689    if ($self->{_outputFormat} ne "X11") {print GP "set output \"$distOutputFile\";";}
     690    print GP
     691        "set term $self->{_outputFormat};" .
     692        "set title \"Cumulative distribution of magic streaks per image between '$begin' and '$end'\";" .
     693        "set yrange [0:$accum];" .
     694        "set key left top;" .
     695        "set grid xtics;" .
     696        "set xlabel \"Magic Mask Fraction\";" .
     697        "set ylabel \"Number of Exposures\";" .
     698        "set xtic rotate by -90 scale 0;" .
     699        "plot " .
     700        "'".$tmpFile->filename."' using 1:3 notitle with lines lt 2 lw 2\n";
     701
     702    print GP "\n";
     703    close GP;
     704
     705    return 1;
     706}
    4917071;
  • branches/eam_branches/ipp-20101103/tools/roboczar.pl

    r29581 r29834  
    1313use czartool::Plotter;
    1414use czartool::Burntool;
     15use czartool::StageMetrics;
    1516
    1617my $czarDbName = "czardb"; # TODO variables for other Db stuff, host etc
     
    5657
    5758        sendEmail(
    58                 "roydhenderson\@gmail.com",
     59                "ps-ipp-ops\@ifa.hawaii.edu",
    5960                "Roboczar warnings",
    6061                "$message\n");
     
    8990    my $stage;
    9091    foreach $stage (@stages) {
    91         my ($started, $finished, $stuck, $processed, $pending, $faults, $totalTime);
    92         $czarDb->runAnalysis(
    93                 "all_stdscience_labels",
    94                 $stage,
    95                 $begin,
    96                 $end,
    97                 \$started,
    98                 \$finished,
    99                 \$stuck,
    100                 \$processed,
    101                 \$pending,
    102                 \$faults,
    103                 \$totalTime);
    10492
    105         print "*     $stage $end $begin:\n";
    106         if (defined $started) {print "* Processing started at $started\n";}
    107         if (defined $finished) {print "* Processing finished at $finished and took $totalTime\n";}
    108         else {print "* Processing has not finished\n";}
    109         if (defined $stuck) {print "* Processing has been stuck since $stuck\n";}
    110         print "* $processed exposures have been processed, with $pending pending and $faults faults\n";
     93    my $stageMetrics = new czartool::StageMetrics($stage, "all_stdscience_labels", $begin, $end);
    11194
    112         print "*******************************************************************************\n";
     95    if ($czarDb->runAnalysis($stageMetrics)) {$stageMetrics->printMe();}
    11396
    114         if ($stuck && $stage eq "burntool" && !$worryAboutBurntool) {next;}
     97        if ($stageMetrics->getStuck() && $stage eq "burntool" && !$worryAboutBurntool) {next;}
    11598
    116         if ($stuck) {
     99        if ($stageMetrics->getStuck()) {
    117100       
    118             ${$message} = ${$message} ."\n - '$stage' is stuck with $pending pending exposures (and $faults faults)";
     101            ${$message} = ${$message} ."\n - '$stage' is stuck with ".$stageMetrics->getFinalPending()." pending exposures (and ".$stageMetrics->getFaults()." faults)";
    119102            $anyStuckStages = 1;
    120103        }
  • branches/eam_branches/ipp-20101103/tools/runchipimfile.pl

    r29586 r29834  
    3838
    3939my $query1 = "SELECT chipProcessedImfile.path_base, camera, exp_id, rawImfile.magicked AS raw_magicked, (rawImfile.user_1 is not NULL and rawImfile.user_1 > 0.5)  As deburned, chip_imfile_id, chipProcessedImfile.fault, rawImfile.uri, chipRun.reduction, chipRun.state";
    40 $query1 .= " FROM chipRun join chipProcessedImfile using(chip_id) JOIN chipImfile USING (chip_id, class_id) JOIN rawExp using(exp_id) JOIN rawImfile USING(exp_id) WHERE chip_id = $chip_id AND class_id = $class_id";
     40$query1 .= " FROM chipRun join chipProcessedImfile using(chip_id,exp_id) JOIN chipImfile USING (chip_id, class_id) JOIN rawExp using(exp_id) JOIN rawImfile USING(exp_id, camera, class_id) WHERE chip_id = $chip_id AND class_id = '$class_id'";
    4141
    4242my $stmt1 = $dbh->prepare($query1);
     
    5555my $exp_id = $results->{exp_id};
    5656
    57 notdone
    58 
    5957die "cannot update database for a chip that is not faulted\n" if $update and !$fault;
    6058
     
    6967    $run_state = 'new';
    7068} elsif ($state eq 'update') {
    71     $state = 'update';
     69    $run_state = 'update';
    7270} else {
    73     die "unexpected warpRun.state found: $state\n";
     71    die "unexpected chipRun.state found: $state\n";
    7472}
    7573
    76 my $command = "chip_imfile.pl --exp_id $exp_id --chip_id $chip_id --class_id $class_id --chip_imfile_id $chip_imfile_id --uri $uri --camera $camera --run-state $run_state --deburned $deburned --outroot $path_base" ;
     74my $command = "chip_imfile.pl --exp_id $exp_id --chip_id $chip_id --chip_imfile_id $chip_imfile_id --class_id $class_id --uri $uri --camera $camera --run-state $run_state --deburned $deburned --outroot $path_base" ;
    7775
    7876$command .= " --magicked $magicked" if $magicked > 0;
     
    8381$command .= " --verbose" unless $no_verbose;
    8482$command .= " --dbname $dbname" if $dbname;
    85 
    8683
    8784if ($update) {
Note: See TracChangeset for help on using the changeset viewer.