icallperf.pl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Attempt to analyze the performance before and after collecting
  2. # performance counters for ThreadPool.
  3. #
  4. # The added costs are an icall per queued item.
  5. # The icall takes/returns nothing -- no marshaling -- and
  6. # internally does an atomic increment. Theoretically the
  7. # bulk of the cost is the increment, not the call/ret.
  8. #
  9. # Doing the work on the managed side would have about the same motivation
  10. # to do the same atomic increment, but would save transition to/from native.
  11. # We could do it thread local and occasionally sweep.
  12. #
  13. # optbase is optimized baseline
  14. # opt is optimized local changes
  15. sub run
  16. {
  17. my $cmd = shift;
  18. open(my $pipe, "-|", $cmd) || die("unable to run $cmd");
  19. while (my $line = <$pipe>)
  20. {
  21. if ($line =~ / items in (\d+)/)
  22. {
  23. return $1;
  24. }
  25. }
  26. }
  27. sub runloop
  28. {
  29. my $cmd = shift;
  30. my $count = shift;
  31. my @data;
  32. #run($cmd); # throw out first
  33. for (my $i = 0; $i < $count; ++$i)
  34. {
  35. push(@data, run($cmd));
  36. }
  37. #run($cmd); # and last
  38. # Later we throw out slowest/fastest.
  39. return \@data;
  40. }
  41. sub report
  42. {
  43. my $name = shift;
  44. my $data = shift;
  45. @{$data} = sort { $a <=> $b } @{$data}; # sort numerically
  46. shift($data); # remove first and last
  47. pop($data);
  48. my $n = scalar(@{$data});
  49. print("data $name:$n:");
  50. my $sum = 0;
  51. my $a = 0;
  52. for my $i (@{$data})
  53. {
  54. print("$i ");
  55. $sum += $i;
  56. }
  57. my $avg = $sum / $n;
  58. print("avg:$avg ");
  59. for my $i (@{$data})
  60. {
  61. my $b = abs($i - $avg);
  62. $a += $b * $b;
  63. }
  64. my $dev = sqrt($a) / $n;
  65. print("stddev: $dev");
  66. print("\n");
  67. }
  68. for (@ARGV)
  69. {
  70. if (/^-?help/i || /^-?h/i || /^-?\?/ || /^-?usage/)
  71. {
  72. print("usage: perl $0 private_command baseline_command iterations\n");
  73. print(" e.g. perl $0"
  74. . " /inst/monoopt/bin/mono /dev2/monoopt/mcs/class/corlib/Test/System.Threading/icallperf.exe"
  75. . " /inst/monooptbase/bin/mono /dev2/monoopt/mcs/class/corlib/Test/System.Threading/icallperf.exe"
  76. . " 20\n");
  77. exit(0);
  78. }
  79. }
  80. my $optcmd = shift || "/inst/monoopt/bin/mono /dev2/monoopt/mcs/class/corlib/Test/System.Threading/icallperf.exe";
  81. my $optbasecmd = shift || "/inst/monooptbase/bin/mono /dev2/monoopt/mcs/class/corlib/Test/System.Threading/icallperf.exe";
  82. my $n = shift || 20;
  83. my $optdata = runloop($optcmd, $n);
  84. my $optbasedata = runloop($optbasecmd, $n);
  85. report("opt", $optdata);
  86. report("base", $optbasedata);