sanity.in 2.16 KB
Newer Older
1
#/usr/bin/perl
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2009 University of Utah and the Flux Group.
# All rights reserved.
#
7 8 9 10 11 12

use Data::Dumper;

# Turn off line buffering on output
$| = 1; 

13
chdir "@prefix@/data/node_usage";
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

open A, "node_usage.raw";

my $keep = 100;
my @data;
$data[0] = {time => -1};
$data[$keep-1] = undef;

sub fetch_until ($) {

    my ($until) = @_;

    while ($data[0]{time}[0] <= $until && ($_ = <A>)) {
	pop @data;
	chop;
	s/^(\d+) (\d+) // or die;
	my $time = $2;
	my %d;
	while (s/^ ([\w\d\-\?]+): (\d+) (\d+) (\d+) //) {
	    my $type = $1;
	    my @d = ($2, $3, $4);
	    next unless $type =~ /^pc(600|850|2000|3000)$/;
	    $d{$type} = \@d;
	}
	$data[0]{time}[1] = $time - 1;
	unshift @data, {time => [$time, $time], data => \%d};
    }
}

open B, "from_ptop.raw";

while (<B>) {
    chop;
    s/^(\d+).+ ::// or die;
    my $time = $1;
    my %d;
    while (s/^ ([\w\d\-\?]+): (\d+)//) {
	my $type = $1;
	my @d = ($2);
	next unless $type =~ /^pc(600|850|2000|3000)$/;
	$d{$type} = $d[0];
    }
    my %r;
    fetch_until $time + 5;
    my $c = 0;
    foreach my $d (@data) {
	last unless $d->{time}[1] >= $time - 10;
	next unless $d->{time}[0] <= $time + 1;
	$c++;
	#print ">>$d->{time}[0] $d->{time}[1]\n";
	while (my ($k,$v) = each %{$d->{data}}) {
	    if (exists $r{$k}) {
		foreach my $i (0 .. 2) {
		    $r{$k}[$i][0] = $v->[$i] if $v->[$i] < $r{$k}[$i][0];
		    $r{$k}[$i][1] = $v->[$i] if $v->[$i] > $r{$k}[$i][1];
		}
	    } else {
		$r{$k} = [map {[$_, $_]} @$v];
	    }
	}
    }
    #print "XXX ";
    #foreach my $k (sort keys %r) {
    #    print "$k: [$r{$k}[0][0] $r{$k}[0][1]] [$r{$k}[1][0] $r{$k}[1][1]] [$r{$k}[2][0] $r{$k}[2][1]]  ";
    #}
    #print "\nYYY ";
    #foreach my $k (sort keys %d) {
    #    print "$k: $d{$k}  ";
    #}
    my @errors;
    foreach my $k (sort keys %r) {
	my ($min,$max) = @{$r{$k}[1]};
	my $errmax = $r{$k}[2][1];
	push @errors, sprintf("%s -%d [%d %d]",$k,$min - $d{$k},$min,$max) if $d{$k} < $min && $min - $d{$k} > $errmax;
	push @errors, sprintf("%s +%d [%d %d]",$k,$d{$k} - $max,$min,$max) if $d{$k} > $max && $d{$k} - $max > $errmax;
    }
    print "$time ";
    foreach (@errors) {
	print " $_ ";
    }
    print "\n";
}