Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | sub usage |
| 4 | { |
| 5 | print STDERR "usage: $0 [-i] [log_file]\n"; |
| 6 | exit(1); |
| 7 | } |
| 8 | |
| 9 | |
| 10 | $with = "steps"; |
| 11 | if ($ARGV[0] eq "-i") { |
| 12 | shift @ARGV; |
| 13 | $with = "lines"; |
| 14 | } |
| 15 | &usage if $ARGV[0] =~ /^-/; |
| 16 | |
| 17 | $n = 1; |
| 18 | while (<>) { |
| 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; |
| 31 | for (@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 | |
| 48 | open(PIPE, $cmd) || die "open: $!"; |
| 49 | print PIPE "0 0\n"; |
| 50 | $i = 0; |
| 51 | for (sort { $a <=> $b } @d) { |
| 52 | $i++; |
| 53 | print PIPE $_, " ", $i/@f, "\n"; |
| 54 | } |
| 55 | close(PIPE) || die "close: $!"; |
| 56 | |
| 57 | system("cat out.eps | ". |
| 58 | "gs -sDEVICE=ppmraw -r100 -sOutputFile=- ". |
| 59 | "-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sPAPERSIZE=a4 -q - | ". |
| 60 | "convert -trim - out.png"); |
| 61 | unlink("out.eps"); |
| 62 |
Branches:
master
