From d29e4da38d5160049a4275be17e7a7f5b0dc967f Mon Sep 17 00:00:00 2001 From: "mcafee%netscape.com" Date: Fri, 30 Nov 2001 04:51:04 +0000 Subject: [PATCH] First add. Clone of startup cgis. plans to make this a general graph cgi are in the wings, this is a temporary get-this-going hack --- webtools/graph/xulwinopen/collect.cgi | 65 +++++++++++++++++ webtools/graph/xulwinopen/query.cgi | 101 ++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100755 webtools/graph/xulwinopen/collect.cgi create mode 100755 webtools/graph/xulwinopen/query.cgi diff --git a/webtools/graph/xulwinopen/collect.cgi b/webtools/graph/xulwinopen/collect.cgi new file mode 100755 index 000000000000..7285c70cc59a --- /dev/null +++ b/webtools/graph/xulwinopen/collect.cgi @@ -0,0 +1,65 @@ +#!/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: "?avg=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{$avg $data $tbox $ua $ip $time}; +$avg = $req->param('avg'); +$data = $req->param('data'); +$tbox = $req->param('tbox'); $tbox =~ tr/A-Z/a-z/; +$ua = $req->cgi->var("HTTP_USER_AGENT"); +$ip = $req->cgi->var("REMOTE_ADDR"); +$time = strftime "%Y:%m:%d:%H:%M:%S", localtime; + +print "Content-type: text/plain\n\n"; +for (qw{avg data tbox ua ip time}) { + no strict 'refs'; + printf "%6s = %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 'avg' parameter supplied" + unless $avg; +die "No 'data' parameter supplied" + unless $data; + +# record data +open(FILE, ">> db/$tbox") || + die "Can't open $tbox: $!"; +print FILE "$time\t$avg\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 () { + next if /^$/; + next if /^#|^\s+#/; + s/\s+#.*$//; + my ($tinderbox, $assigned_ip) = split(/\s+/, $_); + $nametable{$tinderbox} = $assigned_ip; + } + return %nametable; +} diff --git a/webtools/graph/xulwinopen/query.cgi b/webtools/graph/xulwinopen/query.cgi new file mode 100755 index 000000000000..3ce2eaae3416 --- /dev/null +++ b/webtools/graph/xulwinopen/query.cgi @@ -0,0 +1,101 @@ +#!/usr/bin/perl +use CGI::Carp qw(fatalsToBrowser); +use CGI::Request; + +my $req = new CGI::Request; + +my $TBOX = lc($req->param('tbox')); +my $DATAFILE = "db/$TBOX"; + +sub make_machine_list { + my @result; + chdir "db"; + while(<*>) { + if( $_ ne 'config.txt' ) { + push @result, $_; + } + } + chdir ".."; + return @result; +} + +# no tbox, print out a list of machines in db directory, with links. +sub print_machines { + # HTTP header + print "Content-type: text/html\n\n\n"; + print "

XUL Window Open times:

"; + print "

"; + print ""; + print "
Select one of the following machines:
\n"; + print "
    \n"; + + my @machines = make_machine_list(); + my $machines_string = join(" ", @machines); + + foreach (@machines) { + print "
  • $_\n"; + } + print "
"; + +} + +sub show_graph { + die "$TBOX is not a valid machine name" + 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."; + } + + # interpolate params into gnuplot command + my $cmds = qq{ + reset + set term png color + set output "$PNGFILE" + set title "$TBOX XUL Open Window Times" + 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 yrange [ 0 : ] + set xdata time + set ylabel "Startup time (msec.)" + 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 + }; + + open (GNUPLOT, "| $gnuplot") || die "can't fork: $!"; + print GNUPLOT $cmds; + close (GNUPLOT) || die "can't close: $!"; + open (GNUPLOT, "< $PNGFILE") || die "can't read: $!"; + { local $/; $blob = ; } + close (GNUPLOT) || die "can't close: $!"; + unlink $PNGFILE || die "can't unlink $PNGFILE: $!"; + + print "Content-type: image/png\n\n"; + print $blob; +} + +# main +{ + unless ($TBOX) { + print_machines(); + } else { + show_graph(); + } +} + +exit 0; +