forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
measure-simple.pl
88 lines (75 loc) · 2.05 KB
/
measure-simple.pl
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
#!/usr/bin/perl
#
# Script to time mozilla startup
#
# Requirements:
# - a Profile with name "Default User"
# - a MOZ_TIMELINE build
#
# This starts mozilla with the profile "Default User" and makes it quit immediately.
# Measurement is of main1 from MOZ_TIMELINE output
#
# This does multiple runs [default 3] and averages all but the first run.
#
# startup-quick.pl <exe> [n times]
# n - default 3
#
require 5.003;
use strict;
use Cwd;
sub PrintUsage {
die <<END_USAGE
usage: measure-simple.pl [n]
n defaults to 3
e.g
measure-simple.pl ../../../dist/bin/mozilla
measure-simple.pl ../../../dist/bin/mozilla 10
END_USAGE
}
{
PrintUsage() unless $#ARGV >= 0;
my $exe = shift @ARGV;
my $ntimes = shift @ARGV || 3;
my $timelinelog = "timeline.log";
# Do one more than what was requested as we ignore the first run timing
$ntimes++;
# Build up command string.
my $cwd = Cwd::getcwd();
# take care of cygwin adding /cygdrive/<driveletter>
$cwd =~ s/\/cygdrive\/(.)/$1:/;
my $cmd = "$exe -P \"Default User\" file:///$cwd/quit.html";
print "cmd = $cmd\n";
print "$ntimes times\n";
# Setup run environment
$ENV{"NS_TIMELINE_ENABLE"} = 1;
$ENV{"NS_TIMELINE_LOG_FILE"} = $timelinelog;
$ENV{"XPCOM_DEBUG_BREAK"} = "warn";
unlink $timelinelog;
my $i;
my @runtimes = ();
for($i = 0; $i < $ntimes; $i++) {
# Run the command.
system($cmd);
# find the time taken from the TIMELINE LOG
my $F;
open(F, "< $timelinelog") || die "no timeline log ($timelinelog) found";
while(<F>) {
if (/^(.*): \.\.\.main1$/) {
my $t = $1 + 0;
push @runtimes, $t;
print "[$i] startup time : $t sec\n";
last;
}
}
close(F);
# Cleanup
unlink $timelinelog;
}
# Compute final number. Skip first run and average the rest.
my $sum = 0;
shift @runtimes;
foreach $i (@runtimes) {
$sum += $i;
}
printf "Average startup time : %8.4f secs (%d trials - %s)\n", $sum/($ntimes-1), $ntimes-1, join(" ", @runtimes);
}