IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28719


Ignore:
Timestamp:
Jul 27, 2010, 2:42:17 PM (16 years ago)
Author:
rhenders
Message:

Loads of stuff

Location:
trunk/tools
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czarplot.pl

    r28714 r28719  
    55
    66use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    7 use File::Temp qw(tempfile);
    87use POSIX qw/strftime/;
    98
    109use czartool::CzarDb;
    11 use czartool::Gnuplot;
    12 
     10use czartool::Czarplot;
    1311
    1412my $czarDbName = "czardb";
     
    1917my $begin = undef;
    2018my $end = undef;
     19my $path = undef;
    2120my $verbose = undef;
    2221my $histogram = undef;
    2322my $timeSeries = undef;
     23my $savingToFile = undef;
    2424
    2525GetOptions (
     
    3030        "begin|b=s" => \$begin,
    3131        "end|e=s" => \$end,
     32        "output|o=s" => \$path,
    3233        "histogram|h" => \$histogram,
    3334        "timeseries|t" => \$timeSeries,
     
    3738print "\n";
    3839if (!$histogram) {
    39     print "* OPTIONAL: plot histogram                  -h                          (default=on)\n";
    40 }
     40    print "* OPTIONAL: plot histogram                  -h                          (default=off)\n";}
    4141if (!$timeSeries) {
    42     print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";
    43 }
     42    print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";}
    4443if (!$label) {
    45     print "* OPTIONAL: choose a label                  -l <labellName>             (default='all_labels')\n";
    46 }
     44    print "* OPTIONAL: choose a label                  -l <labellName>             (default='all_labels')\n";}
    4745if (!$stage) {
    48     print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";
    49 }
     46    print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";}
    5047if (!$interval) {
    51     print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=interval since 7am this morning)\n";
    52 }
     48    print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=interval since 7am this morning)\n";}
    5349if (!$begin) {
    54     print "* OPTIONAL: choose a begin time             -d <datetime>               (default=7am this morning)\n";
    55 }
     50    print "* OPTIONAL: choose a begin time             -d <datetime>               (default=7am this morning)\n";}
    5651if (!$end) {
    57     print "* OPTIONAL: choose an end time              -e <datetime>               (default=now)\n";
    58 }
     52    print "* OPTIONAL: choose an end time              -e <datetime>               (default=now)\n";}
     53if (!$path) {
     54    print "* OPTIONAL: choose an output location       -o <path>                   (default=none)\n";}
    5955
    6056print "\n";
     
    6258# default values
    6359if (!$label) {$label = "all_labels";}
    64 if (!$histogram && !$timeSeries) {$timeSeries = 1;}
     60if (!$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 1;}
    6561if (!$verbose) {$verbose = 0;}
    6662if (!$save_temps) {$save_temps = 0;}
     63if (!$path) {$savingToFile = 0; $path = ".";}
     64else {$savingToFile = 1;}
    6765
    6866my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose);
    69 my $gnuplot = new czartool::Gnuplot("%Y%m%d-%H%M%S", "X11", "histo.pbm");
    7067$czarDb->setDateFormat("%Y%m%d-%H%i%s");
     68
     69my $czarplot = new czartool::Czarplot($czarDb, "%Y%m%d-%H%M%S", $savingToFile ? "png" : "X11", $path, $save_temps);
    7170
    7271my @allStages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
     
    7978}
    8079
    81 if ($histogram) {plotHistogram($label, $begin, $end);}
    82 if ($timeSeries) {plotTimeSeries($label, $stage, $begin, $end); }
     80if ($timeSeries) {$czarplot->createTimeSeries($label, $stage, $begin, $end);}
     81if ($histogram) {$czarplot->createHistogram($label, $begin, $end);}
    8382
    84 ###########################################################################
    85 #
    86 # Plots a time series for all stages for this label
    87 #
    88 ###########################################################################
    89 sub plotTimeSeries {
    90     my ($label, $selectedStage, $beginTime, $endTime) = @_;
    91 
    92     my ($minX, $maxX, $minY, $maxY, $timeDiff);
    93     $minX = 999999999;
    94     $maxX = -9999999999;
    95     $minY = 999999999;
    96     $maxY = -99999999;
    97 
    98     my $stages = undef;
    99 
    100     if (!$selectedStage) {$stages = \@allStages;}
    101     else {$stages = ["$selectedStage"]};
    102 
    103     my %gnuplotFiles;
    104     foreach $stage (@{$stages}) {
    105         $gnuplotFiles{$stage} = $czarDb->createTimeSeriesData($save_temps, $label, $stage, $beginTime, $endTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
    106     }
    107 
    108     if (!$selectedStage) {$gnuplot->plotAllStagesTimeSeries($label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff, \%gnuplotFiles);}
    109     else {$gnuplot->plotSingleTimeSeries($gnuplotFiles{$selectedStage}, $selectedStage, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff);}
    110 
    111 }
    112 
    113 ###########################################################################
    114 #
    115 # Plots a histogram of stuff processed in provided interval and label for all stages
    116 #
    117 ###########################################################################
    118 sub plotHistogram {
    119     my ($label, $beginTime, $endTime) = @_;
    120 
    121     my ($tempFile, $filePath) = tempfile( "/tmp/czartool_gnuplot_histogram.XXXX", UNLINK => !$save_temps);
    122     my ($processed, $pending, $faults);
    123 
    124     foreach $stage (@allStages) {
    125 
    126         $czarDb->countProcessedPendingAndFaults($label, $stage, $beginTime, $endTime, \$processed, \$pending, \$faults);
    127         print $tempFile "$stage $processed, $pending, $faults\n";
    128     }
    129 
    130     close($tempFile);
    131 
    132     $gnuplot->plotHistogram($filePath, $label, $beginTime, $endTime);
    133 }
    134 
    135 
    136 
  • trunk/tools/czartool/CzarDb.pm

    r28715 r28719  
    7272       $query->execute;
    7373}
     74
     75###########################################################################
     76#
     77# Sets priority for this label
     78#
     79###########################################################################
     80sub setLabelPriority {
     81    my ($self, $label, $priority) = @_;
     82
     83    my $query = $self->{_db}->prepare(<<SQL);
     84     UPDATE current_labels
     85         SET priority = $priority
     86         WHERE label LIKE '$label'
     87         AND server LIKE 'stdscience';
     88SQL
     89
     90    $query->execute;
     91}
     92
    7493###########################################################################
    7594#
     
    7998sub updateCurrentLabels {
    8099    my ($self, $server, $labels) = @_;
     100
     101    my $size = scalar @{$labels};
     102    if ($size < 1) {return;}
    81103
    82104    my $query = $self->{_db}->prepare(<<SQL);
     
    181203
    182204        my ($timestamp, $pending, $faults, $processed) = @row;
     205    #    print  "'$timestamp' '$pending' '$faults' '$processed'\n";
    183206        print $tempFile "$timestamp $pending $faults $processed\n";
    184207    }
     
    298321
    299322    my $currentRevision = -1;
    300     my $latestRevision = 6;
     323    my $latestRevision = 7;
    301324
    302325    while ($currentRevision != $latestRevision) {
     
    311334        elsif ($currentRevision == 4) {$self->createRevision_5();}
    312335        elsif ($currentRevision == 5) {$self->createRevision_6();}
     336        elsif ($currentRevision == 6) {$self->createRevision_7();}
    313337    }
    314338}
     
    476500#######################################################################################
    477501#
     502# Create revision 7 of the database
     503#
     504#######################################################################################
     505sub createRevision_7 {
     506    my ($self) = @_;
     507
     508    print "* Creating revision 7 of '$self->{_dbName}'\n";
     509
     510    my $query = $self->{_db}->prepare(<<SQL);
     511    ALTER TABLE current_labels
     512        ADD COLUMN priority INT NOT NULL DEFAULT 0;
     513SQL
     514
     515    $query->execute;
     516
     517    $self->setRevision(7);
     518}
     519
     520#######################################################################################
     521#
    478522# Sets current revision of ippToPsps database
    479523#
  • trunk/tools/czartool/Gpc1Db.pm

    r28704 r28719  
    7373###########################################################################
    7474#
     75# Returns priority for this label
     76#
     77###########################################################################
     78sub getPriority {
     79    my ($self, $label) = @_;
     80
     81    my $query = $self->{_db}->prepare(<<SQL);
     82    SELECT priority
     83        FROM Label
     84        WHERE label LIKE '$label'
     85SQL
     86
     87        $query->execute;
     88    my $priority = scalar $query->fetchrow_array();
     89    if (!$priority) {return 50000;} # assume labels not given priority in gpc1 Db have highest priority
     90    return $priority;
     91}
     92
     93###########################################################################
     94#
    7595# Returns count of exposures with this state for this label
    7696#
  • trunk/tools/roboczar.pl

    r28715 r28719  
    44use strict;
    55use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     6use POSIX qw/strftime/;
    67
    78# local classes
     
    910use czartool::Gpc1Db;
    1011use czartool::Pantasks;
     12use czartool::Czarplot;
    1113
    1214
    1315my $period = 60;
    1416my $czarDbName = "czardb"; # TODO variables for other Db stuff, host etc
    15 my $save_temps = 1;
     17my $save_temps = 0;
    1618
    1719my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp");
    1820my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
    1921my $pantasks = new czartool::Pantasks();
     22my $czarplot = new czartool::Czarplot($czarDb, "%Y%m%d-%H%M%S", "png", "~/", $save_temps);
     23$czarDb->setDateFormat("%Y%m%d-%H%i%s");
     24
    2025my @stages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
    2126
     
    7984    my $full;
    8085    my $faults;
    81     my $currentTime;
    8286    my $stage;
    8387    my ($totalNew,$totalFull,$totalFaults);
     
    8892    my $rows = undef;
    8993    my $row = undef;
     94    my $begin = undef;
     95    my $end = undef;
     96    my $priority = undef;
    9097
    9198    while (1) {
     
    94101        updateLabels();
    95102        if (!$czarDb->getCurrentLabels("stdscience", \$rows)) {next;}
     103
     104        my $size = @{$rows};
     105        if($size < 1) {
     106           
     107            print "* WARNING: no stdscience labels found in Db\n";
     108            next;
     109        }
     110
     111        # get priority
     112        foreach $row ( @{$rows} ) {
     113            my ($label) = @{$row};
     114            $priority = $gpc1Db->getPriority($label);
     115            $czarDb->setLabelPriority($label, $priority);
     116        }
     117
     118        # sort out times
     119        $begin =  strftime('%Y-%m-%d 07:00',localtime);
     120        $end = $czarDb->getNowTimestamp();
    96121
    97122        foreach $stage (@stages) {
     
    112137                $full = $gpc1Db->countExposures($label, $stage, "full");
    113138                $faults = $gpc1Db->countFaults($label, $stage);
    114                 $currentTime = time();
    115139
    116140                #printf("%ld, %s, %s, %d, %d\n", $currentTime, $label, $stage, $new, $faults);
     
    125149        }
    126150
     151        print "* Generating plots\n";
    127152        foreach $row ( @{$rows} ) {
    128153            my ($label) = @{$row};
     154
     155            $czarplot->createTimeSeries($label, undef, $begin, $end);
     156            $czarplot->createHistogram($label, $begin, $end);
     157
    129158            #routineChecks($label, "1 HOUR");
    130159        }
     160            $czarplot->createTimeSeries("all_labels", undef, $begin, $end);
     161            $czarplot->createHistogram("all_labels", $begin, $end);
    131162        print "--------------------------------------------------------------------------\n";
    132163        print "* Going to sleep\n";
Note: See TracChangeset for help on using the changeset viewer.