forked from WebKit/WebKit-http
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun-testmem
291 lines (251 loc) · 8.64 KB
/
run-testmem
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
#!/usr/bin/env ruby
# Copyright (C) 2018 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
require 'fileutils'
require 'pathname'
require 'open3'
require "JSON"
require 'getoptlong'
def usage
puts "run-testmem [options]"
puts "--build-dir (-b) Pass in a path to your build directory, e.g, WebKitBuild/Release"
puts "--verbose (-v) Print more information as the benchmark runs"
puts "--count (-c) Number of outer iterations to run the benchmark for"
puts "--dry (-d) Print shell output that can be run as a bash script on a different device. When using this option, provide the --script-path and --build-dir options"
puts "--script-path (-s) The path to the directory where you expect the testmem tests to live. Use this when doing a dry run with --dry"
puts "--parse (-p) After executing the dry run, capture its stdout and write it to a file. Pass the path to that file for this option and run-testmem will compute the results of the benchmark run"
puts "--help (-h) Print this message"
end
THIS_SCRIPT_PATH = Pathname.new(__FILE__).realpath
SCRIPTS_PATH = THIS_SCRIPT_PATH.dirname
$buildDir = nil
$verbose = false
$outerIterations = 3
$dryRun = false
$scriptPath = nil
$parsePath = nil
GetoptLong.new(["--build-dir", "-b", GetoptLong::REQUIRED_ARGUMENT],
["--verbose", "-v", GetoptLong::NO_ARGUMENT],
["--count", "-c", GetoptLong::REQUIRED_ARGUMENT],
["--dry", "-d", GetoptLong::NO_ARGUMENT],
["--script-path", "-s", GetoptLong::REQUIRED_ARGUMENT],
["--parse", "-p", GetoptLong::REQUIRED_ARGUMENT],
["--help", "-h", GetoptLong::NO_ARGUMENT],
).each {
| opt, arg |
case opt
when "--build-dir"
$buildDir = arg
when "--verbose"
$verbose = true
when "--count"
$outerIterations = arg.to_i
if $outerIterations < 1
puts "--count must be > 0"
exit 1
end
when "--dry"
$dryRun = true
when "--script-path"
$scriptPath = arg
when "--parse"
$parsePath = arg
when "--help"
usage
exit 1
end
}
if $scriptPath && !$dryRun
puts "--script-path is only supported when you are doing a --dry run"
exit 1
end
def getBuildDirectory
if $buildDir != nil
return $buildDir
end
command = SCRIPTS_PATH.join("webkit-build-directory").to_s
command += " --release"
command += " --executablePath"
output = `#{command}`.split("\n")
if !output.length
puts "Error: could not find release WebKitBuild"
exit 1
end
output = output[0]
$buildDir = Pathname.new(output).to_s
$buildDir
end
def getTestmemPath
path = Pathname.new(getBuildDirectory).join("testmem").to_s
if !File.exists?(path) && !$dryRun
puts "Error: no testmem binary found in <build>/Release"
exit 1
end
path
end
def iterationCount(path)
iterationMap = {
"air" => 4,
"basic" => 5,
"splay" => 10,
"hash-map" => 5,
"box2d" => 3,
}
name = File.basename(path, ".js")
iterationMap[name] || 20
end
def getTests
dirPath = Pathname.new(SCRIPTS_PATH).join("../../PerformanceTests/testmem")
files = []
Dir.foreach(dirPath) {
| filename |
next unless filename =~ /\.js$/
filePath = dirPath.join(filename).to_s
filePath = Pathname.new($scriptPath).join(filename).to_s if $scriptPath
files.push([filePath, iterationCount(filePath)])
}
files.sort_by { | (path) | File.basename(path) }
end
def processRunOutput(stdout, path)
time, peakFootprint, footprintAtEnd = stdout.split("\n")
raise unless time.slice!("time:")
raise unless peakFootprint.slice!("peak footprint:")
raise unless footprintAtEnd.slice!("footprint at end:")
time = time.to_f
peakFootprint = peakFootprint.to_f
footprintAtEnd = footprintAtEnd.to_f
if $verbose
puts path
puts "time: #{time}"
puts "peak footprint: #{peakFootprint/1024/1024} MB"
puts "end footprint: #{footprintAtEnd/1024/1024} MB\n"
end
{"time"=>time, "peak"=>peakFootprint, "end"=>footprintAtEnd}
end
def runTest(path, iters)
command = "#{getTestmemPath} #{path} #{iters}"
environment = {
"DYLD_FRAMEWORK_PATH" => getBuildDirectory,
"JSC_useJIT" => "false",
"JSC_useRegExpJIT" => "false",
}
if $dryRun
environment.each { | key, value |
command = "#{key}=#{value} #{command}"
}
puts "echo \"#{command}\""
puts command
return
end
stdout, stderr, exitCode = Open3.capture3(environment, command)
if $verbose
puts stdout
puts stderr
end
if exitCode != 0
puts "testmem failed to run"
puts stdout
puts stderr
exit 1
end
processRunOutput(stdout, path)
end
def geomean(arr)
score = arr.inject(1.0, :*)
score ** (1.0 / arr.length)
end
def mean(arr)
sum = arr.inject(0.0, :+)
sum / arr.length
end
def processScores(scores)
peakScore = []
endScore = []
timeScore = []
scores.each { | key, value |
endAvg = mean(value.map { | element | element["end"] })
peakAvg = mean(value.map { | element | element["peak"] })
timeAvg = mean(value.map { | element | element["time"] })
peakScore.push(peakAvg)
endScore.push(endAvg)
timeScore.push(timeAvg)
puts File.basename(key, ".js")
puts " end: #{(endAvg/1024/1024).round(4)} MB"
puts " peak: #{(peakAvg/1024/1024).round(4)} MB"
puts " time: #{(timeAvg*1000).round(2)} ms\n"
}
endScore = geomean(endScore)
peakScore = geomean(peakScore)
timeScore = geomean(timeScore)
puts
puts "end score: #{(endScore/1024/1024).round(4)} MB"
puts "peak score: #{(peakScore/1024/1024).round(4)} MB\n"
puts "total memory score: #{(geomean([endScore, peakScore])/1024/1024).round(4)} MB"
puts "time score: #{(timeScore*1000).round(2)} ms\n\n"
puts JSON.pretty_generate(scores) if $verbose
end
def run
tests = getTests
scores = {}
tests.each { | (path) | scores[path] = [] }
count = $outerIterations
if $dryRun
(0..(count-1)).each { | currentIter |
tests.each { | (path, iters) |
runTest(path, iters)
}
}
return
end
(0..(count-1)).each { | currentIter |
tests.each { | (path, iters) |
statusToPrint = "iteration #{currentIter + 1}: #{File.basename(path, ".js")}"
print "#{statusToPrint}\r"
scores[path].push(runTest(path, iters))
print "#{" ".rjust(statusToPrint.length)}\r"
}
}
processScores(scores)
end
def parseResultOfDryRun(path)
contents = IO.read(path).split("\n")
if !contents.length || contents.length % 4 != 0
puts "Bad input, expect multiple of 4 number of lines from output of running the result of --dry"
exit 1
end
scores = {}
i = 0
while i < contents.length
path = contents[i + 0].split(" ")[-2]
scores[path] = [] if !scores[path]
stdout = [contents[i + 1], contents[i + 2], contents[i + 3]].join("\n")
scores[path].push(processRunOutput(stdout, path))
i += 4
end
processScores(scores)
end
if $parsePath
parseResultOfDryRun($parsePath)
else
run
end