1
- import yargs from 'yargs' ;
2
- import { BenchmarkOptions , BENCHMARK_RUNNER , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common.js" ;
1
+ import yargs from "yargs" ;
2
+ import {
3
+ BenchmarkOptions ,
4
+ BENCHMARK_RUNNER ,
5
+ config ,
6
+ ErrorAndWarning ,
7
+ FrameworkData ,
8
+ initializeFrameworks ,
9
+ } from "./common.js" ;
3
10
import { fork } from "child_process" ;
4
11
import * as fs from "fs" ;
5
- import { BenchmarkInfo , benchmarkInfos , BenchmarkType , CPUBenchmarkInfo , cpuBenchmarkInfosArray , CPUBenchmarkResult , MemBenchmarkInfo , StartupBenchmarkInfo } from "./benchmarksCommon.js" ;
12
+ import {
13
+ BenchmarkInfo ,
14
+ benchmarkInfos ,
15
+ BenchmarkType ,
16
+ CPUBenchmarkInfo ,
17
+ cpuBenchmarkInfosArray ,
18
+ CPUBenchmarkResult ,
19
+ MemBenchmarkInfo ,
20
+ StartupBenchmarkInfo ,
21
+ } from "./benchmarksCommon.js" ;
6
22
import { StartupBenchmarkResult } from "./benchmarksLighthouse.js" ;
7
23
import { writeResults } from "./writeResults.js" ;
8
- import { PlausibilityCheck , parseCPUTrace } from ' ./timeline.js' ;
24
+ import { PlausibilityCheck , parseCPUTrace } from " ./timeline.js" ;
9
25
10
26
function forkAndCallBenchmark (
11
27
framework : FrameworkData ,
12
28
benchmarkInfo : BenchmarkInfo ,
13
29
benchmarkOptions : BenchmarkOptions
14
- ) : Promise < ErrorAndWarning < number | CPUBenchmarkResult | StartupBenchmarkResult > > {
30
+ ) : Promise < ErrorAndWarning < number | CPUBenchmarkResult | StartupBenchmarkResult > > {
15
31
return new Promise ( ( resolve , reject ) => {
16
32
let forkedRunner = null ;
17
33
if ( benchmarkInfo . type === BenchmarkType . STARTUP_MAIN ) {
@@ -27,7 +43,7 @@ function forkAndCallBenchmark(
27
43
} else {
28
44
forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js" ;
29
45
}
30
- console . log ( "forking " , forkedRunner ) ;
46
+ console . log ( "forking " , forkedRunner ) ;
31
47
const forked = fork ( forkedRunner ) ;
32
48
if ( config . LOG_DETAILS ) console . log ( "FORKING: forked child process" ) ;
33
49
forked . send ( {
@@ -36,10 +52,13 @@ function forkAndCallBenchmark(
36
52
benchmarkId : benchmarkInfo . id ,
37
53
benchmarkOptions,
38
54
} ) ;
39
- forked . on ( "message" , ( msg : ErrorAndWarning < number | CPUBenchmarkResult | StartupBenchmarkResult > ) => {
55
+ forked . on (
56
+ "message" ,
57
+ ( msg : ErrorAndWarning < number | CPUBenchmarkResult | StartupBenchmarkResult > ) => {
40
58
if ( config . LOG_DETAILS ) console . log ( "FORKING: main process got message from child" , msg ) ;
41
59
resolve ( msg ) ;
42
- } ) ;
60
+ }
61
+ ) ;
43
62
forked . on ( "close" , ( msg ) => {
44
63
if ( config . LOG_DETAILS ) console . log ( "FORKING: child closed" , msg ) ;
45
64
} ) ;
@@ -70,7 +89,6 @@ async function runBenchmakLoopStartup(
70
89
71
90
console . log ( "runBenchmakLoopStartup" , framework , benchmarkInfo ) ;
72
91
73
-
74
92
while ( done < count ) {
75
93
console . log ( "FORKING: " , benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
76
94
let res = await forkAndCallBenchmark ( framework , benchmarkInfo , benchmarkOptions ) ;
@@ -96,7 +114,7 @@ async function runBenchmakLoopStartup(
96
114
framework : framework ,
97
115
benchmark : benchmarkInfo ,
98
116
results : results ,
99
- type : BenchmarkType . STARTUP
117
+ type : BenchmarkType . STARTUP ,
100
118
} ) ;
101
119
}
102
120
return { errors, warnings } ;
@@ -106,14 +124,14 @@ async function runBenchmakLoopStartup(
106
124
107
125
async function runBenchmakLoop (
108
126
framework : FrameworkData ,
109
- benchmarkInfo : CPUBenchmarkInfo | MemBenchmarkInfo ,
127
+ benchmarkInfo : CPUBenchmarkInfo | MemBenchmarkInfo ,
110
128
benchmarkOptions : BenchmarkOptions ,
111
129
plausibilityCheck : PlausibilityCheck
112
130
) : Promise < { errors : string [ ] ; warnings : string [ ] } > {
113
131
let warnings : string [ ] = [ ] ;
114
132
let errors : string [ ] = [ ] ;
115
133
116
- let results : Array < CPUBenchmarkResult | number > = [ ] ;
134
+ let results : Array < CPUBenchmarkResult | number > = [ ] ;
117
135
let count = 0 ;
118
136
119
137
if ( benchmarkInfo . type == BenchmarkType . CPU ) {
@@ -133,8 +151,8 @@ async function runBenchmakLoop(
133
151
console . log ( "FORKING: " , benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
134
152
let res = await forkAndCallBenchmark ( framework , benchmarkInfo , benchmarkOptions ) ;
135
153
if ( Array . isArray ( res . result ) ) {
136
- results = results . concat ( res . result as number [ ] | CPUBenchmarkResult [ ] ) ;
137
- } else if ( res . result !== undefined ) {
154
+ results = results . concat ( res . result as number [ ] | CPUBenchmarkResult [ ] ) ;
155
+ } else if ( res . result !== undefined ) {
138
156
results . push ( res . result ) ;
139
157
}
140
158
warnings = warnings . concat ( res . warnings ) ;
@@ -151,7 +169,9 @@ async function runBenchmakLoop(
151
169
}
152
170
if ( benchmarkInfo . type == BenchmarkType . CPU ) {
153
171
console . log ( "CPU results before: " , results ) ;
154
- ( results as CPUBenchmarkResult [ ] ) . sort ( ( a : CPUBenchmarkResult , b : CPUBenchmarkResult ) => a . total - b . total ) ;
172
+ // (results as CPUBenchmarkResult[]).sort(
173
+ // (a: CPUBenchmarkResult, b: CPUBenchmarkResult) => a.total - b.total
174
+ // );
155
175
// results = results.slice(0, config.NUM_ITERATIONS_FOR_BENCHMARK_CPU);
156
176
// console.log("CPU results after: ", results)
157
177
}
@@ -163,24 +183,27 @@ async function runBenchmakLoop(
163
183
framework : framework ,
164
184
benchmark : benchmarkInfo ,
165
185
results : results as CPUBenchmarkResult [ ] ,
166
- type : BenchmarkType . CPU
186
+ type : BenchmarkType . CPU ,
167
187
} ) ;
168
188
} else {
169
189
await writeResults ( benchmarkOptions . resultsDirectory , {
170
190
framework : framework ,
171
191
benchmark : benchmarkInfo ,
172
192
results : results as number [ ] ,
173
- type : BenchmarkType . MEM
193
+ type : BenchmarkType . MEM ,
174
194
} ) ;
175
195
}
176
-
177
196
}
178
197
return { errors, warnings } ;
179
198
// } else {
180
199
// return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
181
200
}
182
201
183
- async function runBench ( runFrameworks : FrameworkData [ ] , benchmarkInfos : BenchmarkInfo [ ] , benchmarkOptions : BenchmarkOptions ) {
202
+ async function runBench (
203
+ runFrameworks : FrameworkData [ ] ,
204
+ benchmarkInfos : BenchmarkInfo [ ] ,
205
+ benchmarkOptions : BenchmarkOptions
206
+ ) {
184
207
let errors : string [ ] = [ ] ;
185
208
let warnings : string [ ] = [ ] ;
186
209
@@ -258,11 +281,15 @@ let args: any = yargs(process.argv)
258
281
"$0 [--framework Framework1 Framework2 ...] [--benchmark Benchmark1 Benchmark2 ...] [--chromeBinary path] \n or: $0 [directory1] [directory2] .. [directory3]"
259
282
)
260
283
. help ( "help" )
261
- . boolean ( "headless" ) . default ( "headless" , false )
284
+ . boolean ( "headless" )
285
+ . default ( "headless" , false )
262
286
. boolean ( "smoketest" )
263
- . boolean ( "nothrottling" ) . default ( "nothrottling" , false )
264
- . string ( "runner" ) . default ( "runner" , "puppeteer" )
265
- . string ( "browser" ) . default ( "browser" , "chrome" )
287
+ . boolean ( "nothrottling" )
288
+ . default ( "nothrottling" , false )
289
+ . string ( "runner" )
290
+ . default ( "runner" , "puppeteer" )
291
+ . string ( "browser" )
292
+ . default ( "browser" , "chrome" )
266
293
. array ( "framework" )
267
294
. array ( "benchmark" )
268
295
. number ( "count" )
@@ -271,32 +298,45 @@ let args: any = yargs(process.argv)
271
298
console . log ( "args" , args ) ;
272
299
273
300
let runner = args . runner ;
274
- if ( [ BENCHMARK_RUNNER . WEBDRIVER_CDP , BENCHMARK_RUNNER . WEBDRIVER , BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME ,
301
+ if (
302
+ [
303
+ BENCHMARK_RUNNER . WEBDRIVER_CDP ,
304
+ BENCHMARK_RUNNER . WEBDRIVER ,
305
+ BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME ,
275
306
BENCHMARK_RUNNER . PLAYWRIGHT ,
276
- BENCHMARK_RUNNER . PUPPETEER ] . includes ( runner ) ) {
277
- console . log ( `INFO: Using ${ runner } benchmark runner` )
307
+ BENCHMARK_RUNNER . PUPPETEER ,
308
+ ] . includes ( runner )
309
+ ) {
310
+ console . log ( `INFO: Using ${ runner } benchmark runner` ) ;
278
311
config . BENCHMARK_RUNNER = runner ;
279
312
} else {
280
- console . log ( "ERROR: argument driver has illegal value " + runner , [ BENCHMARK_RUNNER . WEBDRIVER_CDP , BENCHMARK_RUNNER . WEBDRIVER , BENCHMARK_RUNNER . PLAYWRIGHT , BENCHMARK_RUNNER . PUPPETEER ] ) ;
313
+ console . log ( "ERROR: argument driver has illegal value " + runner , [
314
+ BENCHMARK_RUNNER . WEBDRIVER_CDP ,
315
+ BENCHMARK_RUNNER . WEBDRIVER ,
316
+ BENCHMARK_RUNNER . PLAYWRIGHT ,
317
+ BENCHMARK_RUNNER . PUPPETEER ,
318
+ ] ) ;
281
319
process . exit ( 1 ) ;
282
320
}
283
321
console . log ( "HEADLESS*** " , args . headless ) ;
284
322
285
323
let benchmarkOptions : BenchmarkOptions = {
286
324
port : 8080 ,
287
- host : ' localhost' ,
325
+ host : " localhost" ,
288
326
browser : args . browser ,
289
327
remoteDebuggingPort : 9999 ,
290
328
chromePort : 9998 ,
291
329
headless : args . headless ,
292
330
chromeBinaryPath : args . chromeBinary ,
293
- numIterationsForCPUBenchmarks : config . NUM_ITERATIONS_FOR_BENCHMARK_CPU + config . NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT ,
331
+ numIterationsForCPUBenchmarks :
332
+ config . NUM_ITERATIONS_FOR_BENCHMARK_CPU +
333
+ config . NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT ,
294
334
numIterationsForMemBenchmarks : config . NUM_ITERATIONS_FOR_BENCHMARK_MEM ,
295
335
numIterationsForStartupBenchmark : config . NUM_ITERATIONS_FOR_BENCHMARK_STARTUP ,
296
336
batchSize : 1 ,
297
337
resultsDirectory : "results" ,
298
338
tracesDirectory : "traces" ,
299
- allowThrottling : ! args . nothrottling
339
+ allowThrottling : ! args . nothrottling ,
300
340
} ;
301
341
302
342
if ( args . count ) {
@@ -306,7 +346,6 @@ if (args.count) {
306
346
benchmarkOptions . numIterationsForStartupBenchmark = args . count ;
307
347
}
308
348
309
-
310
349
let allArgs = args . _ . length <= 2 ? [ ] : args . _ . slice ( 2 , args . _ . length ) ;
311
350
let frameworkArgument = ! args . framework ? allArgs : args . framework ;
312
351
console . log ( "args" , args , "allArgs" , allArgs ) ;
@@ -317,36 +356,43 @@ if (process.env.HOST) {
317
356
}
318
357
console . log ( "benchmarkOptions" , benchmarkOptions ) ;
319
358
320
- let runBenchmarksArgs : string [ ] = ( args . benchmark && args . benchmark . length > 0 ) ? args . benchmark : [ "" ] ;
321
- let runBenchmarks : Array < BenchmarkInfo > = benchmarkInfos . filter ( ( b ) =>
359
+ let runBenchmarksArgs : string [ ] =
360
+ args . benchmark && args . benchmark . length > 0 ? args . benchmark : [ "" ] ;
361
+ let runBenchmarks : Array < BenchmarkInfo > = benchmarkInfos . filter (
362
+ ( b ) =>
322
363
// afterframe currently only targets CPU benchmarks
323
- ( config . BENCHMARK_RUNNER !== BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME || b . type == BenchmarkType . CPU ) &&
364
+ ( config . BENCHMARK_RUNNER !== BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME ||
365
+ b . type == BenchmarkType . CPU ) &&
324
366
runBenchmarksArgs . some ( ( name ) => b . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
325
367
) ;
326
368
327
369
let runFrameworks : FrameworkData [ ] ;
328
370
let matchesDirectoryArg = ( directoryName : string ) =>
329
371
frameworkArgument . length == 0 || frameworkArgument . some ( ( arg : string ) => arg == directoryName ) ;
330
- runFrameworks = ( await initializeFrameworks ( benchmarkOptions , matchesDirectoryArg ) ) . filter ( f => f . keyed || config . BENCHMARK_RUNNER !== BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME ) ;
372
+ runFrameworks = ( await initializeFrameworks ( benchmarkOptions , matchesDirectoryArg ) ) . filter (
373
+ ( f ) => f . keyed || config . BENCHMARK_RUNNER !== BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME
374
+ ) ;
331
375
332
- console . log ( "ARGS.smotest" , args . smoketest )
376
+ console . log ( "ARGS.smotest" , args . smoketest ) ;
333
377
if ( args . smoketest ) {
334
378
config . WRITE_RESULTS = false ;
335
- benchmarkOptions . numIterationsForCPUBenchmarks = 1 ,
336
- benchmarkOptions . numIterationsForMemBenchmarks = 1 ,
337
- benchmarkOptions . numIterationsForStartupBenchmark = 1 ,
379
+ benchmarkOptions . numIterationsForCPUBenchmarks = 1 ;
380
+ benchmarkOptions . numIterationsForMemBenchmarks = 1 ;
381
+ benchmarkOptions . numIterationsForStartupBenchmark = 1 ;
338
382
config . NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT = 0 ;
339
383
config . EXIT_ON_ERROR = true ;
340
384
cpuBenchmarkInfosArray . forEach ( ( b ) => {
341
385
b . additionalNumberOfRuns = 0 ;
342
- } )
343
- console . log ( ' Using smoketest config ' , JSON . stringify ( config ) ) ;
386
+ } ) ;
387
+ console . log ( " Using smoketest config " , JSON . stringify ( config ) ) ;
344
388
}
345
389
if ( config . BENCHMARK_RUNNER == BENCHMARK_RUNNER . WEBDRIVER_AFTERFRAME ) {
346
- benchmarkOptions . resultsDirectory = "results_client_" + benchmarkOptions . browser ;
390
+ benchmarkOptions . resultsDirectory = "results_client_" + benchmarkOptions . browser ;
347
391
}
348
- if ( ! fs . existsSync ( benchmarkOptions . resultsDirectory ) ) fs . mkdirSync ( benchmarkOptions . resultsDirectory ) ;
349
- if ( ! fs . existsSync ( benchmarkOptions . tracesDirectory ) ) fs . mkdirSync ( benchmarkOptions . tracesDirectory ) ;
392
+ if ( ! fs . existsSync ( benchmarkOptions . resultsDirectory ) )
393
+ fs . mkdirSync ( benchmarkOptions . resultsDirectory ) ;
394
+ if ( ! fs . existsSync ( benchmarkOptions . tracesDirectory ) )
395
+ fs . mkdirSync ( benchmarkOptions . tracesDirectory ) ;
350
396
351
397
if ( args . help ) {
352
398
// yargs.showHelp();
@@ -363,4 +409,4 @@ main()
363
409
. catch ( ( error ) => {
364
410
console . log ( "run was not completely sucessful" , error ) ;
365
411
process . exit ( 1 ) ;
366
- } ) ;
412
+ } ) ;
0 commit comments