1
1
import { fork } from "child_process" ;
2
2
import * as fs from "fs" ;
3
3
import * as yargs from "yargs" ;
4
- import { BenchmarkInfo , BenchmarkType , TBenchmark } from "./benchmarksCommon" ;
5
- import { CPUBenchmarkPuppeteer , MemBenchmarkPuppeteer , TBenchmarkPuppeteer } from "./benchmarksPuppeteer" ;
6
- import { CPUBenchmarkPlaywright , MemBenchmarkPlaywright , TBenchmarkPlaywright } from "./benchmarksPlaywright" ;
7
- import { CPUBenchmarkWebdriver } from "./benchmarksWebdriver" ;
8
- import { BenchmarkDriverOptions , BenchmarkOptions , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common" ;
4
+ import { BenchmarkInfo , benchmarkInfos , BenchmarkType , CPUBenchmarkInfo , MemBenchmarkInfo , StartupBenchmarkInfo } from "./benchmarksCommon" ;
5
+ import { StartupBenchmarkResult } from "./benchmarksLighthouse" ;
6
+ import { BenchmarkOptions , BENCHMARK_RUNNER , config , ErrorAndWarning , FrameworkData , initializeFrameworks } from "./common" ;
9
7
import { writeResults } from "./writeResults" ;
10
- import { benchmarks , TBenchmarkImplementation } from "./benchmarkConfiguration" ;
11
- import { BenchmarkLighthouse , StartupBenchmarkResult } from "./benchmarksLighthouse" ;
12
- import { CPUBenchmarkWebdriverCDP } from "./benchmarksWebdriverCDP" ;
13
8
14
9
function forkAndCallBenchmark (
15
10
framework : FrameworkData ,
16
- benchmark : CPUBenchmarkWebdriver | TBenchmarkPuppeteer | BenchmarkLighthouse ,
11
+ benchmarkInfo : BenchmarkInfo ,
17
12
benchmarkOptions : BenchmarkOptions
18
13
) : Promise < ErrorAndWarning > {
19
14
return new Promise ( ( resolve , reject ) => {
20
15
let forkedRunner = null ;
21
- if ( benchmark instanceof BenchmarkLighthouse ) {
16
+ if ( benchmarkInfo . type === BenchmarkType . STARTUP_MAIN ) {
22
17
forkedRunner = "dist/forkedBenchmarkRunnerLighthouse.js" ;
23
- } else if ( benchmark instanceof CPUBenchmarkWebdriverCDP ) {
18
+ } else if ( config . BENCHMARK_RUNNER == BENCHMARK_RUNNER . WEBDRIVER_CDP ) {
24
19
forkedRunner = "dist/forkedBenchmarkRunnerWebdriverCDP.js" ;
25
- } else if ( benchmark instanceof CPUBenchmarkPlaywright || benchmark instanceof MemBenchmarkPlaywright ) {
20
+ } else if ( config . BENCHMARK_RUNNER == BENCHMARK_RUNNER . PLAYWRIGHT ) {
26
21
forkedRunner = "dist/forkedBenchmarkRunnerPlaywright.js" ;
27
- } else if ( benchmark instanceof CPUBenchmarkPuppeteer || benchmark instanceof MemBenchmarkPuppeteer ) {
28
- forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js" ;
29
- } else {
22
+ } else if ( config . BENCHMARK_RUNNER == BENCHMARK_RUNNER . WEBDRIVER ) {
30
23
forkedRunner = "dist/forkedBenchmarkRunnerWebdriver.js" ;
24
+ } else {
25
+ forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js" ;
31
26
}
32
27
console . log ( "forking " , forkedRunner ) ;
33
28
const forked = fork ( forkedRunner ) ;
34
29
if ( config . LOG_DETAILS ) console . log ( "FORKING: forked child process" ) ;
35
30
forked . send ( {
36
31
config,
37
32
framework,
38
- benchmarkId : benchmark . benchmarkInfo . id ,
33
+ benchmarkId : benchmarkInfo . id ,
39
34
benchmarkOptions,
40
35
} ) ;
41
36
forked . on ( "message" , async ( msg : ErrorAndWarning ) => {
@@ -57,7 +52,7 @@ function forkAndCallBenchmark(
57
52
58
53
async function runBenchmakLoopStartup (
59
54
framework : FrameworkData ,
60
- benchmark : BenchmarkLighthouse ,
55
+ benchmarkInfo : StartupBenchmarkInfo ,
61
56
benchmarkOptions : BenchmarkOptions
62
57
) : Promise < { errors : String [ ] ; warnings : String [ ] } > {
63
58
let warnings : String [ ] = [ ] ;
@@ -70,12 +65,12 @@ async function runBenchmakLoopStartup(
70
65
let retries = 0 ;
71
66
let done = 0 ;
72
67
73
- console . log ( "runBenchmakLoopStartup" , framework , benchmark ) ;
68
+ console . log ( "runBenchmakLoopStartup" , framework , benchmarkInfo ) ;
74
69
75
70
76
71
while ( done < count ) {
77
- console . log ( "FORKING: " , benchmark . benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
78
- let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
72
+ console . log ( "FORKING: " , benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
73
+ let res = await forkAndCallBenchmark ( framework , benchmarkInfo , benchmarkOptions ) ;
79
74
if ( Array . isArray ( res . result ) ) {
80
75
results = results . concat ( res . result as StartupBenchmarkResult [ ] ) ;
81
76
} else results . push ( res . result ) ;
@@ -86,7 +81,7 @@ async function runBenchmakLoopStartup(
86
81
retries ++ ;
87
82
if ( retries == 3 ) break ;
88
83
} else {
89
- errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . benchmarkInfo . id } failed: ` + res . error ) ;
84
+ errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmarkInfo . id } failed: ` + res . error ) ;
90
85
break ;
91
86
}
92
87
}
@@ -95,7 +90,7 @@ async function runBenchmakLoopStartup(
95
90
console . log ( "******* result " , results ) ;
96
91
await writeResults ( config , {
97
92
framework : framework ,
98
- benchmark : benchmark ,
93
+ benchmark : benchmarkInfo ,
99
94
results : results ,
100
95
type : BenchmarkType . STARTUP
101
96
} ) ;
@@ -106,7 +101,7 @@ async function runBenchmakLoopStartup(
106
101
107
102
async function runBenchmakLoop (
108
103
framework : FrameworkData ,
109
- benchmark : CPUBenchmarkWebdriver | TBenchmarkPuppeteer ,
104
+ benchmarkInfo : CPUBenchmarkInfo | MemBenchmarkInfo ,
110
105
benchmarkOptions : BenchmarkOptions
111
106
) : Promise < { errors : String [ ] ; warnings : String [ ] } > {
112
107
let warnings : String [ ] = [ ] ;
@@ -115,23 +110,23 @@ async function runBenchmakLoop(
115
110
let results : Array < number > = [ ] ;
116
111
let count = 0 ;
117
112
118
- if ( benchmark . type == BenchmarkType . CPU ) {
113
+ if ( benchmarkInfo . type == BenchmarkType . CPU ) {
119
114
count = benchmarkOptions . numIterationsForCPUBenchmarks ;
120
115
// FIXME
121
- benchmarkOptions . batchSize = config . ALLOW_BATCHING && ( benchmark . benchmarkInfo as any ) . allowBatching ? count : 1 ;
122
- } else if ( benchmark . type == BenchmarkType . MEM ) {
116
+ benchmarkOptions . batchSize = config . ALLOW_BATCHING && benchmarkInfo . allowBatching ? count : 1 ;
117
+ } else if ( benchmarkInfo . type == BenchmarkType . MEM ) {
123
118
count = benchmarkOptions . numIterationsForMemBenchmarks ;
124
119
benchmarkOptions . batchSize = 1 ;
125
120
}
126
121
127
122
let retries = 0 ;
128
123
129
- console . log ( "runBenchmakLoop" , framework , benchmark ) ;
124
+ console . log ( "runBenchmakLoop" , framework , benchmarkInfo ) ;
130
125
131
126
while ( results . length < count ) {
132
127
benchmarkOptions . batchSize = Math . min ( benchmarkOptions . batchSize , count - results . length ) ;
133
- console . log ( "FORKING: " , benchmark . benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
134
- let res = await forkAndCallBenchmark ( framework , benchmark , benchmarkOptions ) ;
128
+ console . log ( "FORKING: " , benchmarkInfo . id , " BatchSize " , benchmarkOptions . batchSize ) ;
129
+ let res = await forkAndCallBenchmark ( framework , benchmarkInfo , benchmarkOptions ) ;
135
130
if ( Array . isArray ( res . result ) ) {
136
131
results = results . concat ( res . result as number [ ] ) ;
137
132
} else results . push ( res . result ) ;
@@ -142,12 +137,12 @@ async function runBenchmakLoop(
142
137
retries ++ ;
143
138
if ( retries == 3 ) break ;
144
139
} else {
145
- errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmark . benchmarkInfo . id } failed: ` + res . error ) ;
140
+ errors . push ( `Executing ${ framework . uri } and benchmark ${ benchmarkInfo . id } failed: ` + res . error ) ;
146
141
break ;
147
142
}
148
143
}
149
144
}
150
- if ( benchmark . type == BenchmarkType . CPU ) {
145
+ if ( benchmarkInfo . type == BenchmarkType . CPU ) {
151
146
console . log ( "CPU results before: " , results ) ;
152
147
( results as number [ ] ) . sort ( ( a : number , b : number ) => a - b ) ;
153
148
results = results . slice ( 0 , config . NUM_ITERATIONS_FOR_BENCHMARK_CPU ) ;
@@ -157,23 +152,19 @@ async function runBenchmakLoop(
157
152
console . log ( "******* result " , results ) ;
158
153
await writeResults ( config , {
159
154
framework : framework ,
160
- benchmark : benchmark . benchmarkInfo ,
155
+ benchmark : benchmarkInfo ,
161
156
results : results ,
162
- type : benchmark . type as typeof BenchmarkType . CPU | BenchmarkType . MEM
157
+ type : benchmarkInfo . type as typeof BenchmarkType . CPU | BenchmarkType . MEM
163
158
} ) ;
164
159
return { errors, warnings } ;
165
160
// } else {
166
161
// return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
167
162
}
168
163
169
- async function runBench ( runFrameworks : FrameworkData [ ] , benchmarkNames : string [ ] ) {
164
+ async function runBench ( runFrameworks : FrameworkData [ ] , benchmarkInfos : BenchmarkInfo [ ] ) {
170
165
let errors : String [ ] = [ ] ;
171
166
let warnings : String [ ] = [ ] ;
172
167
173
- let runBenchmarks : Array < TBenchmarkImplementation > = benchmarks . filter ( ( b ) =>
174
- benchmarkNames . some ( ( name ) => b . benchmarkInfo . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
175
- ) ;
176
-
177
168
let restart : string = undefined ;
178
169
let index = runFrameworks . findIndex ( ( f ) => f . fullNameWithKeyedAndVersion === restart ) ;
179
170
if ( index > - 1 ) {
@@ -186,13 +177,14 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
186
177
) ;
187
178
console . log (
188
179
"Benchmarks that will be run" ,
189
- runBenchmarks . map ( ( b ) => b . benchmarkInfo . id )
180
+ benchmarkInfos . map ( ( b ) => b . id )
190
181
) ;
191
182
192
183
console . log ( "HEADLESS*** " , args . headless ) ;
193
184
194
185
let benchmarkOptions : BenchmarkOptions = {
195
186
port : config . PORT . toFixed ( ) ,
187
+ HOST : config . HOST ,
196
188
remoteDebuggingPort : config . REMOTE_DEBUGGING_PORT ,
197
189
chromePort : config . CHROME_PORT ,
198
190
headless : args . headless ,
@@ -203,13 +195,20 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
203
195
batchSize : 1 ,
204
196
} ;
205
197
198
+ console . log ( "benchmarkOptions" , benchmarkOptions ) ;
199
+
206
200
for ( let i = 0 ; i < runFrameworks . length ; i ++ ) {
207
- for ( let j = 0 ; j < runBenchmarks . length ; j ++ ) {
201
+ for ( let j = 0 ; j < benchmarkInfos . length ; j ++ ) {
208
202
try {
209
- console . log ( "****** runBenchmarks[j].type" , runBenchmarks [ j ] . type , runBenchmarks [ j ] . type == BenchmarkType . STARTUP_MAIN )
210
- let result = ( runBenchmarks [ j ] . type == BenchmarkType . STARTUP_MAIN ) ?
211
- await runBenchmakLoopStartup ( runFrameworks [ i ] , runBenchmarks [ j ] as BenchmarkLighthouse , benchmarkOptions )
212
- : await runBenchmakLoop ( runFrameworks [ i ] , runBenchmarks [ j ] as TBenchmarkPuppeteer | CPUBenchmarkWebdriver , benchmarkOptions ) ;
203
+ let result ;
204
+
205
+ if ( benchmarkInfos [ j ] . type == BenchmarkType . STARTUP_MAIN ) {
206
+ result = await runBenchmakLoopStartup ( runFrameworks [ i ] , benchmarkInfos [ j ] as StartupBenchmarkInfo , benchmarkOptions )
207
+ } else if ( benchmarkInfos [ j ] . type == BenchmarkType . CPU ) {
208
+ result = await runBenchmakLoop ( runFrameworks [ i ] , benchmarkInfos [ j ] as CPUBenchmarkInfo , benchmarkOptions ) ;
209
+ } else {
210
+ result = await runBenchmakLoop ( runFrameworks [ i ] , benchmarkInfos [ j ] as MemBenchmarkInfo , benchmarkOptions ) ;
211
+ }
213
212
errors = errors . concat ( result . errors ) ;
214
213
warnings = warnings . concat ( result . warnings ) ;
215
214
} catch ( e ) {
@@ -252,18 +251,37 @@ let args: any = yargs(process.argv)
252
251
. help ( "help" )
253
252
. boolean ( "headless" ) . default ( "headless" , false )
254
253
. boolean ( "smoketest" )
254
+ . string ( "runner" ) . default ( "runner" , "playwright" )
255
255
. array ( "framework" )
256
256
. array ( "benchmark" )
257
257
. string ( "chromeBinary" ) . argv ;
258
258
259
+ let runner = args . runner ;
260
+ if ( [ BENCHMARK_RUNNER . WEBDRIVER_CDP , BENCHMARK_RUNNER . WEBDRIVER , BENCHMARK_RUNNER . PLAYWRIGHT , BENCHMARK_RUNNER . PUPPETEER ] . includes ( runner ) ) {
261
+ console . log ( `INFO: Using ${ runner } benchmark runner` )
262
+ config . BENCHMARK_RUNNER = runner ;
263
+ } else {
264
+ console . log ( "ERROR: argument driver has illegal value " + runner , [ BENCHMARK_RUNNER . WEBDRIVER_CDP , BENCHMARK_RUNNER . WEBDRIVER , BENCHMARK_RUNNER . PLAYWRIGHT , BENCHMARK_RUNNER . PUPPETEER ] ) ;
265
+ process . exit ( 1 ) ;
266
+ }
267
+
259
268
let allArgs = args . _ . length <= 2 ? [ ] : args . _ . slice ( 2 , args . _ . length ) ;
260
269
let frameworkArgument = ! args . framework ? allArgs : args . framework ;
261
270
console . log ( "args" , args , "allArgs" , allArgs ) ;
262
271
272
+ if ( process . env . HOST ) {
273
+ config . HOST = process . env . HOST ;
274
+ console . log ( `INFO: Using host ${ config . HOST } instead of localhost` ) ;
275
+ }
276
+
263
277
async function main ( ) {
264
- let runBenchmarks = ( args . benchmark && args . benchmark . length > 0 ? args . benchmark : [ "" ] ) . map ( ( v : string ) => v . toString ( ) ) ;
278
+ let runBenchmarksArgs : string [ ] = ( args . benchmark && args . benchmark . length > 0 ) ? args . benchmark : [ "" ] ;
279
+ let runBenchmarks : Array < BenchmarkInfo > = Object . values ( benchmarkInfos ) . filter ( ( b ) =>
280
+ runBenchmarksArgs . some ( ( name ) => b . id . toLowerCase ( ) . indexOf ( name ) > - 1 )
281
+ ) ;
282
+
283
+
265
284
let runFrameworks : FrameworkData [ ] ;
266
-
267
285
let matchesDirectoryArg = ( directoryName : string ) =>
268
286
frameworkArgument . length == 0 || frameworkArgument . some ( ( arg : string ) => arg == directoryName ) ;
269
287
runFrameworks = await initializeFrameworks ( matchesDirectoryArg ) ;
@@ -297,4 +315,4 @@ main()
297
315
. catch ( ( error ) => {
298
316
console . log ( "run was not completely sucessful" , error ) ;
299
317
process . exit ( 1 ) ;
300
- } ) ;
318
+ } ) ;
0 commit comments