-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
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];
$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);
} 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 {
my $htdocsDumpDir = shift;
my $quietParam = shift;
my $endpointParam = shift;
+ my $logParam = shift;
+
# Start Webserver
print "\n\nStart Webserver. Navigate to http://$host:$port\n";
# 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";
# 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
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,
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";
# 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;
}
# 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;
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 = ();
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();
@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'},
'-'
];
- 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);
}
}
- unless ($quiet) {
+ unless ($config->{'quiet'}) {
printTable $tab;
print "\n";
}
}
}
- 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;
] 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];
}
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);
}
}