3 # Copyright (C) 2007 Apple Inc. All rights reserved.
4 # Copyright (C) 2007 Eric Seidel <eric@webkit.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 use POSIX qw(strftime);
40 my $testRuns = 5; # This number may be different from what ./sunspider defaults to (that's OK)
42 my $programName = basename($0);
44 Usage: $programName --shell=[path] [options]
45 --help Show this help message
46 --set-baseline Set baseline for future comparisons
47 --shell Path to JavaScript shell
48 --runs Number of times to run tests (default: $testRuns)
49 --tests Only run tests matching provided pattern
50 --shark Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
51 --shark20 Like --shark, but with a 20 microsecond sampling interval
54 GetOptions('runs=i' => \$testRuns,
55 'set-baseline' => \$setBaseline,
56 'shell=s' => \$jsShellPath,
57 'shark' => \$runShark,
58 'shark20' => \$runShark20,
59 'tests=s' => \$testsPattern,
60 'help' => \$showHelp);
62 $runShark = 20 if $runShark20;
63 $testRuns = 1 if $runShark;
65 if (!$jsShellPath || $showHelp) {
72 my ($contents, $path) = @_;
73 open FILE, ">", $path or die "Failed to open $path";
80 my %uniqueCategories = ();
84 open TESTLIST, "<", "tests/LIST" or die;
87 next unless !$testsPattern || /$testsPattern/;
92 if (!$uniqueCategories{$category}) {
93 push @categories, $category;
94 $uniqueCategories{$category} = $category;
100 my $timeString = strftime "%Y-%m-%d-%H.%M.%S", localtime $^T;
101 my $prefixFile = "tmp/sunspider-test-prefix.js";
102 my $resultsFile = "tmp/sunspider-results-$timeString.js";
104 sub writePrefixFile()
106 my $prefix = "var tests = [ " . join(", ", map { '"' . $_ . '"' } @tests) . " ];\n";
107 $prefix .= "var categories = [ " . join(", ", map { '"' . $_ . '"' } @categories) . " ];\n";
110 dumpToFile($prefix, $prefixFile);
116 my $shellArgs = "-f $prefixFile -f resources/sunspider-standalone-driver.js 2> /dev/null";
119 my $intervalArg = $useShark == 20 ? "-I 20u" : "";
120 $output = `shark $intervalArg -i -1-q "$jsShellPath" $shellArgs`;
122 $output = `"$jsShellPath" $shellArgs | grep -v break`;
129 my ($dir, $pattern) = @_;
133 opendir DIR, $dir or die;
134 for my $file (readdir DIR) {
135 if ($file =~ $pattern) {
136 my $age = -M "$dir/$file";
137 if (!defined $newestAge || $age < $newestAge) {
145 return "$dir/$newestFile";
150 print STDERR "Found " . scalar(@tests) . " tests matching '" . $testsPattern . "'\n";
152 print STDERR "Found " . scalar(@tests) . " tests\n";
154 die "No tests to run" unless scalar(@tests);
155 print STDERR "Running SunSpider once for warmup, then " . ($runShark ? "under Shark" : "$testRuns time" . ($testRuns == 1 ? "" : "s")) . "\n";
159 print "Discarded first run.\n";
166 while ($count++ < $testRuns) {
167 $result = runTestsOnce($runShark);
168 $result =~ s/\r\n/\n/g;
170 push @results, $result;
172 print ",\n" unless ($count == $testRuns);
176 my $output = "var output = [\n" . join(",\n", @results) . "\n];\n";
177 dumpToFile($output, $resultsFile);
178 dumpToFile(File::Spec->rel2abs($resultsFile), "tmp/baseline-filename.txt") if $setBaseline;
180 system("$jsShellPath", "-f", $prefixFile, "-f", $resultsFile, "-f", "resources/sunspider-analyze-results.js");
183 my $newestMShark = newestFile(".", qr/\.mshark$/);
185 my $profileFile = "tmp/sunspider-profile-$timeString.mshark";
186 rename $newestMShark, $profileFile or die;
187 exec "/usr/bin/open", $profileFile;