]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
Logging option added to CTS monitor
authorManuel Penschuck <manuel.penschuck@stud.uni-frankfurt.de>
Wed, 31 Jul 2013 10:41:53 +0000 (12:41 +0200)
committerManuel Penschuck <manuel.penschuck@stud.uni-frankfurt.de>
Wed, 31 Jul 2013 10:41:53 +0000 (12:41 +0200)
web/cts
web/cts_gui
web/include/CtsCommands.pm

diff --git a/web/cts b/web/cts
index d303bd2fc06e291066917762b793ca7696011795..c104f3db6ee004d62a758eca02dc82f23d865bed 100755 (executable)
--- a/web/cts
+++ b/web/cts
@@ -48,7 +48,12 @@ Options:
    -e | --endpoint  Endpoint number of CTS
    -s | --sim       Simulate TrbNet
    -i | --interval  Interval of rate monitoring in milliseconds. Default: 1000
-   -q | --quiet     Prevent monitor from writing values to stdout            
+   -q | --quiet     Prevent monitor from writing values to stdout
+   -l | --log       [interval,]path-to-log-file
+                    Applicable only in monitoring mode, this option enables
+                    logging of the trigger rates into an cvs file. Example:
+                    cts -l 2,/dev/shm/cts-log m  
+                    Will write a message every 3 monitoring cycles (i.e. skip 2)
    
 Commands:
    l | list         Connect to CTS and list all named registers available
@@ -91,8 +96,9 @@ sub connectToCTS {
 my $endpoint = CtsConfig->getDefaultEndpoint;
 
 my $updateInterval = 1000;
-my $rateNumber     = 30;
 my $quiet = 0;
+my $logPath = "";
+my $logSkip = 1;
 
 for(my $i=0; $i < @ARGV; $i++) {
    my $arg = $ARGV[$i];
@@ -135,12 +141,18 @@ for(my $i=0; $i < @ARGV; $i++) {
       $quiet = 1;
       
    } elsif ($arg eq "-n") {
+      print "Support for the -n Option discontinued";
+      
+   } elsif ($arg eq "-l" or $arg eq "--log") {
       unless ($i < @ARGV) {
          print "last parameter expects value\n";
          exit();
       }
       
-      $rateNumber = $ARGV[++$i];
+      my @tmp = split /,/, $ARGV[++$i], 2;
+      $logPath = pop @tmp;
+      $logSkip = pop @tmp;
+      $logSkip = 0 if (not defined $logSkip or $logSkip < 0);
    
    } elsif ($arg eq "l" or $arg eq "list") {
       printTable commandList connectToCTS($endpoint);
@@ -172,7 +184,12 @@ for(my $i=0; $i < @ARGV; $i++) {
    
    } elsif ($arg eq "m" or $arg eq "monitor") {
       my $cts = connectToCTS($endpoint);
-      commandMonitor($cts, $ARGV[++$i], $updateInterval, $rateNumber, $quiet);
+      commandMonitor($cts, {
+         'dump_dir' => $ARGV[++$i],
+         'interval' => $updateInterval,
+         'quiet'    => $quiet,
+         'log_path' => $logPath,
+         'log_skip' => $logSkip});
       exit();
       
    } else {
index 8eb54b194c5bffa19e80cd3298c91876104c143f..c5b3e86357125e2e6a0031bf7c568f9c838a7622 100755 (executable)
@@ -14,6 +14,8 @@ sub execServerAndMonitor {
    my $htdocsDumpDir = shift;
    my $quietParam = shift;
    my $endpointParam = shift;
+   my $logParam = shift;
+   
 
 # Start Webserver
    print "\n\nStart Webserver. Navigate to http://$host:$port\n";
@@ -27,7 +29,7 @@ sub execServerAndMonitor {
    
 # Exec Monitor   
    while(1) {
-      system "./cts $quietParam $endpointParam  m $htdocsDumpDir";
+      system "./cts $quietParam $endpointParam $logParam m $htdocsDumpDir";
       #system "clear";
       print "\n\n\nIf you willingly killed the monitoring script press CTRL+C again! \n\n\n\n\n\n\n\n\n";
       
@@ -41,9 +43,11 @@ sub execServerAndMonitor {
 # Print help
 sub help {
    print <<EOFHELP;
-$0 [--port=1234] [--[no]openxterm] [--endpoint=0x....] [--help]
+$0 [--port=1234] [--[no]openxterm] [--endpoint=0x....] [--log=[skip,]path] [--help]
 Setups up running enviroment for the CTS gui and start webserver.
 
+--log          Log trigger rates into file specified. If "Number," is prefixed,
+               the stated number of monitoring cycles is skipped between each write.
 --quiet        Don't print monitored values to stdout
 --port         Port number of the webserver
 --noopenxterm  By default, the CTS monitoring results are displayed in an
@@ -64,10 +68,12 @@ EOFHELP
    my $help = 0;
    my $quiet = 0;
    my $endpoint = undef;
+   my $log = undef;
 
    GetOptions(
       'openxterm!' => \$openxterm,
       'endpoint=s' => \$endpoint,
+      'log=s' => \$log,
       'port=i' => \$port,
       'monitor!' => \$monitor,
       'help!' => \$help,
@@ -93,7 +99,7 @@ EOFHELP
    my $sharedDir     = "/dev/shm/cts-monitor-$port";
    my $htdocsDumpDir = "htdocs/monitor-$port";
    my $quietParam    = $quiet ? '--quiet ' : '';
-   
+   my $logParam      = $log ? "--log $log" : '';
 
    sub clean_up {
       print "\n\n\n CLEAN UP\n";
@@ -103,7 +109,7 @@ EOFHELP
    
 # If this script was started within xterm - start monitor  
    if ($monitor) {
-      execServerAndMonitor $host, $port, $htdocsDumpDir, $quietParam, $endpointParam;
+      execServerAndMonitor $host, $port, $htdocsDumpDir, $quietParam, $endpointParam, $logParam;
       exit;
    }
 
@@ -126,9 +132,9 @@ EOFHELP
 # Start Monitor (either directly or indirectly via XTERM)"
    print "\n\nStart monitoring script";
    if ($openxterm) {
-      system("xterm -fn '-misc-fixed-medium-r-normal--8-*-*-*-*-*-iso8859-15' +sb -geometry 200x100 +aw +bc -bg LightCoral -j -e '$0 --monitor --port=$port $quietParam $endpointParam'");
+      system("xterm -fn '-misc-fixed-medium-r-normal--8-*-*-*-*-*-iso8859-15' +sb -geometry 200x100 +aw +bc -bg LightCoral -j -e '$0 --monitor --port=$port $quietParam $endpointParam $logParam'");
    } else {
-      execServerAndMonitor $host, $port, $htdocsDumpDir, $quietParam, $endpointParam;
+      execServerAndMonitor $host, $port, $htdocsDumpDir, $quietParam, $endpointParam, $logParam;
    }
    
    clean_up;
index 00afc09165d6d2d59ba1043d4e5ce124534b15f2..e51e4e819dc0af2df3be3c7a1f65cc3692d7f221 100644 (file)
@@ -279,12 +279,16 @@ sub commandWrite {
    print "Done.\n";
 }
 
+# commandMonitor $cts $config
+# where $config is a hash-reference with the following properties
+#   dump_dir     Empty, or path to directory in which all results are to
+#   interval     Time between two monitoring cycles in milliseconds 
+#   quite        If True the output to stdout is strongly reduced
+#   log_path     Path to a cvs file in which current rate is dumped
+#   log_skip     Number of monitoring cycles to be skipped between two file accesses 
 sub commandMonitor {
    my $cts = shift;
-   my $filename = shift;
-   my $interval = shift;
-   my $rateNumber = shift;
-   my $quiet = shift;
+   my $config = shift;
    
    my $trb = $cts->getTrb;
    my @rateRegs = ();
@@ -292,7 +296,10 @@ sub commandMonitor {
    
    my @monRegs = ();
    
-   local $| = 1 if $quiet;
+   
+   my $logSkipCounter = 1;
+   
+   local $| = 1 if $config->{'quiet'};
 
 # gather all registers and slices that need to be monitored
    $trb->clearPrefetch();
@@ -323,8 +330,8 @@ sub commandMonitor {
    @rateRegs = sort @rateRegs;
    
 # write enumration + enviroment into cache
-   if ($filename) {
-      open FH, ">$filename/enum.js";
+   if ($config->{'dump_dir'}) {
+      open FH, ">$config->{'dump_dir'}/enum.js";
       print FH JSON_BIND->new->encode({
          'endpoint'  => sprintf("0x%04x", $trb->getEndpoint()),
          'daqop'     => $ENV{'DAQOPSERVER'},
@@ -368,7 +375,8 @@ EOF
          '-'
       ];
       
-      print chr(27) . "[1;1H" . chr(27) . "[2J" unless $quiet;
+      # clear screen
+      print chr(27) . "[1;1H" . chr(27) . "[2J" unless $config->{'quiet'};
    
       my $read = {};
       $trb->prefetch(1);
@@ -401,7 +409,7 @@ EOF
          }
       }
 
-      unless ($quiet) {
+      unless ($config->{'quiet'}) {
          printTable $tab;
          print "\n";
       }
@@ -451,20 +459,20 @@ EOF
          }
       }
       
-      printTable $tab unless $quiet;
+      printTable $tab unless $config->{'quiet'};
       
-      if ($filename) {
+      if ($config->{'dump_dir'}) {
       # store json
          my $json = JSON_BIND->new->encode({
             'time' => $time,
             'servertime' => time2str('%Y-%m-%d %H:%M', time),
-            'interval' => $interval,
+            'interval' => $config->{'interval'},
             'endpoint' => $trb->getEndpoint,
             'rates' => $rates,
             'monitor' => $monData
          });
 
-         open FH, ">$filename/dump.js";
+         open FH, ">$config->{'dump_dir'}/dump.js";
          print FH $json;
          close FH;
 
@@ -479,7 +487,7 @@ EOF
             ] if $rates->{'cts_cnt_trg_asserted.value'};
 
             if ($#{ $plotData } > 4) {
-               open FH, ">$filename/plot.data";
+               open FH, ">$config->{'dump_dir'}/plot.data";
                foreach (@{$plotData}) {
                   my @row = (@{ $_ });
                   $row[0] -= $plotData->[-1][0];
@@ -487,35 +495,54 @@ EOF
                }
                close FH;
 
+               # First plot into a different file and the issue a move command,
+               # in order to reduce the number of accesses from the webserver to
+               # a corrupt image file (works quite well !)
                print $gnuplot_fh <<"EOF"
 set xrange [*:0]
-set output "$filename/_tmp_plot.png"
+set output "$config->{'dump_dir'}/_tmp_plot.png"
 plot \\
-"$filename/plot.data" using 1:3:(\$3 / 1000) with yerrorlines title "Edges", \\
-"$filename/plot.data" using 1:4:(\$4 / 1000) with yerrorlines title "Accepted"
+"$config->{'dump_dir'}/plot.data" using 1:3:(\$3 / 1000) with yerrorlines title "Edges", \\
+"$config->{'dump_dir'}/plot.data" using 1:4:(\$4 / 1000) with yerrorlines title "Accepted"
 
 set xrange [-5:0]
-set output "$filename/_tmp_plotshort.png"
+set output "$config->{'dump_dir'}/_tmp_plotshort.png"
 plot \\
-"$filename/plot.data" using 1:3:(\$3 / 1000) with yerrorlines title "Edges", \\
-"$filename/plot.data" using 1:4:(\$4 / 1000) with yerrorlines title "Accepted"
+"$config->{'dump_dir'}/plot.data" using 1:3:(\$3 / 1000) with yerrorlines title "Edges", \\
+"$config->{'dump_dir'}/plot.data" using 1:4:(\$4 / 1000) with yerrorlines title "Accepted"
 
 EOF
 ;
+               rename "$config->{'dump_dir'}/_tmp_plot.png",      "$config->{'dump_dir'}/plot.png";
+               rename "$config->{'dump_dir'}/_tmp_plotshort.png", "$config->{'dump_dir'}/plotshort.png";
 
-               rename "$filename/_tmp_plot.png",      "$filename/plot.png";
-               rename "$filename/_tmp_plotshort.png", "$filename/plotshort.png";
-               
-
-               print ($quiet ? "." : "Plot produced\n");
+               print ($config->{'quiet'} ? "." : "Plot produced\n");
             } else {
                print "Plotting delayed as too few points captured yet\n";
             }
          }
       }
       
+      if (0 == $logSkipCounter and $config->{'log_path'}) {
+         my $new_file = not (-e $config->{'log_path'});  # True if log file does not exists (yet)
+         my $log_fh = new FileHandle (">>$config->{'log_path'}");
+         if ($log_fh) {
+            print $log_fh "Timestamp,Trigger Asserted,Trigger Rising Edges,Trigger Accepted\n" if $new_file;
+            print $log_fh sprintf("%d,%.1f,%.1f,%.1f\n", 
+               scalar time,
+               $rates->{'cts_cnt_trg_asserted.value'}{'rate'},
+               $rates->{'cts_cnt_trg_edges.value'}{'rate'},
+               $rates->{'cts_cnt_trg_accepted.value'}{'rate'}
+            );
+         }
+         close $log_fh;
+         $logSkipCounter = $config->{'log_skip'};
+      } else {
+         $logSkipCounter--;
+      }
+      
       $lastRead = $read;
-      usleep($interval*1e3);
+      usleep($config->{'interval'}*1e3);
    }
 }