#!/usr/bin/perl -w
-# Copyright (C) 2007 Apple Inc. All rights reserved.
-# Copyright (C) Eric Seidel <eric@webkit.org>
+# Copyright (C) 2007 Apple Inc. All rights reserved.
+# Copyright (C) 2007 Eric Seidel <eric@webkit.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
use strict;
use Getopt::Long;
use File::Basename;
+use File::Spec;
use Cwd;
+use POSIX qw(strftime);
my $showHelp = 0;
my $runShark = 0;
+my $runShark20 = 0;
my $jsShellPath;
+my $setBaseline = 0;
my $testsPattern;
my $testRuns = 5; # This number may be different from what ./sunspider defaults to (that's OK)
my $programName = basename($0);
my $usage = <<EOF;
Usage: $programName --shell=[path] [options]
- --help Show this help message
- --shell Path to javascript shell
- --runs Number of times to run tests (default: $testRuns)
- --tests Only run tests matching provided pattern
- --shark Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
+ --help Show this help message
+ --set-baseline Set baseline for future comparisons
+ --shell Path to JavaScript shell
+ --runs Number of times to run tests (default: $testRuns)
+ --tests Only run tests matching provided pattern
+ --shark Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
+ --shark20 Like --shark, but with a 20 microsecond sampling interval
EOF
GetOptions('runs=i' => \$testRuns,
+ 'set-baseline' => \$setBaseline,
'shell=s' => \$jsShellPath,
'shark' => \$runShark,
+ 'shark20' => \$runShark20,
'tests=s' => \$testsPattern,
'help' => \$showHelp);
-$testRuns = 1 if $runShark;
+$runShark = 20 if $runShark20;
+$testRuns = 1 if $runShark;
+if ($runShark && ! -x "/usr/bin/shark") {
+ die "Please install CHUD tools from http://developer.apple.com/tools/download/\n";
+}
if (!$jsShellPath || $showHelp) {
print STDERR $usage;
sub dumpToFile($$)
{
my ($contents, $path) = @_;
- open FILE, ">$path";
+ open FILE, ">", $path or die "Failed to open $path";
print FILE $contents;
close FILE;
}
-# FIXME: these globals are rather poor abstraction
my @tests = ();
my @categories = ();
my %uniqueCategories = ();
sub loadTestsList()
{
- open TESTLIST, "<./tests/LIST";
+ open TESTLIST, "<", "tests/LIST" or die;
while (<TESTLIST>) {
chomp;
next unless !$testsPattern || /$testsPattern/;
close TESTLIST;
}
+my $timeString = strftime "%Y-%m-%d-%H.%M.%S", localtime $^T;
+my $prefixFile = "tmp/sunspider-test-prefix.js";
+my $resultsFile = "tmp/sunspider-results-$timeString.js";
+
sub writePrefixFile()
{
my $prefix = "var tests = [ " . join(", ", map { '"' . $_ . '"' } @tests) . " ];\n";
$prefix .= "var categories = [ " . join(", ", map { '"' . $_ . '"' } @categories) . " ];\n";
mkdir "tmp";
- dumpToFile($prefix, "tmp/sunspider-test-prefix.js");
+ dumpToFile($prefix, $prefixFile);
}
sub runTestsOnce($)
{
my ($useShark) = @_;
- my $shellArgs = "-f tmp/sunspider-test-prefix.js -f resources/sunspider-standalone-driver.js 2> /dev/null";
+ my $shellArgs = "-f $prefixFile -f resources/sunspider-standalone-driver.js 2> /dev/null";
my $output;
if ($useShark) {
- print STDERR "Running sunspider under Shark... (this will take a while)\n";
- print STDERR "shark -i -1 -q \"$jsShellPath\" $shellArgs\n";
- $output = `shark -i -1 -q "$jsShellPath" $shellArgs`;
+ my $intervalArg = $useShark == 20 ? "-I 20u" : "";
+ $output = `shark $intervalArg -i -1-q "$jsShellPath" $shellArgs`;
} else {
$output = `"$jsShellPath" $shellArgs | grep -v break`;
}
return $output;
}
+sub newestFile($$)
+{
+ my ($dir, $pattern) = @_;
+
+ my $newestAge;
+ my $newestFile = "";
+ opendir DIR, $dir or die;
+ for my $file (readdir DIR) {
+ if ($file =~ $pattern) {
+ my $age = -M "$dir/$file";
+ if (!defined $newestAge || $age < $newestAge) {
+ $newestFile = $file;
+ $newestAge = $age;
+ }
+ }
+ }
+ closedir DIR;
+ return "$dir/$newestFile";
+}
loadTestsList();
if ($testsPattern) {
print STDERR "Found " . scalar(@tests) . " tests\n";
}
die "No tests to run" unless scalar(@tests);
-print STDERR "Running SunSpider once for warmup, then $testRuns times\n";
+print STDERR "Running SunSpider once for warmup, then " . ($runShark ? "under Shark" : "$testRuns time" . ($testRuns == 1 ? "" : "s")) . "\n";
writePrefixFile();
runTestsOnce(0);
print "[";
while ($count++ < $testRuns) {
$result = runTestsOnce($runShark);
+ $result =~ s/\r\n/\n/g;
chomp $result;
push @results, $result;
print $result;
print "]\n";
my $output = "var output = [\n" . join(",\n", @results) . "\n];\n";
-dumpToFile($output, "tmp/sunspider-results.js");
+dumpToFile($output, $resultsFile);
+dumpToFile(File::Spec->rel2abs($resultsFile), "tmp/baseline-filename.txt") if $setBaseline;
-system("$jsShellPath", "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-results.js", "-f", "resources/sunspider-analyze-results.js");
+system("$jsShellPath", "-f", $prefixFile, "-f", $resultsFile, "-f", "resources/sunspider-analyze-results.js");
-print STDERR "Shark sessions can be found in " . getcwd() . "\n" if $runShark;
+if ($runShark) {
+ my $newestMShark = newestFile(".", qr/\.mshark$/);
+ if ($newestMShark) {
+ my $profileFile = "tmp/sunspider-profile-$timeString.mshark";
+ rename $newestMShark, $profileFile or die;
+ exec "/usr/bin/open", $profileFile;
+ }
+}