Root/m1rc3/norruption/2/plot-cdf

1#!/usr/bin/perl
2
3sub usage
4{
5    print STDERR "usage: $0 [-i] [log_file]\n";
6    exit(1);
7}
8
9
10$with = "steps";
11if ($ARGV[0] eq "-i") {
12    shift @ARGV;
13    $with = "lines";
14}
15&usage if $ARGV[0] =~ /^-/;
16
17$n = 1;
18while (<>) {
19    next unless /^=== (\d+) ===/;
20    while ($1 != $n) {
21        push(@f, $n);
22        $n++;
23    }
24    $n++;
25}
26
27$n--;
28$f = int($n/@f+0.5);
29
30$last = 0;
31for (@f) {
32    push(@d, $_-$last);
33    $last = $_;
34}
35
36$cmd = "|gnuplot -e '".
37    'set term postscript color eps enhanced solid lw 2 20;'.
38    'set output "out.eps";'.
39    'set title "Probability distribution of time between NOR corruptions";'.
40    'set xlabel "Power cycles";'.
41    'set ylabel "Cumulative probability";'.
42    'set key bottom;'.
43    'plot "-" with '.$with.' title "Empirical distribution (N='.@f.')", '.
44      '1-exp(-'.1/$f.'*x) with lines lt 3 '.
45      'title "Exponential distribution ({/Symbol l}=1/'.$f.')"'.
46    "'";
47
48open(PIPE, $cmd) || die "open: $!";
49print PIPE "0 0\n";
50$i = 0;
51for (sort { $a <=> $b } @d) {
52    $i++;
53    print PIPE $_, " ", $i/@f, "\n";
54}
55close(PIPE) || die "close: $!";
56
57system("cat out.eps | ".
58    "gs -sDEVICE=ppmraw -r100 -sOutputFile=- ".
59    "-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sPAPERSIZE=a4 -q - | ".
60    "convert -trim - out.png");
61unlink("out.eps");
62

Archive Download this file

Branches:
master



interactive