getbw 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # Extract the bandwith information.
  2. # Usage: getbw file file....
  3. #
  4. # Hacked into existence by Larry McVoy (lm@sun.com now lm@sgi.com).
  5. # Copyright (c) 1994 Larry McVoy. GPLed software.
  6. # $Id$
  7. eval 'exec perl -Ssw $0 "$@"'
  8. if 0;
  9. #
  10. # Default is file bandwidth which lists: mem read, file read (both),
  11. # mmap read (both), bcopy.
  12. #
  13. # -mem turns off the file stuff but turns on rd, wr, rdwr, frd, fwr,
  14. # bcopy, bzero, cp, fcp.
  15. #
  16. foreach $file (@ARGV) {
  17. open(FD, $file);
  18. &cache;
  19. open(FD, $file);
  20. ($f = $file) =~ s|/|-|;
  21. if ($mem || $all) {
  22. print "tmp/bwmem.$f\n";
  23. open(OUT, ">tmp/bwmem.$f");
  24. } else {
  25. print "tmp/bwfile.$f\n";
  26. open(OUT, ">tmp/bwfile.$f");
  27. }
  28. print OUT "%X Memory size \n%Y Bandwidth in MB/sec\n";
  29. while (<FD>) {
  30. chop;
  31. if (/^\[lmbench/) {
  32. @_ = split;
  33. if ($_[3] eq "SunOS") {
  34. $_[3] .= "-$_[5]";
  35. }
  36. $uname = "@_";
  37. }
  38. if (/^\d+.*Mhz/) {
  39. @_ = split;
  40. $mhz = $_[0];
  41. $tmp = &getinfo("$uname", $mhz);
  42. if ($mem) {
  43. print OUT "%T Memory bandwidth for $tmp\n";
  44. } else {
  45. print OUT "%T Reread bandwidth for $tmp\n";
  46. }
  47. }
  48. if (/MHZ/) {
  49. @_ = split;
  50. $mhz = $_[1];
  51. chop($mhz) if $mhz =~ /]$/;
  52. $tmp = &getinfo("$uname", $mhz);
  53. if ($mem) {
  54. print OUT "%T Memory bandwidth for $tmp\n";
  55. } else {
  56. print OUT "%T Reread bandwidth for $tmp\n";
  57. }
  58. }
  59. if ((!$all && !$mem) && /^"read bandwidth/) {
  60. print OUT "\"File reread\n";
  61. while (<FD>) {
  62. last if /^\s*$/;
  63. print OUT;
  64. }
  65. print OUT "\n";
  66. next;
  67. }
  68. if ((!$all && !$mem) && /^"read open2close bandwidth/) {
  69. print OUT "\"File open2close reread\n";
  70. while (<FD>) {
  71. last if /^\s*$/;
  72. print OUT;
  73. }
  74. print OUT "\n";
  75. next;
  76. }
  77. if ((!$all && !$mem) && /^"Mmap read bandwidth/) {
  78. print OUT "\"File mmap reread\n";
  79. while (<FD>) {
  80. last if /^\s*$/;
  81. print OUT;
  82. }
  83. print OUT "\n";
  84. next;
  85. }
  86. if ((!$all && !$mem) && /^"Mmap read open2close bandwidth/) {
  87. print OUT "\"File mmap open2close reread\n";
  88. while (<FD>) {
  89. last if /^\s*$/;
  90. print OUT;
  91. }
  92. print OUT "\n";
  93. next;
  94. }
  95. if ($all && /^"libc bcopy aligned/) {
  96. print OUT "\"libc bcopy aligned\n";
  97. while (<FD>) {
  98. last if /^\s*$/;
  99. print OUT;
  100. }
  101. print OUT "\n";
  102. next;
  103. }
  104. if (/^"libc bcopy unaligned/) {
  105. print OUT "\"libc bcopy unaligned\n";
  106. while (<FD>) {
  107. last if /^\s*$/;
  108. print OUT;
  109. }
  110. print OUT "\n";
  111. next;
  112. }
  113. if ($all && /^"unrolled bcopy aligned/) {
  114. print OUT "\"libc bcopy unaligned\n";
  115. while (<FD>) {
  116. last if /^\s*$/;
  117. print OUT;
  118. }
  119. print OUT "\n";
  120. next;
  121. }
  122. if (($all || $mem) && /^"unrolled bcopy unaligned/) {
  123. print OUT "\"unrolled bcopy unaligned\n";
  124. while (<FD>) {
  125. last if /^\s*$/;
  126. print OUT;
  127. }
  128. print OUT "\n";
  129. next;
  130. }
  131. if (($all || $mem) && /^"unrolled partial bcopy unaligned/) {
  132. print OUT "\"unrolled partial bcopy unaligned\n";
  133. while (<FD>) {
  134. last if /^\s*$/;
  135. @_ = split; next unless $_[0] > $cache;
  136. print OUT;
  137. }
  138. print OUT "\n";
  139. next;
  140. }
  141. if (/^Memory read bandwidth/) {
  142. print OUT "\"$_\n";
  143. while (<FD>) {
  144. last if /^\s*$/;
  145. print OUT;
  146. }
  147. print OUT "\n";
  148. next;
  149. }
  150. if (($all || $mem) && /^Memory partial read bandwidth/) {
  151. print OUT "\"$_\n";
  152. while (<FD>) {
  153. last if /^\s*$/;
  154. @_ = split; next unless $_[0] > $cache;
  155. print OUT;
  156. }
  157. print OUT "\n";
  158. next;
  159. }
  160. if (($all || $mem) && /^Memory partial read.write bandwidth/) {
  161. print OUT "\"$_\n";
  162. while (<FD>) {
  163. last if /^\s*$/;
  164. @_ = split; next unless $_[0] > $cache;
  165. print OUT;
  166. }
  167. print OUT "\n";
  168. next;
  169. }
  170. if (($all || $mem) && /^Memory partial write bandwidth/) {
  171. print OUT "\"$_\n";
  172. while (<FD>) {
  173. last if /^\s*$/;
  174. @_ = split; next unless $_[0] > $cache;
  175. print OUT;
  176. }
  177. print OUT "\n";
  178. next;
  179. }
  180. if (($all || $mem) && /^Memory write bandwidth/) {
  181. print OUT "\"$_\n";
  182. while (<FD>) {
  183. last if /^\s*$/;
  184. print OUT;
  185. }
  186. print OUT "\n";
  187. next;
  188. }
  189. if (($all || $mem) && /^Memory bzero bandwidth/) {
  190. print OUT "\"$_\n";
  191. while (<FD>) {
  192. last if /^\s*$/;
  193. print OUT;
  194. }
  195. print OUT "\n";
  196. next;
  197. }
  198. }
  199. }
  200. # Paw through the data and figure out how big the L1 cache is.
  201. # We look at the memory read performance and look for cluster breaks
  202. # at 4, 8, 16, 32, 64, 126, and 256k.
  203. sub cache
  204. {
  205. local($in) = 0;
  206. local($n, $sum, $avg) = (0,0,0);
  207. $cache = 0;
  208. while (<FD>) {
  209. if (/^Memory partial read bandwidth/) {
  210. $in = 1;
  211. next;
  212. }
  213. next unless $in;
  214. @_ = split;
  215. if ($n == 0) {
  216. $sum += $_[1];
  217. $n++;
  218. next;
  219. }
  220. $avg = $sum/$n;
  221. if ($_[1] < .75*$avg) {
  222. $cache = $last;
  223. return;
  224. }
  225. $last = $_[0];
  226. $sum += $_[1];
  227. $n++;
  228. }
  229. }
  230. # Try and create sensible names from uname -a output
  231. sub getinfo
  232. {
  233. local(@info);
  234. local($name);
  235. local($mhz);
  236. $mhz = $_[1];
  237. $_ = $_[0];
  238. @info = split;
  239. $name = pop(@info);
  240. chop($name);
  241. if ($name eq "unknown") {
  242. $name = pop(@info);
  243. }
  244. if ($name eq "mips") {
  245. $name = "$info[$#info]\@$mhz";
  246. } elsif ($_[0] =~ /HP-UX/) {
  247. $name = "$info[7]\@$mhz";
  248. } elsif ($_[0] =~ /SunOS/) {
  249. $name = "$info[7]\@$mhz";
  250. } else {
  251. $name .= "\@$mhz";
  252. }
  253. "$info[3] $name";
  254. }