Root/m1rc3/norruption/2/plot-corr

Source at commit 36b52a976d287876f06a12bdf34dfe13c80d7df0 created 12 years 5 months ago.
By Werner Almesberger, m1rc3/norruption/2/plot-corr: options -n and -i to set samples and interval
1#!/usr/bin/perl
2
3sub usage
4{
5    print STDERR "usage: $0 [-s [-n samples] [-i interval]] [log_file]\n";
6    exit(1);
7}
8
9
10while ($ARGV[0] =~ /^-/) {
11    $opt = shift @ARGV;
12    if ($opt eq "-s") {
13        $sim = 1;
14    } elsif ($opt eq "-n") {
15        $sim_n = shift @ARGV;
16        &usage unless defined $sim_n;
17    } elsif ($opt eq "-i") {
18        $sim_t = shift @ARGV;
19        &usage unless defined $sim_t;
20    } else {
21        &usage;
22    }
23}
24
25unless ($sim && defined $sim_n && defined $sim_t) {
26    $n = 1;
27    while (<>) {
28        next unless /^=== (\d+) ===/;
29        while ($1 != $n) {
30            push(@f, $n);
31            $n++;
32        }
33        $n++;
34    }
35
36    $n--;
37    $t = int($n/@f+0.5);
38
39    $last = 0;
40    for (@f) {
41        push(@d, $_-$last);
42        $last = $_;
43    }
44}
45
46if ($sim) {
47    # y = 1-exp(-x/T)
48    # 1-y = exp(-x/T)
49    # ln(1-y) = -x/T
50    # -T*ln(1-y) = x
51
52    $type = " (SIMULATED)";
53    $sim_n = @f unless defined $sim_n;
54    $sim_t = $t unless defined $sim_t;
55    @d = ();
56    for ($i = 0; $i != $sim_n; $i++) {
57        push(@d, -$sim_t*log(1-rand));
58    }
59}
60
61for (@d) {
62    $max = $_ if $_ > $max;
63}
64
65$cmd = "|gnuplot -e '".
66    'set term postscript color eps enhanced solid lw 2 20;'.
67    'set output "out.eps";'.
68    'set xrange [0:'.$max*1.05.'];'.
69    'set yrange [0:'.$max*1.05.'];'.
70    'set title "Correlation of time to adjacent corruptions'.$type.'";'.
71    'set xlabel "Cycles since previous event";'.
72    'set ylabel "Cycles until next event";'.
73    'plot "-" with points pt 7 notitle'.
74    "'";
75
76open(PIPE, $cmd) || die "open: $!";
77undef $last;
78for (@d) {
79    print PIPE "$last $_\n" if defined $last;
80    $last = $_;
81}
82close(PIPE) || die "close: $!";
83
84system("cat out.eps | ".
85    "gs -sDEVICE=ppmraw -r100 -sOutputFile=- ".
86    "-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sPAPERSIZE=a4 -q - | ".
87    "convert -trim - out.png");
88unlink("out.eps");
89

Archive Download this file

Branches:
master



interactive