-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRun
More file actions
executable file
·1835 lines (1533 loc) · 56.4 KB
/
Run
File metadata and controls
executable file
·1835 lines (1533 loc) · 56.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
use strict;
use POSIX qw(strftime);
use Time::HiRes;
use IO::Handle;
############################################################################
# UnixBench - Release 5.1.1, based on:
# The BYTE UNIX Benchmarks - Release 3
# Module: Run SID: 3.11 5/15/91 19:30:14
# Original Byte benchmarks written by:
# Ben Smith, Tom Yager at BYTE Magazine
# ben@bytepb.byte.com tyager@bytepb.byte.com
# BIX: bensmith tyager
#
#######################################################################
# General Purpose Benchmark
# based on the work by Ken McDonell, Computer Science, Monash University
#
# You will need ...
# perl Time::HiRes IO::Handlecat cc chmod comm cp date dc df echo
# kill ls make mkdir rm sed test time touch tty umask who
###############################################################################
# Modification Log:
# $Header: run,v 5.2 88/01/12 06:23:43 kenj Exp $
# Ken McDonell, Computer Science, Monash University
# August 1, 1983
# 3/89 - Ben Smith - BYTE: globalized many variables, modernized syntax
# 5/89 - commented and modernized. Removed workload items till they
# have been modernized. Added database server test.
# 11/14/89 - Made modifications to reflect new version of fstime
# and elimination of mem tests.
# 10/22/90 - Many tests have been flipped so that they run for
# a specified length of time and loops are counted.
# 4/3/91 - Cleaned up and debugged several test parameters - Ben
# 4/9/91 - Added structure for creating index and determing flavor of UNIX
# 4/26/91 - Made changes and corrections suggested by Tin Le of Sony
# 5/15/91 - Removed db from distribution
# 4/4/92 Jon Tombs <jon@robots.ox.ac.uk> fixed for GNU time to look like
# BSD (don't know the format of sysV!)
# 12/95 - Massive changes for portability, speed, and more meaningful index
# DCN David C Niemi <niemi@tux.org>
# 1997.06.20 DCN Fixed overflow condition in fstime.c on fast machines
# 1997.08.24 DCN Modified "system", replaced double with
# whetstone-double in "index"
# 1997.09.10 DCN Added perlbench as an Exhibition benchmark
# 1997.09.23 DCN Added rgooch's select as an Exhibition benchmark
# 1999.07.28 DCN "select" not compiled or run by default, because it
# does not compile on many platforms. PerlBench also
# not run by default.
# 2007.09.26 IS Huge rewrite -- see release notes in README.
# 2007.10.12 IS Added graphics tests, categories feature.
# 2007.10.14 IS Set and report LANG. Added "grep" and "sysexec".
# 2007.12.22 IS Tiny fixes; see README.
############################################################################
# CONFIGURATION
############################################################################
# Version number of the script.
my $version = "5.1.2";
# The setting of LANG makes a huge difference to some of the scores,
# particularly depending on whether UTF-8 is used. So we always set
# it to the same value, which is configured here.
#
# If you want your results to be meaningful when compared to other peoples'
# results, you should not change this. Change it if you want to measure the
# effect of different languages.
my $language = "en_US.utf8";
# The number of iterations per test.
my $longIterCount = 10;
my $shortIterCount = 3;
# C compiler to use in compilation tests.
my $cCompiler = 'gcc';
# Establish full paths to directories. These need to be full pathnames
# (or do they, any more?). They can be set in env.
# variables whose names are the first parameter to getDir() below.
my $BASEDIR = `pwd`;
chomp($BASEDIR);
# Directory where the test programs live.
my $BINDIR = getDir('UB_BINDIR', $BASEDIR . "/pgms");
# Temp directory, for temp files.
my $TMPDIR = getDir('UB_TMPDIR', $BASEDIR . "/tmp");
# Directory to put results in.
my $RESULTDIR = getDir('UB_RESULTDIR', $BASEDIR . "/results");
# Directory where the tests are executed.
my $TESTDIR = getDir('UB_TESTDIR', $BASEDIR . "/testdir");
############################################################################
# TEST SPECIFICATIONS
############################################################################
# Configure the categories to which tests can belong.
my $testCats = {
'system' => { 'name' => "System Benchmarks", 'maxCopies' => 16 },
'2d' => { 'name' => "2D Graphics Benchmarks", 'maxCopies' => 1 },
'3d' => { 'name' => "3D Graphics Benchmarks", 'maxCopies' => 1 },
'misc' => { 'name' => "Non-Index Benchmarks", 'maxCopies' => 16 },
};
my $arithmetic = [
"arithoh", "short", "int", "long", "float", "double", "whetstone-double"
];
my $fs = [
"fstime-w", "fstime-r", "fstime",
"fsbuffer-w", "fsbuffer-r", "fsbuffer",
"fsdisk-w", "fsdisk-r", "fsdisk"
];
my $oldsystem = [
"execl", "fstime", "fsbuffer", "fsdisk", "pipe", "context1", "spawn",
"syscall"
];
my $system = [
@$oldsystem, "shell1", "shell8", "shell16"
];
my $index = [
"dhry2reg", "whetstone-double", @$oldsystem, "shell1", "shell8"
];
my $graphics = [
"2d-rects", "2d-ellipse", "2d-aashapes", "2d-text", "2d-blit",
"2d-window", "ubgears"
];
# List of all supported test names.
my $testList = {
# Individual tests.
"dhry2reg" => undef,
"whetstone-double" => undef,
"syscall" => undef,
"pipe" => undef,
"context1" => undef,
"spawn" => undef,
"execl" => undef,
"fstime-w" => undef,
"fstime-r" => undef,
"fstime" => undef,
"fsbuffer-w" => undef,
"fsbuffer-r" => undef,
"fsbuffer" => undef,
"fsdisk-w" => undef,
"fsdisk-r" => undef,
"fsdisk" => undef,
"shell1" => undef,
"shell8" => undef,
"shell16" => undef,
"short" => undef,
"int" => undef,
"long" => undef,
"float" => undef,
"double" => undef,
"arithoh" => undef,
"C" => undef,
"dc" => undef,
"hanoi" => undef,
"grep" => undef,
"sysexec" => undef,
"2d-rects" => undef,
"2d-lines" => undef,
"2d-circle" => undef,
"2d-ellipse" => undef,
"2d-shapes" => undef,
"2d-aashapes" => undef,
"2d-polys" => undef,
"2d-text" => undef,
"2d-blit" => undef,
"2d-window" => undef,
"ubgears" => undef,
# Named combos and shorthands.
"arithmetic" => $arithmetic,
"dhry" => [ "dhry2reg" ],
"dhrystone" => [ "dhry2reg" ],
"whets" => [ "whetstone-double" ],
"whetstone" => [ "whetstone-double" ],
"load" => [ "shell" ],
"misc" => [ "C", "dc", "hanoi" ],
"speed" => [ @$arithmetic, @$system ],
"oldsystem" => $oldsystem,
"system" => $system,
"fs" => $fs,
"shell" => [ "shell1", "shell8", "shell16" ],
"graphics" => $graphics,
# The tests which constitute the official index.
"index" => $index,
# The tests which constitute the official index plus the graphics
# index.
"gindex" => [ @$index, @$graphics ],
};
# Default parameters for benchmarks. Note that if "prog" is used,
# it must contain just the program name, as it will be quoted (this
# is necessary if BINDIR contains spaces). Put any options in "options".
my $baseParams = {
"prog" => undef,
"options" => "",
"repeat" => 'short',
"stdout" => 1, # Non-0 to keep stdout.
"stdin" => "",
"logmsg" => "",
};
# Individual parameters for all benchmarks.
my $testParams = {
##########################
## System Benchmarks ##
##########################
"dhry2reg" => {
"logmsg" => "Dhrystone 2 using register variables",
"cat" => 'system',
"options" => "10",
"repeat" => 'long',
},
"whetstone-double" => {
"logmsg" => "Double-Precision Whetstone",
"cat" => 'system',
"repeat" => 'long',
},
"syscall" => {
"logmsg" => "System Call Overhead",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"context1" => {
"logmsg" => "Pipe-based Context Switching",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"pipe" => {
"logmsg" => "Pipe Throughput",
"cat" => 'system',
"repeat" => 'long',
"options" => "10",
},
"spawn" => {
"logmsg" => "Process Creation",
"cat" => 'system',
"options" => "30",
},
"execl" => {
"logmsg" => "Execl Throughput",
"cat" => 'system',
"options" => "30",
},
"fstime-w" => {
"logmsg" => "File Write 1024 bufsize 2000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-w -t 30 -d \"${TMPDIR}\" -b 1024 -m 2000",
},
"fstime-r" => {
"logmsg" => "File Read 1024 bufsize 2000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-r -t 30 -d \"${TMPDIR}\" -b 1024 -m 2000",
},
"fstime" => {
"logmsg" => "File Copy 1024 bufsize 2000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-c -t 30 -d \"${TMPDIR}\" -b 1024 -m 2000",
},
"fsbuffer-w" => {
"logmsg" => "File Write 256 bufsize 500 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-w -t 30 -d \"${TMPDIR}\" -b 256 -m 500",
},
"fsbuffer-r" => {
"logmsg" => "File Read 256 bufsize 500 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-r -t 30 -d \"${TMPDIR}\" -b 256 -m 500",
},
"fsbuffer" => {
"logmsg" => "File Copy 256 bufsize 500 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-c -t 30 -d \"${TMPDIR}\" -b 256 -m 500",
},
"fsdisk-w" => {
"logmsg" => "File Write 4096 bufsize 8000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-w -t 30 -d \"${TMPDIR}\" -b 4096 -m 8000",
},
"fsdisk-r" => {
"logmsg" => "File Read 4096 bufsize 8000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-r -t 30 -d \"${TMPDIR}\" -b 4096 -m 8000",
},
"fsdisk" => {
"logmsg" => "File Copy 4096 bufsize 8000 maxblocks",
"cat" => 'system',
"prog" => "${BINDIR}/fstime",
"options" => "-c -t 30 -d \"${TMPDIR}\" -b 4096 -m 8000",
},
"shell1" => {
"logmsg" => "Shell Scripts (1 concurrent)",
"cat" => 'system',
"prog" => "${BINDIR}/looper",
"options" => "60 \"${BINDIR}/multi.sh\" 1",
},
"shell8" => {
"logmsg" => "Shell Scripts (8 concurrent)",
"cat" => 'system',
"prog" => "${BINDIR}/looper",
"options" => "60 \"${BINDIR}/multi.sh\" 8",
},
"shell16" => {
"logmsg" => "Shell Scripts (16 concurrent)",
"cat" => 'system',
"prog" => "${BINDIR}/looper",
"options" => "60 \"${BINDIR}/multi.sh\" 16",
},
##########################
## Graphics Benchmarks ##
##########################
"2d-rects" => {
"logmsg" => "2D graphics: rectangles",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "rects 3 2",
},
"2d-lines" => {
"logmsg" => "2D graphics: lines",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "lines 3 2",
},
"2d-circle" => {
"logmsg" => "2D graphics: circles",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "circle 3 2",
},
"2d-ellipse" => {
"logmsg" => "2D graphics: ellipses",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "ellipse 3 2",
},
"2d-shapes" => {
"logmsg" => "2D graphics: polygons",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "shapes 3 2",
},
"2d-aashapes" => {
"logmsg" => "2D graphics: aa polygons",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "aashapes 3 2",
},
"2d-polys" => {
"logmsg" => "2D graphics: complex polygons",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "polys 3 2",
},
"2d-text" => {
"logmsg" => "2D graphics: text",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "text 3 2",
},
"2d-blit" => {
"logmsg" => "2D graphics: images and blits",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "blit 3 2",
},
"2d-window" => {
"logmsg" => "2D graphics: windows",
"cat" => '2d',
"prog" => "${BINDIR}/gfx-x11",
"options" => "window 3 2",
},
"ubgears" => {
"logmsg" => "3D graphics: gears",
"cat" => '3d',
"options" => "-time 20 -v",
},
##########################
## Non-Index Benchmarks ##
##########################
"C" => {
"logmsg" => "C Compiler Throughput ($cCompiler)",
"cat" => 'misc',
"prog" => "${BINDIR}/looper",
"options" => "60 $cCompiler cctest.c",
},
"arithoh" => {
"logmsg" => "Arithoh",
"cat" => 'misc',
"options" => "10",
},
"short" => {
"logmsg" => "Arithmetic Test (short)",
"cat" => 'misc',
"options" => "10",
},
"int" => {
"logmsg" => "Arithmetic Test (int)",
"cat" => 'misc',
"options" => "10",
},
"long" => {
"logmsg" => "Arithmetic Test (long)",
"cat" => 'misc',
"options" => "10",
},
"float" => {
"logmsg" => "Arithmetic Test (float)",
"cat" => 'misc',
"options" => "10",
},
"double" => {
"logmsg" => "Arithmetic Test (double)",
"cat" => 'misc',
"options" => "10",
},
"dc" => {
"logmsg" => "Dc: sqrt(2) to 99 decimal places",
"cat" => 'misc',
"prog" => "${BINDIR}/looper",
"options" => "30 dc",
"stdin" => "dc.dat",
},
"hanoi" => {
"logmsg" => "Recursion Test -- Tower of Hanoi",
"cat" => 'misc',
"options" => "20",
},
"grep" => {
"logmsg" => "Grep a large file (system's grep)",
"cat" => 'misc',
"prog" => "${BINDIR}/looper",
"options" => "30 grep -c gimp large.txt",
},
"sysexec" => {
"logmsg" => "Exec System Call Overhead",
"cat" => 'misc',
"repeat" => 'long',
"prog" => "${BINDIR}/syscall",
"options" => "10 exec",
},
};
# CPU flags of interest.
my $x86CpuFlags = {
'pae' => "Physical Address Ext",
'sep' => "SYSENTER/SYSEXIT",
'syscall' => "SYSCALL/SYSRET",
'mmx' => "MMX",
'mmxext' => "AMD MMX",
'cxmmx' => "Cyrix MMX",
'xmm' => "Streaming SIMD",
'xmm2' => "Streaming SIMD-2",
'xmm3' => "Streaming SIMD-3",
'ht' => "Hyper-Threading",
'ia64' => "IA-64 processor",
'lm' => "x86-64",
'vmx' => "Intel virtualization",
'svm' => "AMD virtualization",
};
############################################################################
# UTILITIES
############################################################################
# Exec the given command, and catch its standard output.
# We return an array containing the PID and the filehandle on the
# process' standard output. It's up to the caller to wait for the command
# to terminate.
sub command {
my ( $cmd ) = @_;
my $pid = open(my $childFd, "-|");
if (!defined($pid)) {
die("Run: fork() failed (undef)\n");
} elsif ($pid == 0) {
exec($cmd);
die("Run: exec() failed (returned)\n");
}
return ( $pid, $childFd );
}
# Get data from running a system command. Used for things like getting
# the host OS from `uname -o` etc.
#
# Ignores initial blank lines from the command and returns the first
# non-blank line, with white space trimmed off. Returns a blank string
# if there is no output; undef if the command fails.
sub getCmdOutput {
my ( $cmd ) = @_;
my ( $pid, $fd ) = command($cmd . " 2>/dev/null");
my $result = "";
while (<$fd>) {
chomp;
next if /^[ \t]*$/;
$result = $_;
$result =~ s/^[ \t]+//;
$result =~ s/[ \t]+$//;
last;
}
# Close the command and wait for it to die.
waitpid($pid, 0);
my $status = $?;
return $status == 0 ? $result : undef;
}
# Get a directory pathname from an environment variable, or the given
# default. Canonicalise and return the value.
sub getDir {
my ( $var, $def ) = @_;
my $val = $ENV{$var} || $def;
# Canonicalise the value.
my $wd;
chomp($wd = `pwd`);
chdir($val);
chomp($val = `pwd`);
chdir($wd);
$ENV{$var} = $val;
$val;
}
# Get the name of the file we're going to log to. The name uses the hostname
# and date, plus a sequence number to make it unique.
sub logFile {
my ( $sysInfo ) = @_;
my $count = 1;
# Use the date in the base file name.
my $ymd = strftime "%Y-%m-%d", localtime;
while (1) {
my $log = sprintf "%s/%s-%s-%02d",
${RESULTDIR}, $sysInfo->{'name'}, $ymd, $count;
return $log if (! -e $log);
++$count;
}
}
# Print a message to the named log file. We use this method rather than
# keeping the FD open because we use shell redirection to send command
# output to the same file.
sub printLog {
my ( $logFile, @args ) = @_;
open(my $fd, ">>", $logFile) || abortRun("can't append to $logFile");
printf $fd @args;
close($fd);
}
# Display a number of something, auto-selecting the plural form
# if appropriate. We are given the number, the singular, and the
# plural; if the plural is omitted, it defaults to singular + "s".
sub number {
my ( $n, $what, $plural ) = @_;
$plural = $what . "s" if !defined($plural);
if (!defined($n)) {
return sprintf "unknown %s", $plural;
} else {
return sprintf "%d %s", $n, $n == 1 ? $what : $plural;
}
}
# Merge two sets of test parameters -- defaults and actual parameters.
# Return the merged parameter hash.
sub mergeParams {
my ( $def, $vals ) = @_;
my $params = { };
foreach my $k (keys(%$def)) {
$params->{$k} = $def->{$k};
}
foreach my $k (keys(%$vals)) {
$params->{$k} = $vals->{$k};
}
$params;
}
############################################################################
# SYSTEM ANALYSIS
############################################################################
# Extract interesting flags from the given processor flags string and
# convert them to descriptive names.
sub processCpuFlags {
my ( $flagStr ) = @_;
my @names;
foreach my $f (sort split(/\s+/, $flagStr)) {
my $name = $x86CpuFlags->{$f};
push(@names, $name) if $name;
}
join(", ", @names);
}
# Get information on the CPUs in the system. Returns a reference to an
# array of N entries, one per CPU, where each entry is a hash containing
# these fields:
# describing the model etc. Returns undef if the information can't be got.
sub getCpuInfo {
open(my $fd, "<", "/proc/cpuinfo") || return undef;
my $cpus = [ ];
my $cpu = 0;
while (<$fd>) {
chomp;
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
next if (!$field || !$val);
if ($field eq "processor") {
$cpu = $val;
} elsif ($field eq "model name") {
my $model = $val;
$model =~ s/ +/ /g;
$cpus->[$cpu]{'model'} = $model;
} elsif ($field eq "bogomips") {
$cpus->[$cpu]{'bogo'} = $val;
} elsif ($field eq "flags") {
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
}
}
close($fd);
$cpus;
}
# Get information on the host system. Returns a reference to a hash
# with the following fields:
# name Host name
# os Host OS name
# osRel Host OS release
# osVer Host OS version
# mach Host machine name (eg. "SparcStation 20", but on
# PC/Linux usually "i686" etc.)
# platform Hardware platform; on Linux, the base CPU type?
# system System name (eg. hostname and Linux distro, like
# "hostname: openSUSE 10.2 (i586)").
# cpus Value returned by getCpuInfo(), undef if not avail.
# numCpus Number of CPUs if known, else undef.
# load System load message as per "uptime".
# numUsers Number of users and/or open shell sessions.
sub getSystemInfo {
my $info = { };
# Get host system data.
$info->{'name'} = getCmdOutput("hostname");
$info->{'os'} = getCmdOutput("uname -o") || getCmdOutput("uname -s");
$info->{'osRel'} = getCmdOutput("uname -r");
$info->{'osVer'} = getCmdOutput("uname -v");
$info->{'mach'} = getCmdOutput("uname -m");
$info->{'platform'} = getCmdOutput("uname -i");
# Get the system name (SUSE, Red Hat, etc.) if possible.
$info->{'system'} = $info->{'os'};
if ( -r "/etc/SuSE-release" ) {
$info->{'system'} = getCmdOutput("cat /etc/SuSE-release");
} elsif ( -r "/etc/release" ) {
$info->{'system'} = getCmdOutput("cat /etc/release");
}
# Get the language info.
my $lang = getCmdOutput("printenv LANG");
my $map = getCmdOutput("locale -k LC_CTYPE | grep charmap");
$map =~ s/.*=//;
my $coll = getCmdOutput("locale -k LC_COLLATE | grep collate-codeset");
$coll =~ s/.*=//;
$info->{'language'} = sprintf "%s (charmap=%s, collate=%s)",
$lang, $map, $coll;
# Get details on the CPUs, if possible.
my $cpus = getCpuInfo();
if (defined($cpus)) {
$info->{'cpus'} = $cpus;
$info->{'numCpus'} = scalar(@$cpus);
}
# Get graphics hardware info.
$info->{'graphics'} = getCmdOutput("3dinfo | cut -f1 -d\'(\'");
# Get system run state, load and usage info.
$info->{'runlevel'} = getCmdOutput("runlevel | cut -f2 -d\" \"");
$info->{'load'} = getCmdOutput("uptime");
$info->{'numUsers'} = getCmdOutput("who | wc -l");
$info;
}
############################################################################
# ERROR HANDLING
############################################################################
# Abort the benchmarking run with an error message.
sub abortRun {
my ( $err ) = @_;
printf STDERR "\n**********************************************\n";
printf STDERR "Run: %s; aborting\n", $err;
exit(1);
}
############################################################################
# TEST SETUP
############################################################################
# Do checks that everything's ready for testing.
sub preChecks {
# Set the language.
$ENV{'LANG'} = $language;
# Check that the required files are in the proper places.
system("make check");
if ($? != 0) {
system("make all");
if ($? != 0) {
abortRun("\"make all\" failed");
}
}
# Create a script to kill this run.
system("echo \"kill -9 $$\" > \"${TMPDIR}/kill_run\"");
chmod(0755, $TMPDIR . "/kill_run");
}
# Parse the command arguments.
sub parseArgs {
my @words = @_;
# The accumulator for the bench units to be run.
my $tests = [ ];
my $params = { 'tests' => $tests };
# Generate the requested list of bench programs.
my $opt;
my $word;
while ($word = shift(@words)) {
if ($word !~ m/^-/) { # A test name.
if ($word eq "all") {
foreach my $t (keys(%$testList)) {
push(@$tests, $t) if (!defined($testList->{$t}));
}
} elsif (exists($testList->{$word})) {
my $val = $testList->{$word} || [ $word ];
push(@$tests, @$val);
} else {
die("Run: unknown test \"$word\"\n");
}
} elsif ($word eq "-q") {
$params->{'verbose'} = 0;
} elsif ($word eq "-v") {
$params->{'verbose'} = 2;
} elsif ($word eq "-i") {
$params->{'iterations'} = shift(@words);
} elsif ($word eq "-c") {
if (!defined($params->{'copies'})) {
$params->{'copies'} = [ ];
}
push(@{$params->{'copies'}}, shift(@words));
} else {
die("Run: unknown option $word\n");
}
}
$params;
}
############################################################################
# RESULTS INPUT / OUTPUT
############################################################################
# Read a set of benchmarking results from the given file.
# Returns results in the form returned by runTests(), but without the
# individual pass results.
sub readResultsFromFile {
my ( $file ) = @_;
# Attempt to get the baseline data file; if we can't, just return undef.
open(my $fd, "<", $file) || return undef;
my $results = { };
while (<$fd>) {
chomp;
# Dump comments, ignore blank lines.
s/#.*//;
next if /^\s*$/;
my ( $name, $time, $slab, $sum, $score, $iters ) = split(/\|/);
my $bresult = { };
$bresult->{'score'} = $score;
$bresult->{'scorelabel'} = $slab;
$bresult->{'time'} = $time;
$bresult->{'iterations'} = $iters;
$results->{$name} = $bresult;
}
close($fd);
$results;
}
############################################################################
# RESULTS PROCESSING
############################################################################
# Process a set of results from a single test by averaging the individal
# pass results into a single final value.
# First, though, dump the worst 1/3 of the scores. The logic is that a
# glitch in the system (background process waking up, for example) may
# make one or two runs go slow, so let's discard those.
#
# $bresult is a hashed array representing the results of a single test;
# $bresult->{'passes'} is an array of the output from the individual
# passes.
sub combinePassResults {
my ( $bench, $tdata, $bresult, $logFile ) = @_;
$bresult->{'cat'} = $tdata->{'cat'};
# Computed results.
my $iterations = 0;
my $totalTime = 0;
my $sum = 0;
my $product = 0;
my $label;
my $pres = $bresult->{'passes'};
# We're going to throw away the worst 1/3 of the pass results.
# Figure out how many to keep.
my $npasses = scalar(@$pres);
my $ndump = int($npasses / 3);
foreach my $presult (sort { $a->{'COUNT0'} <=> $b->{'COUNT0'} } @$pres) {
my $count = $presult->{'COUNT0'};
my $timebase = $presult->{'COUNT1'};
$label = $presult->{'COUNT2'};
my $time = $presult->{'TIME'} || $presult->{'elapsed'};
# Skip this result if it's one of the worst ones.
if ($ndump > 0) {
printLog($logFile, "*Dump score: %12.1f\n", $count);
--$ndump;
next;
}
# Count this result.
++$iterations;
printLog($logFile, "Count score: %12.1f\n", $count);
# If $timebase is 0 the figure is a rate; else compute
# counts per $timebase. $time is always seconds.
if ($timebase > 0) {
$sum += $count / ($time / $timebase);
$product += log($count) - log($time / $timebase);
} else {
$sum += $count;
$product += log($count);
}
$totalTime += $time;
}
# Save the results for the benchmark.
if ($iterations > 0) {
$bresult->{'score'} = exp($product / $iterations);
$bresult->{'scorelabel'} = $label;
$bresult->{'time'} = $totalTime / $iterations;
$bresult->{'iterations'} = $iterations;
} else {
$bresult->{'error'} = "No measured results";
}
}
# Index the given full benchmark results against the baseline results.
# $results is a hashed array of test names to test results.
#
# Adds the following fields to each benchmark result:
# iscore The baseline score for this test
# index The index of this test against the baseline
# Adds the following fields to $results:
# indexed The number of tests for which index values were
# generated
# fullindex Non-0 if all the index tests were indexed
# index The computed overall index for the run
# Note that the index values are computed as
# result / baseline * 10
# so an index of 523 indicates that a test ran 52.3 times faster than
# the baseline.
sub indexResults {
my ( $results ) = @_;
# Read in the baseline result data. If we can't get it, just return
# without making indexed results.
my $index = readResultsFromFile($BINDIR . "/index.base");
if (!defined($index)) {
return;
}
# Count the number of results we have (indexed or not) in
# each category.
my $numCat = { };
foreach my $bench (@{$results->{'list'}}) {
my $bresult = $results->{$bench};
++$numCat->{$bresult->{'cat'}};
}
$results->{'numCat'} = $numCat;
my $numIndex = { };
my $indexed = { };
my $sum = { };
foreach my $bench (sort(keys(%$index))) {
# Get the test data for this benchmark.
my $tdata = $testParams->{$bench};
if (!defined($tdata)) {
abortRun("unknown benchmark \"$bench\" in $BINDIR/index.base");
}
# Get the test category. Count the total tests in this cat.
my $cat = $tdata->{'cat'};
++$numIndex->{$cat};