You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

620 lines
16 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. #!/usr/bin/perl
  2. # Copyright (c) 2000, 2001, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
  3. # Use is subject to license terms.
  4. #
  5. # This library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Library General Public
  7. # License as published by the Free Software Foundation; version 2
  8. # of the License.
  9. #
  10. # This library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Library General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Library General Public
  16. # License along with this library; if not, write to the Free
  17. # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. # MA 02110-1301, USA
  19. #
  20. # a little program to generate a table of results
  21. # just read all the RUN-*.log files and format them nicely
  22. # Made by Luuk de Boer
  23. # Patched by Monty
  24. use Getopt::Long;
  25. $opt_server="mysql";
  26. $opt_dir="output";
  27. $opt_machine=$opt_cmp="";
  28. $opt_relative=$opt_same_server=$opt_help=$opt_Information=$opt_skip_count=$opt_no_bars=$opt_verbose=0;
  29. GetOptions("Information","help","server=s","cmp=s","machine=s","relative","same-server","dir=s","skip-count","no-bars","html","verbose") || usage();
  30. usage() if ($opt_help || $opt_Information);
  31. $opt_cmp=lc(join(",",sort(split(',',$opt_cmp))));
  32. if ($opt_same_server)
  33. {
  34. $files="$opt_dir/RUN-$opt_server*$opt_machine";
  35. }
  36. else
  37. {
  38. $files="$opt_dir/RUN-*$opt_machine";
  39. }
  40. $files.= "-cmp-$opt_cmp" if (length($opt_cmp));
  41. #
  42. # Go trough all RUN files and gather statistics.
  43. #
  44. if ($#ARGV == -1)
  45. {
  46. @ARGV=glob($files);
  47. $automatic_files=1;
  48. }
  49. foreach (@ARGV)
  50. {
  51. next if (!$opt_cmp && /-cmp-/ && $automatic_files || defined($found{$_}));
  52. $prog=$filename = $_;
  53. $found{$_}=1; # Remove dupplicates
  54. /RUN-(.*)$/;
  55. $tot{$prog}{'version'}=$1;
  56. push(@key_order,$prog);
  57. $next = 0;
  58. open(TMP, "<$filename") || die "Can't open $filename: $!\n";
  59. while (<TMP>)
  60. {
  61. chomp;
  62. if ($next == 0) {
  63. if (/Server version:\s+(\S+.*)/i)
  64. {
  65. $tot{$prog}{'server'} = $1;
  66. }
  67. elsif (/Arguments:\s+(.+)/i)
  68. {
  69. $arguments= $1;
  70. # Remove some standard, not informative arguments
  71. $arguments =~ s/--force|--log|--use-old\S*|--server=\S+|--cmp=\S+|--user=\S+|--pass=\S+|--machine=\S+|--dir=\S+//g;
  72. if (($tmp=index($arguments,"--comment")) >= 0)
  73. {
  74. if (($end=index($arguments,$tmp+2,"--")) >= 0)
  75. {
  76. substr($arguments,$tmp,($end-$tmp))="";
  77. }
  78. else
  79. {
  80. $arguments=substr($arguments,0,$tmp);
  81. }
  82. }
  83. $arguments =~ s/\s+/ /g;
  84. $tot{$prog}{'arguments'}=$arguments;
  85. }
  86. elsif (/Comments:\s+(.+)/i) {
  87. $tot{$prog}{'comments'} = $1;
  88. } elsif (/^(\S+):.*(estimated\s|)total\stime:\s+([\d.]+)\s+(wallclock\s|)secs/i)
  89. {
  90. $tmp = $1; $tmp =~ s/://;
  91. $tot{$prog}{$tmp} = [ $3, (length($2) ? "+" : "")];
  92. $op1{$tmp} = $tmp;
  93. } elsif (/Totals per operation:/i) {
  94. $next = 1;
  95. next;
  96. }
  97. }
  98. elsif ($next == 1)
  99. {
  100. if (/^(\S+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*([+|?])*/)
  101. {
  102. $tot1{$prog}{$1} = [$2,$6,$7];
  103. $op{$1} = $1;
  104. }
  105. }
  106. }
  107. }
  108. if (!%op)
  109. {
  110. print "Didn't find any files matching: '$files'\n";
  111. print "Use the --cmp=server,server option to compare benchmarks\n";
  112. exit 1;
  113. }
  114. # everything is loaded ...
  115. # now we have to create a fancy output :-)
  116. # I prefer to redirect scripts instead to force it to file ; Monty
  117. #
  118. # open(RES, ">$resultfile") || die "Can't write to $resultfile: $!\n";
  119. # select(RES)
  120. #
  121. if ($opt_html) {
  122. html_output();
  123. } else {
  124. ascii_output();
  125. }
  126. exit 0;
  127. #
  128. # some output + format functions;
  129. #
  130. sub ascii_output {
  131. print <<EOF;
  132. This is the result file of the different benchmark tests.
  133. The number in () after each tests shows how many SQL commands the particular
  134. test did. As one test may have many different parameters this gives only
  135. a rough picture of what was done. Check the source for more information :)
  136. Keep in mind that one can\'t compare benchmarks run with different --cmp
  137. options. The --cmp options sets the all limits according to the worst
  138. limit for all server in the benchmark.
  139. Numbers marked with '+' are estimated according to previous runs because
  140. the query took longer than a given time-limit to finish. The estimation
  141. shouldn\'t be far from the real result thought.
  142. Numbers marked with '?' contains results that gave wrong result. This can only
  143. be used as an indication of how long it took for the server to produce a wrong
  144. result :)
  145. Numbers marked with '*' are tests that was run a different number times
  146. than the test in the first column. The reason for this is normally that the
  147. marked test was run with different options that affects the number of tests
  148. or that the test was from another version of the MySQL benchmarks.
  149. Hope this will give you some idea how each db is performing at what thing ....
  150. Hope you like it .... Luuk & Monty (1997)
  151. EOF
  152. if ($opt_relative)
  153. {
  154. print "Column 1 is in seconds. All other columns are presented relative\n";
  155. print "to this. 1.00 is the same, bigger numbers indicates slower\n\n";
  156. }
  157. if ($opt_verbose)
  158. {
  159. print "The test values is printed in the format 'time:number of tests'\n";
  160. }
  161. if (length($opt_cmp))
  162. {
  163. print "The test was run with limits from: $opt_cmp\n\n";
  164. }
  165. print "The result logs which where found and the options:\n";
  166. $bar= $opt_no_bars ? " " : "|";
  167. # Move $opt_server first in array if not filename on command line
  168. if ($automatic_files)
  169. {
  170. @key_order=sort {$a cmp $b} keys %tot;
  171. for ($i=0; $i <= $#key_order; $i++)
  172. {
  173. if ($tot{$key_order[$i]}{'version'} =~ /^$opt_server-/)
  174. {
  175. unshift(@key_order,$key_order[$i]);
  176. splice(@key_order,$i+1,1);
  177. last;
  178. }
  179. }
  180. }
  181. # Print header
  182. $column_count=0;
  183. foreach $key (@key_order)
  184. {
  185. $tmp=$tmp=$tot{$key}{'version'};
  186. $tmp =~ s/-cmp-$opt_cmp// if (length($opt_cmp));
  187. $column_count++;
  188. printf "%2d %-40.40s: %s %s\n", $column_count, $tmp,
  189. $tot{$key}{'server'}, $tot{$key}{'arguments'};
  190. print " $tot{$key}{'comments'}\n"
  191. if ($tot{$key}{'comments'} =~ /\w+/);
  192. }
  193. print "\n";
  194. $namewidth=($opt_skip_count && !$opt_verbose) ? 29 : 36;
  195. $colwidth= $opt_relative ? 10 : 7;
  196. $count_width=7;
  197. $colwidth+=$count_width if ($opt_verbose);
  198. print_sep("=");
  199. printf "%-$namewidth.${namewidth}s${bar}", "Operation";
  200. $count = 1;
  201. foreach $key (@key_order)
  202. {
  203. printf "%${colwidth}d${bar}", $count;
  204. $count++;
  205. }
  206. printf "\n%-$namewidth.${namewidth}s${bar}", "";
  207. foreach $key (@key_order)
  208. {
  209. $ver=$tot{$key}{'version'};
  210. $ver =~ s/-[a-zA-Z0-9_\.]+-cmp-$opt-cmp$//;
  211. printf "%${colwidth}.${colwidth}s${bar}", $ver;
  212. }
  213. print "\n";
  214. print_sep("-");
  215. print_string($opt_relative ? "Relative results per test (First column is in seconds):" : "Results per test in seconds:");
  216. print_sep("-");
  217. foreach $key (sort {$a cmp $b} keys %op1)
  218. {
  219. printf "%-$namewidth.${namewidth}s${bar}", $key;
  220. $first=undef();
  221. foreach $server (@key_order)
  222. {
  223. print_value($first,$tot{$server}{$key}->[0],undef(),$tot{$server}{$key}->[1]);
  224. $first=$tot{$server}{$key}->[0] if (!defined($first));
  225. }
  226. print "\n";
  227. }
  228. print_sep("-");
  229. print_string("The results per operation:");
  230. print_sep("-");
  231. foreach $key (sort {$a cmp $b} keys %op)
  232. {
  233. next if ($key =~ /TOTALS/i);
  234. $tmp=$key;
  235. $count=$tot1{$key_order[0]}{$key}->[1];
  236. $tmp.= " (" . $count . ")" if (!$skip_count);
  237. printf "%-$namewidth.${namewidth}s${bar}", $tmp;
  238. $first=undef();
  239. foreach $server (@key_order)
  240. {
  241. $tmp= $count != $tot1{$server}{$key}->[1] ? "*" : "";
  242. print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[1],
  243. $tot1{$server}{$key}->[2] . $tmp);
  244. $first=$tot1{$server}{$key}->[0] if (!defined($first));
  245. }
  246. print "\n";
  247. }
  248. print_sep("-");
  249. $key="TOTALS";
  250. printf "%-$namewidth.${namewidth}s${bar}", $key;
  251. $first=undef();
  252. foreach $server (@key_order)
  253. {
  254. print_value($first,$tot1{$server}{$key}->[0],undef(),
  255. $tot1{$server}{$key}->[2]);
  256. $first=$tot1{$server}{$key}->[0] if (!defined($first));
  257. }
  258. print "\n";
  259. print_sep("=");
  260. }
  261. sub html_output
  262. {
  263. my $template="template.html";
  264. my $title="MySQL | | Information | Benchmarks | Compare with $opt_cmp";
  265. my $image="info.gif";
  266. $bar="";
  267. open(TEMPLATE, $template) || die;
  268. while (<TEMPLATE>)
  269. {
  270. if (/<center>/)
  271. {
  272. print $_;
  273. print "<!---- This is AUTOMATICALLY Generated. Do not edit here! ---->\n";
  274. }
  275. elsif (/TITLE:SUBTITLE/)
  276. {
  277. s|TITLE:SUBTITLE|$title|;
  278. print $_;
  279. }
  280. elsif (/TITLE:COMPARE/)
  281. {
  282. s|TITLE:COMPARE|$opt_cmp|;
  283. print $_;
  284. }
  285. elsif (/ subchapter name /)
  286. {
  287. # Nothing here for now
  288. print $_;
  289. }
  290. elsif (/ text of chapter /)
  291. {
  292. print $_;
  293. print_html_body();
  294. }
  295. else
  296. {
  297. print $_;
  298. }
  299. }
  300. close(TEMPLATE);
  301. }
  302. sub print_html_body
  303. {
  304. my ($title,$count,$key);
  305. print <<EOF;
  306. <center>
  307. <font size=+4><b>MySQL Benchmark Results</b></font><br>
  308. <font size=+1><b>Compare with $opt_cmp</b></font><p><p>
  309. </center>
  310. This is the result file of the different benchmark tests.
  311. <p>
  312. The number in () after each tests shows how many SQL commands the particular
  313. test did. As one test may have many different parameters this gives only
  314. a rough picture of what was done. Check the source for more information.
  315. <p>
  316. Keep in mind that one can\'t compare benchmarks run with different --cmp
  317. options. The --cmp options sets the all limits according to the worst
  318. limit for all server in the benchmark.
  319. <p>
  320. Numbers marked with '+' are estimated according to previous runs because
  321. the query took longer than a given time-limit to finish. The estimation
  322. shouldn\'t be far from the real result thought.
  323. <p>
  324. Numbers marked with '?' contains results that gave wrong result. This can only
  325. be used as an indication of how long it took for the server to produce a wrong
  326. result :)
  327. <p>
  328. Hope this will give you some idea how each db is performing at what thing ....
  329. <br>
  330. Hope you like it .... Luuk & Monty (1997)
  331. <p><p>
  332. EOF
  333. if ($opt_relative)
  334. {
  335. print "Column 1 is in seconds. All other columns are presented relative<br>\n";
  336. print "to this. 1.00 is the same, bigger numbers indicates slower<p>\n\n";
  337. }
  338. if (length($opt_cmp))
  339. {
  340. print "The test was run with limits from: $opt_cmp\n\n";
  341. }
  342. print "The result logs which where found and the options:<br>\n";
  343. # Move $opt_server first in array
  344. if ($automatic_files)
  345. {
  346. @key_order=sort {$a cmp $b} keys %tot;
  347. for ($i=0; $i <= $#key_order; $i++)
  348. {
  349. if ($tot{$key_order[$i]}{'version'} =~ /^$opt_server-/)
  350. {
  351. unshift(@key_order,$key_order[$i]);
  352. splice(@key_order,$i+1,1);
  353. last;
  354. }
  355. }
  356. }
  357. # Print header
  358. print "<p><center><table border=1 width=100%>\n";
  359. $column_count=0;
  360. foreach $key (@key_order)
  361. {
  362. $tmp=$tot{$key}{'version'};
  363. $tmp =~ s/-cmp-$opt_cmp// if (length($opt_cmp));
  364. $column_count++;
  365. # printf "<tr><td>%2d<td>%-36.36s<td>%s %s</tr>\n", $column_count, $tmp,
  366. printf "<tr><td>%2d</td><td>%s</td><td>%s %s</td></tr>\n",
  367. $column_count, $tmp, $tot{$key}{'server'}, $tot{$key}{'arguments'};
  368. print "<tr><td colspan=3>$tot{$key}{'comments'}</td></tr>\n"
  369. if ($tot{$key}{'comments'} =~ /\w+/);
  370. }
  371. print "</table></center><p><center><table border=1 width=100%>\n";
  372. $namewidth=$opt_skip_count ? 22 :29;
  373. $colwidth= $opt_relative ? 10 : 7;
  374. $count_width=7;
  375. printf "<tr><td><b>%s</b></td>\n", "Operation";
  376. $count = 1;
  377. foreach $key (@key_order)
  378. {
  379. $ver=$tot{$key}{'version'};
  380. printf "<td align=center><b>%d", $count;
  381. printf "<br>%${colwidth}.${colwidth}s</b></td>\n", substr($ver,0,index($ver,"-"));
  382. $count++;
  383. }
  384. print "</tr>\n";
  385. $title = $opt_relative ? "Relative results per test (First column is in seconds):" : "Results per test in seconds:";
  386. printf "<tr><td colspan=%d><b>%s</b></td></tr>\n", $count, $title;
  387. foreach $key (sort {$a cmp $b} keys %op1)
  388. {
  389. if (!$opt_html)
  390. {
  391. printf "<tr><td>%-$namewidth.${namewidth}s</td>", $key;
  392. }
  393. else
  394. {
  395. print "<tr><td>$key</td>";
  396. }
  397. $first=undef();
  398. foreach $server (@key_order)
  399. {
  400. print_value($first,$tot{$server}{$key}->[0],undef(),
  401. $tot{$server}{$key}->[1]);
  402. $first=$tot{$server}{$key}->[0] if (!defined($first));
  403. }
  404. print "</tr>\n";
  405. }
  406. $title = "The results per operation:";
  407. printf "<tr><td colspan=%d><b>%s</b></td></tr>\n", $count, $title;
  408. foreach $key (sort {$a cmp $b} keys %op)
  409. {
  410. next if ($key =~ /TOTALS/i);
  411. $tmp=$key;
  412. $tmp.= " (" . $tot1{$key_order[0]}{$key}->[1] . ")" if (!$skip_count);
  413. if (!$opt_html)
  414. {
  415. printf "<tr><td>%-$namewidth.${namewidth}s</td>", $tmp;
  416. }
  417. else
  418. {
  419. print "<tr><td>$tmp</td>";
  420. }
  421. $first=undef();
  422. foreach $server (@key_order)
  423. {
  424. print_value($first,$tot1{$server}{$key}->[0],
  425. $tot1{$server}{$key}->[1],
  426. $tot1{$server}{$key}->[2]);
  427. $first=$tot1{$server}{$key}->[0] if (!defined($first));
  428. }
  429. print "</tr>\n";
  430. }
  431. $key="TOTALS";
  432. printf "<tr><td><b>%-$namewidth.${namewidth}s</b></td>", $key;
  433. $first=undef();
  434. foreach $server (@key_order)
  435. {
  436. print_value($first,$tot1{$server}{$key}->[0],undef(),
  437. $tot1{$server}{$key}->[2]);
  438. $first=$tot1{$server}{$key}->[0] if (!defined($first));
  439. }
  440. print "</tr>\n</table>\n";
  441. }
  442. sub print_sep
  443. {
  444. my ($sep)=@_;
  445. print $sep x ($namewidth + (($colwidth+1) * $column_count)+1),"\n";
  446. }
  447. sub print_value
  448. {
  449. my ($first,$value,$count,$flags)=@_;
  450. my ($tmp,$width);
  451. if (defined($value))
  452. {
  453. if (!defined($first) || !$opt_relative)
  454. {
  455. $tmp=sprintf("%.2f",$value);
  456. }
  457. else
  458. {
  459. $first=1 if ($first == 0); # Assume that it took one second instead of 0
  460. $tmp= sprintf("%.2f",$value/$first);
  461. }
  462. if (defined($flags))
  463. {
  464. $tmp="+".$tmp if ($flags =~ /\+/);
  465. $tmp="?".$tmp if ($flags =~ /\?/);
  466. $tmp="*".$tmp if ($flags =~ /\*/);
  467. }
  468. }
  469. else
  470. {
  471. $tmp="";
  472. }
  473. $width= ($opt_verbose ? $colwidth - $count_width : $colwidth);
  474. if (!$opt_html)
  475. {
  476. $tmp= " " x ($width-length($tmp)) . $tmp if (length($tmp) < $width);
  477. }
  478. if ($opt_verbose)
  479. {
  480. if ($count)
  481. {
  482. $tmp.= ":" . " " x ($count_width-1-length($count)) . $count;
  483. }
  484. else
  485. {
  486. $tmp.= " " x ($count_width);
  487. }
  488. }
  489. if (!$opt_html) {
  490. print $tmp . "${bar}";
  491. } else {
  492. print "<td align=right>$tmp</td>";
  493. }
  494. }
  495. sub print_string
  496. {
  497. my ($str)=@_;
  498. if (!$opt_html)
  499. {
  500. my ($width);
  501. $width=$namewidth + ($colwidth+1)*$column_count;
  502. $str=substr($str,1,$width) if (length($str) > $width);
  503. print($str," " x ($width - length($str)),"${bar}\n");
  504. }
  505. else
  506. {
  507. print $str,"\n";
  508. }
  509. }
  510. sub usage
  511. {
  512. print <<EOF;
  513. $0 Ver 1.2
  514. This program parses all RUN files from old 'run-all-tests --log' scripts
  515. and makes a nice comparable table.
  516. $0 takes currently the following options:
  517. --help or --Information
  518. Shows this help
  519. --cmp=server,server,server (Default $opt_cmp)
  520. Compares all runs that are done with the same --cmp options to run-all-tests.
  521. The most normal options are '--cmp=mysql,pg,solid' and '--cmp ""'
  522. --dir=... (Default $opt_dir)
  523. From which directory one should get the runs. All runs made by
  524. run-all-tests --log is saved in the 'output' directory.
  525. In the 'results' directory you may have some example runs from different
  526. databases.
  527. --html
  528. Print the table in html format.
  529. --machine='full-machine-name' (Default $opt_machine)
  530. Use only runs that match this machine.
  531. --relative
  532. Show all numbers in times of the first server where the time for the
  533. first server is 1.0
  534. --same-server
  535. Compare all runs for --server=.... The --machine is not used in this case
  536. This is nice to compare how the same server runs on different machines.
  537. --server='server name' (Default $opt_server)
  538. Put this server in the first result column.
  539. --skip-count
  540. Do not write the number of tests after the test-name.
  541. --verbose
  542. Write the number of tests in each column. This is useful when some column
  543. is marked with '*'.
  544. EOF
  545. exit(0);
  546. }