Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / EC_Multiple / histo.pl
blob128fcc8059faba359a7448c5ddb274dfe3efce36
2 # Extract a histogram, minimum, maximum and average from a file,
3 # filtering by a given RE.
6 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
7 & eval 'exec perl -S $0 $argv:q'
8 if 0;
10 # The first three lines above let this script run without specifying the
11 # full path to perl, as long as it is in the user's PATH.
12 # Taken from perlrun man page.
14 use Getopt::Std;
16 $opt_k = 'Latency\[LCL,[A-Z]*\]';
17 $opt_r = 1;
19 getopts ('k:r:');
21 $max = 0;
22 $min = 0;
23 $sum = 0;
24 $sum2 = 0;
25 $n = 0;
26 %histo = ();
28 while (<>) {
29 if (!m/^$opt_k/) {
30 next;
32 chop;
33 @f = split(/:/, $_);
34 if ($n == 0) {
35 $min = $f[1];
36 $max = $f[1];
37 $sum = $f[1];
38 $sum2 = $f[1] * $f[1];
39 $n = 1;
40 } else {
41 if ($min > $f[1]) {
42 $min = $f[1];
44 if ($max < $f[1]) {
45 $max = $f[1];
47 $sum += $f[1];
48 $sum2 += $f[1] * $f[1];
49 $n++;
51 $i = int ($f[1] * $opt_r);
52 $histo{"$i"}++;
55 print "Latency results for $opt_k:\n";
56 $s2 = $sum2 / ($n - 1) - $sum / $n * $sum / ($n - 1);
57 if ($s2 >= 0) {
58 $sigma = int(sqrt ( $s2 ));
59 } else {
60 print "Error: $sum, $sum2, $n\n";
61 $sigma = $sum2;
64 print "Min: $min,",
65 " Max: $max,",
66 " Avg: ", int($sum / $n),
67 " Dev: ", $sigma,
68 "\n";
70 while ( ($key,$value) = each %histo ) {
71 $t = ($key / $opt_r);
72 print $t, " ", 100 * $value / $n, "\n";