зеркало из https://github.com/mozilla/gecko-dev.git
First attempt at generalizing graph.cgi and collect.cgi
This commit is contained in:
Родитель
16e4f2d4d9
Коммит
1920fcaacd
|
@ -0,0 +1 @@
|
|||
db
|
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/perl
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
use CGI::Request;
|
||||
use POSIX qw(strftime);
|
||||
use strict;
|
||||
|
||||
my $req = new CGI::Request;
|
||||
|
||||
# incoming query string has the form: "?value=n&data=p:q:r...&tbox=foopy"
|
||||
# where 'n' is the average recorded time, and p,q,r... are the raw numbers,
|
||||
# and 'tbox' is a name of a tinderbox
|
||||
|
||||
use vars qw{$value $data $tbox $testname $ua $ip $time};
|
||||
$value = $req->param('value');
|
||||
$data = $req->param('data');
|
||||
$tbox = $req->param('tbox'); $tbox =~ tr/A-Z/a-z/;
|
||||
$testname = $req->param('testname');
|
||||
$ua = $req->cgi->var("HTTP_USER_AGENT");
|
||||
$ip = $req->cgi->var("REMOTE_ADDR");
|
||||
$time = strftime "%Y:%m:%d:%H:%M:%S", localtime;
|
||||
|
||||
#$value = "1234"; # $req->param('value');
|
||||
#$data = "1:2:3:4"; #$req->param('data');
|
||||
#$tbox = "coffee"; #$tbox =~ tr/A-Z/a-z/;
|
||||
#$testname = "startup"; #$req->param('testname');
|
||||
#$ua = "ua"; #$req->cgi->var("HTTP_USER_AGENT");
|
||||
#$ip = "1.2.3.4"; #$req->cgi->var("REMOTE_ADDR");
|
||||
#$time = "now"; #strftime "%Y:%m:%d:%H:%M:%S", localtime;
|
||||
|
||||
|
||||
print "Content-type: text/plain\n\n";
|
||||
for (qw{value data tbox testname ua ip time}) {
|
||||
no strict 'refs';
|
||||
printf "%10s = %s\n", $_, $$_;
|
||||
}
|
||||
|
||||
# close HTTP transaction, and then decide whether to record data
|
||||
#close(STDOUT);
|
||||
|
||||
#my %nametable = read_config();
|
||||
|
||||
# punt fake inputs
|
||||
#die "Yer a liar"
|
||||
# unless $ip eq $nametable{$tbox} or $ip eq '208.12.39.125';
|
||||
#die "No 'real' browsers allowed: $ua"
|
||||
# unless $ua =~ /^(libwww-perl|PERL_CGI_BASE)/;
|
||||
die "No 'value' parameter supplied"
|
||||
unless $value;
|
||||
die "No 'testname' parameter supplied"
|
||||
unless $testname;
|
||||
die "No 'tbox' parameter supplied"
|
||||
unless $tbox;
|
||||
die "No 'data' parameter supplied"
|
||||
unless $data;
|
||||
|
||||
|
||||
# Test for dirs.
|
||||
unless (-d "db") {
|
||||
mkdir("db");
|
||||
}
|
||||
|
||||
|
||||
unless (-d "db/$testname") {
|
||||
mkdir("db/$testname");
|
||||
}
|
||||
|
||||
# If file doesn't exist, try creating empty file.
|
||||
unless (-f "db/$testname/$tbox") {
|
||||
open(FILE, "> db/$testname/$tbox") || die "Can't create new file db/$testname/$tbox: $!";
|
||||
close(FILE);
|
||||
}
|
||||
|
||||
# record data
|
||||
open(FILE, ">> db/$testname/$tbox") ||
|
||||
die "Can't open db/$tbox: $!";
|
||||
print FILE "$time\t$value\t$data\t$ip\t$tbox\t$ua\n";
|
||||
close(FILE);
|
||||
|
||||
exit 0;
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
#sub read_config() {
|
||||
# my %nametable;
|
||||
# open(CONFIG, "< db/config.txt") ||
|
||||
# die "can't open config.txt: $!";
|
||||
# while (<CONFIG>) {
|
||||
# next if /^$/;
|
||||
# next if /^#|^\s+#/;
|
||||
# s/\s+#.*$//;
|
||||
# my ($tinderbox, $assigned_ip) = split(/\s+/, $_);
|
||||
# $nametable{$tinderbox} = $assigned_ip;
|
||||
# }
|
||||
# return %nametable;
|
||||
#}
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/perl
|
||||
use CGI::Carp qw(fatalsToBrowser);
|
||||
use CGI::Request;
|
||||
use Date::Calc qw(Add_Delta_Days); # http://www.engelschall.com/u/sb/download/Date-Calc/
|
||||
|
||||
my $req = new CGI::Request;
|
||||
|
||||
my $TESTNAME = lc($req->param('testname'));
|
||||
my $UNITS = lc($req->param('units'));
|
||||
my $TBOX = lc($req->param('tbox'));
|
||||
my $AUTOSCALE = lc($req->param('autoscale'));
|
||||
my $DAYS = lc($req->param('days'));
|
||||
my $DATAFILE = "db/$TESTNAME/$TBOX";
|
||||
|
||||
sub make_filenames_list {
|
||||
my ($dir) = @_;
|
||||
|
||||
my @result;
|
||||
|
||||
if (-d "$dir") {
|
||||
chdir "$dir";
|
||||
while(<*>) {
|
||||
if( $_ ne 'config.txt' ) {
|
||||
push @result, $_;
|
||||
}
|
||||
}
|
||||
chdir "../..";
|
||||
}
|
||||
return @result;
|
||||
}
|
||||
|
||||
# Print out a list of testnames in db directory
|
||||
sub print_testnames {
|
||||
my ($testname) = @_;
|
||||
|
||||
# HTTP header
|
||||
print "Content-type: text/html\n\n<HTML>\n";
|
||||
print "<title>testnames</title>";
|
||||
print "<center><h2><b>testnames</b></h2></center>";
|
||||
print "<p><table width=\"100%\">";
|
||||
print "<tr><td align=center>Select one of the following tests:</td></tr>";
|
||||
print "<tr><td align=center>\n";
|
||||
print " <table><tr><td><ul>\n";
|
||||
|
||||
my @machines = make_filenames_list("db");
|
||||
my $machines_string = join(" ", @machines);
|
||||
|
||||
foreach (@machines) {
|
||||
print "<li><a href=graph.cgi?&testname=$_$testname>$_</a>\n";
|
||||
}
|
||||
print "</ul></td></tr></table></td></tr></table>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Print out a list of machines in db/<testname> directory, with links.
|
||||
sub print_machines {
|
||||
my ($testname) = @_;
|
||||
|
||||
# HTTP header
|
||||
print "Content-type: text/html\n\n<HTML>\n";
|
||||
print "<title>$TESTNAME machines</title>";
|
||||
print "<center><h2><b>$TESTNAME machines:</b></h2></center>";
|
||||
print "<p><table width=\"100%\">";
|
||||
print "<tr><td align=center>Select one of the following machines:</td></tr>";
|
||||
print "<tr><td align=center>\n";
|
||||
print " <table><tr><td><ul>\n";
|
||||
|
||||
my @machines = make_filenames_list("db/$testname");
|
||||
my $machines_string = join(" ", @machines);
|
||||
|
||||
foreach (@machines) {
|
||||
print "<li><a href=graph.cgi?tbox=$_&testname=$testname&autoscale=0&days=0>$_</a>\n";
|
||||
}
|
||||
print "</ul></td></tr></table></td></tr></table>";
|
||||
|
||||
}
|
||||
|
||||
sub show_graph {
|
||||
die "$TBOX: no data file found."
|
||||
unless -e $DATAFILE;
|
||||
|
||||
my $PNGFILE = "/tmp/gnuplot.$$";
|
||||
|
||||
# Find gnuplot, sorry this is for solaris.
|
||||
my $gnuplot;
|
||||
if(-f "/usr/bin/gnuplot") {
|
||||
$gnuplot = "/usr/bin/gnuplot";
|
||||
} elsif(-f "/usr/local/bin/gnuplot") {
|
||||
$gnuplot = "/usr/local/bin/gnuplot";
|
||||
$ENV{LD_LIBRARY_PATH} .= "/usr/local/lib";
|
||||
} else {
|
||||
die "Can't find gnuplot.";
|
||||
}
|
||||
|
||||
|
||||
# Set scaling for x-axis (time)
|
||||
my $xscale;
|
||||
my $today;
|
||||
my $n_days_ago;
|
||||
|
||||
# Get current time, $today.
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdat) = localtime();
|
||||
$year += 1900;
|
||||
$mon += 1;
|
||||
$today = sprintf "%04d:%02d:%02d:%02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec;
|
||||
|
||||
# Calculate date $DAYS before $today.
|
||||
my ($year2, $mon2, $mday2) = Add_Delta_Days($year, $mon, $mday, -$DAYS);
|
||||
$n_days_ago= sprintf "%04d:%02d:%02d:%02d:%02d:%02d", $year2, $mon2, $mday2, $hour, $min, $sec;
|
||||
|
||||
if($DAYS) {
|
||||
# Assume we want to see 7 days on the graph, so we set the max value also.
|
||||
$xscale = "set xrange [\"$n_days_ago\" : \"$today\"]";
|
||||
} else {
|
||||
$xscale = "";
|
||||
}
|
||||
|
||||
|
||||
# Set scaling for y-axis.
|
||||
my $yscale;
|
||||
if($AUTOSCALE) {
|
||||
$yscale = "";
|
||||
} else {
|
||||
$yscale = "set yrange [ 0 : ]";
|
||||
}
|
||||
|
||||
|
||||
# Set units. Assume ms unless otherwise specified.
|
||||
unless($UNITS) {
|
||||
$UNITS = "ms";
|
||||
}
|
||||
|
||||
|
||||
# interpolate params into gnuplot command
|
||||
my $cmds = qq{
|
||||
reset
|
||||
set term png color
|
||||
set output "$PNGFILE"
|
||||
set title "$TBOX $TESTNAME"
|
||||
set key graph 0.1,0.95 reverse spacing .75 width -18
|
||||
set linestyle 1 lt 1 lw 1 pt 7 ps 0
|
||||
set linestyle 2 lt 1 lw 1 pt 7 ps 1
|
||||
set data style points
|
||||
set timefmt "%Y:%m:%d:%H:%M:%S"
|
||||
set xdata time
|
||||
$xscale
|
||||
$yscale
|
||||
set ylabel "$TESTNAME ($UNITS)"
|
||||
set timestamp "Generated: %d/%b/%y %H:%M" 0,0
|
||||
set format x "%h %d"
|
||||
set grid
|
||||
plot "$DATAFILE" using 1:2 with points ls 1, "$DATAFILE" using 1:2 with lines ls 2
|
||||
};
|
||||
|
||||
|
||||
# Set up command string for gnuplot
|
||||
open (GNUPLOT, "| $gnuplot") || die "can't fork: $!";
|
||||
print GNUPLOT $cmds;
|
||||
close (GNUPLOT) || die "Empty data set? Gnuplot failed to set up the plot command string : $!";
|
||||
|
||||
# Actually do the gnuplot command.
|
||||
open (GNUPLOT, "< $PNGFILE") || die "can't read: $!";
|
||||
{ local $/; $blob = <GNUPLOT>; }
|
||||
close (GNUPLOT) || die "can't close: $!";
|
||||
unlink $PNGFILE || die "can't unlink $PNGFILE: $!";
|
||||
|
||||
print "Content-type: image/png\n\n";
|
||||
print $blob;
|
||||
}
|
||||
|
||||
# main
|
||||
{
|
||||
|
||||
if(!$TESTNAME) {
|
||||
print_testnames();
|
||||
} elsif(!$TBOX) {
|
||||
print_machines($TESTNAME);
|
||||
} else {
|
||||
show_graph();
|
||||
}
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
Загрузка…
Ссылка в новой задаче