opercent 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. eval "exec perl -sS $0 $*"
  2. if 0;
  3. $fmt = 0;
  4. @fmts = (
  5. "%33s %4s %4s %3s %4s %4s %4s %4s %4s %4s\n",
  6. "%28s %6s %6s %5s %6s %7s %7s\n",
  7. "%29s %5s %4s %5s %5s %5s %5s %4s\n",
  8. "%30s %6s %6s %6s %8s %5s %7s\n",
  9. "%28s %4s %4s %6s %6s %6s %6s %4s %5s\n",
  10. "%29s %5s %6s %11s\n",
  11. );
  12. while (<>) {
  13. print;
  14. next unless /^Host/;
  15. $_ = <>; print;
  16. unless (/^-/) {
  17. $_ = <>; print;
  18. }
  19. @values = ();
  20. @a = @b = @c = @d = @e = @f = @g = @h = @i = @j = @k = ();
  21. $i = 0;
  22. while (<>) {
  23. last if /^\s/;
  24. print;
  25. s/.......................\s+//;
  26. ($a[$i],$b[$i],$c[$i],$d[$i],$e[$i],$f[$i],$g[$i],$h[$i],$i[$i],$j[$i],$k[$i]) = split;
  27. $i++;
  28. }
  29. $a = &sss(@a) if $#a != -1;
  30. $b = &sss(@b) if $#b != -1;
  31. $c = &sss(@c) if $#c != -1;
  32. $d = &sss(@d) if $#d != -1;
  33. $e = &sss(@e) if $#e != -1;
  34. $f = &sss(@f) if $#f != -1;
  35. $g = &sss(@g) if $#g != -1;
  36. $h = &sss(@h) if $#h != -1;
  37. $i = &sss(@i) if $#i != -1;
  38. $j = &sss(@j) if $#j != -1;
  39. $k = &sss(@k) if $#k != -1;
  40. printf $fmts[$fmt], $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k;
  41. print "\n";
  42. exit if $fmt++ == $#fmts;
  43. }
  44. sub sss
  45. {
  46. local($tmp);
  47. local(@values) = ();
  48. local($n, $sum, $min, $max) = (0,0,1.7E+300,2.2E-300);
  49. foreach $_ (@_) {
  50. next unless /^\d/;
  51. chop if /K$/;
  52. push(@values, $_);
  53. $sum += $_;
  54. $min = $_ if $_ < $min;
  55. $max = $_ if $_ > $max;
  56. $n++;
  57. }
  58. return "" if $#values == -1;
  59. # Do some statistics.
  60. @s = sort(@values);
  61. if ($n & 1) {
  62. $median = $s[($n + 1)/2];
  63. } else {
  64. $i = $n / 2;
  65. $median = ($s[$i] + $s[$i+1]) / 2;
  66. }
  67. $avg = $sum/$n;
  68. $avgdev = $var = 0;
  69. foreach $_ (@values) {
  70. $var += ($_ - $median) ** 2;
  71. $tmp = $_ - $median;
  72. $avgdev += $tmp > 0 ? $tmp : -$tmp;
  73. }
  74. $var /= $n - 1;
  75. $stddev = sqrt($var);
  76. $avgdev /= $n;
  77. #printf("%8s %8s %8s %8s %8s %4s %8s\n", "Min", "Max", "Average", "Median", "Std Dev", "%", "Avg Dev");
  78. #printf "%8.2f %8.2f %8.2f %8.2f %8.2f %4.1f%% %8.2f\n", $min, $max, $avg, $median, $stddev, $stddev/$median*100, $avgdev;
  79. $percent = $stddev/$median*100;
  80. if ($percent > 90) {
  81. printf "Huh: $percent $stddev $median @values\n";
  82. }
  83. if ($percent >= 10) {
  84. return sprintf "%.0f%%", $percent;
  85. } else {
  86. return sprintf "%.1f%%", $percent;
  87. }
  88. }