1
1
import { Browser , Page , CDPSession } from "playwright-core" ;
2
- import { BenchmarkType , slowDownFactor } from "./benchmarksCommon.js" ;
2
+ import { BenchmarkType , CPUBenchmarkResult , slowDownFactor } from "./benchmarksCommon.js" ;
3
3
import { benchmarks , CPUBenchmarkPlaywright , fileNameTrace , MemBenchmarkPlaywright , TBenchmarkPlaywright } from "./benchmarksPlaywright.js" ;
4
4
import { BenchmarkOptions , config as defaultConfig , ErrorAndWarning , FrameworkData , TConfig } from "./common.js" ;
5
5
import { startBrowser } from "./playwrightAccess.js" ;
@@ -53,11 +53,11 @@ async function forceGC(page: Page, client: CDPSession) {
53
53
}
54
54
}
55
55
56
- async function runCPUBenchmark ( framework : FrameworkData , benchmark : CPUBenchmarkPlaywright , benchmarkOptions : BenchmarkOptions ) : Promise < ErrorAndWarning < number > >
56
+ async function runCPUBenchmark ( framework : FrameworkData , benchmark : CPUBenchmarkPlaywright , benchmarkOptions : BenchmarkOptions ) : Promise < ErrorAndWarning < CPUBenchmarkResult > >
57
57
{
58
58
let error : string = undefined ;
59
59
let warnings : string [ ] = [ ] ;
60
- let results : number [ ] = [ ] ;
60
+ let results : CPUBenchmarkResult [ ] = [ ] ;
61
61
62
62
console . log ( "benchmarking " , framework , benchmark . benchmarkInfo . id ) ;
63
63
let browser : Browser = null ;
@@ -72,6 +72,7 @@ async function runCPUBenchmark(framework: FrameworkData, benchmark: CPUBenchmark
72
72
} ) ;
73
73
// }
74
74
let client = await page . context ( ) . newCDPSession ( page ) ;
75
+ await client . send ( 'Performance.enable' ) ;
75
76
for ( let i = 0 ; i < benchmarkOptions . batchSize ; i ++ ) {
76
77
await page . goto ( `http://${ benchmarkOptions . host } :${ benchmarkOptions . port } /${ framework . uri } /index.html` , { waitUntil : "networkidle" } ) ;
77
78
@@ -112,16 +113,28 @@ async function runCPUBenchmark(framework: FrameworkData, benchmark: CPUBenchmark
112
113
screenshots : false ,
113
114
categories :categories
114
115
} ) ;
116
+ let m1 = ( await client . send ( 'Performance.getMetrics' ) ) . metrics ;
117
+ let m1_val = m1 . find ( m => m . name === 'ScriptDuration' ) . value ;
118
+ let m1_Timestamp = m1 . find ( m => m . name === 'Timestamp' ) . value ;
119
+ console . log ( "m1" , m1 , m1_val ) ;
115
120
console . log ( "runBenchmark Playwright" ) ;
116
121
await runBenchmark ( browser , page , benchmark , framework ) ;
117
122
118
123
await wait ( 40 ) ;
124
+ let m2 = ( await client . send ( 'Performance.getMetrics' ) ) . metrics ;
125
+ let m2_val = m2 . find ( m => m . name === 'ScriptDuration' ) . value ;
126
+ let m2_Timestamp = m2 . find ( m => m . name === 'Timestamp' ) . value ;
127
+ console . log ( "m2" , m2 , m2_val ) ;
119
128
await browser . stopTracing ( ) ;
120
129
if ( throttleCPU ) {
121
130
await client . send ( 'Emulation.setCPUThrottlingRate' , { rate : 1 } ) ;
122
131
}
123
132
let result = await computeResultsCPU ( config , fileNameTrace ( framework , benchmark . benchmarkInfo , i , benchmarkOptions ) , benchmark . benchmarkInfo . durationMeasurementMode ) ;
124
- results . push ( result ) ;
133
+ let resultScript = ( m2_val - m1_val ) * 1000.0 ;
134
+ console . log ( "**** resultScript = " , resultScript ) ;
135
+ if ( m2_Timestamp == m1_Timestamp ) throw new Error ( "Page metrics timestamp didn't change" ) ;
136
+
137
+ results . push ( { total : result , script : resultScript } ) ;
125
138
console . log ( `duration for ${ framework . name } and ${ benchmark . benchmarkInfo . id } : ${ result } ` ) ;
126
139
if ( result < 0 )
127
140
throw new Error ( `duration ${ result } < 0` ) ;
@@ -218,12 +231,12 @@ export async function executeBenchmark(
218
231
framework : FrameworkData ,
219
232
benchmarkId : string ,
220
233
benchmarkOptions : BenchmarkOptions
221
- ) : Promise < ErrorAndWarning < number > > {
234
+ ) : Promise < ErrorAndWarning < number | CPUBenchmarkResult > > {
222
235
let runBenchmarks : Array < TBenchmarkPlaywright > = benchmarks . filter ( b => benchmarkId === b . benchmarkInfo . id && ( b instanceof CPUBenchmarkPlaywright || b instanceof MemBenchmarkPlaywright ) ) as Array < TBenchmarkPlaywright > ;
223
236
224
237
let benchmark = runBenchmarks [ 0 ] ;
225
238
226
- let errorAndWarnings : ErrorAndWarning < number > ;
239
+ let errorAndWarnings : ErrorAndWarning < number | CPUBenchmarkResult > ;
227
240
if ( benchmark . type == BenchmarkType . CPU ) {
228
241
errorAndWarnings = await runCPUBenchmark ( framework , benchmark as CPUBenchmarkPlaywright , benchmarkOptions ) ;
229
242
} else {
0 commit comments