@@ -9,13 +9,19 @@ import {GEN_DIR} from '../../../conductor/paths.js';
99import {
1010 navigateToPerformanceTab ,
1111} from '../../../e2e/helpers/performance-helpers.js' ;
12- import type { DevToolsPage } from '../../../e2e_non_hosted/shared/frontend-helper.js' ;
13- import type { InspectedPage } from '../../../e2e_non_hosted/shared/target-helper.js' ;
14- import { measurements } from '../../report/report.js' ;
12+ import {
13+ getBrowserAndPages ,
14+ reloadDevTools ,
15+ waitFor ,
16+ waitForFunction ,
17+ } from '../../../shared/helper.js' ;
18+ import { mean , percentile } from '../../helpers/perf-helper.js' ;
19+ import { addBenchmarkResult , type Benchmark } from '../../report/report.js' ;
1520
16- async function timeFixture ( fixture : string , devToolsPage : DevToolsPage , inspectedPage : InspectedPage ) : Promise < number > {
17- await navigateToPerformanceTab ( undefined , devToolsPage , inspectedPage ) ;
18- const panelElement = await devToolsPage . waitFor ( '.widget.panel.timeline' ) ;
21+ async function timeFixture ( fixture : string ) : Promise < number > {
22+ const { frontend} = getBrowserAndPages ( ) ;
23+ await navigateToPerformanceTab ( ) ;
24+ const panelElement = await waitFor ( '.widget.panel.timeline' ) ;
1925 await panelElement . evaluate ( el => {
2026 // @ts -expect-error page context.
2127 window . perfDuration = 0 ;
@@ -25,12 +31,12 @@ async function timeFixture(fixture: string, devToolsPage: DevToolsPage, inspecte
2531 window . perfDuration = ev . duration ;
2632 } , { once : true } ) ;
2733 } ) ;
28- const uploadProfileHandle = await devToolsPage . waitFor ( 'input[type=file]' ) ;
34+ const uploadProfileHandle = await waitFor ( 'input[type=file]' ) ;
2935 await uploadProfileHandle . uploadFile ( path . join ( GEN_DIR , `front_end/panels/timeline/fixtures/traces/${ fixture } .gz` ) ) ;
3036 // We use wait for function to avoid long running evaluation calls to
3137 // avoid protocol-level timeouts.
32- return await devToolsPage . waitForFunction ( async ( ) => {
33- const result = await devToolsPage . evaluate ( ( ) => {
38+ return await waitForFunction ( async ( ) => {
39+ const result = await frontend . evaluate ( ( ) => {
3440 // @ts -expect-error page context.
3541 return window . perfDuration ;
3642 } ) ;
@@ -42,34 +48,98 @@ async function timeFixture(fixture: string, devToolsPage: DevToolsPage, inspecte
4248}
4349
4450describe ( 'Performance panel trace load performance' , ( ) => {
51+ const allTestValues : Array < { name : string , values : number [ ] } > = [ ] ;
4552 // Skipped because this throws range errors
46- describe . skip ( '[crbug.com/433466849] Large CPU profile load benchmark' , function ( ) {
53+ describe . skip ( '[crbug.com/433466849] Large CPU profile load benchmark' , ( ) => {
54+ beforeEach ( async ( ) => {
55+ // Reload devtools to get a fresh version of the panel on each
56+ // run and prevent a skew due to caching, etc.
57+ await reloadDevTools ( ) ;
58+ } ) ;
4759 const RUNS = 10 ;
48- this . timeout ( 40_000 ) ;
49-
60+ const testValues = {
61+ name : 'LargeCPULoad' ,
62+ values : [ ] as number [ ] ,
63+ } ;
5064 for ( let run = 1 ; run <= RUNS ; run ++ ) {
51- it ( 'run large cpu profile benchmark' , async ( { devToolsPage , inspectedPage } ) => {
52- await devToolsPage . reload ( ) ;
53- const duration = await timeFixture ( 'large-profile.cpuprofile' , devToolsPage , inspectedPage ) ;
65+ it ( 'run large cpu profile benchmark' , async function ( ) {
66+ this . timeout ( 40_000 ) ;
67+ const duration = await timeFixture ( 'large-profile.cpuprofile' ) ;
5468 // Ensure only 2 decimal places.
5569 const timeTaken = Number ( duration . toFixed ( 2 ) ) ;
56- measurements . LargeCPULoad . push ( timeTaken ) ;
70+ testValues . values . push ( timeTaken ) ;
5771 } ) ;
5872 }
73+ after ( ( ) => {
74+ allTestValues . push ( testValues ) ;
75+ } ) ;
5976 } ) ;
6077
61- describe ( 'Large DOM trace load benchmark' , function ( ) {
78+ describe ( 'Large DOM trace load benchmark' , ( ) => {
79+ beforeEach ( async ( ) => {
80+ // Reload devtools to get a fresh version of the panel on each
81+ // run and prevent a skew due to caching, etc.
82+ await reloadDevTools ( ) ;
83+ } ) ;
6284 const RUNS = 10 ;
63- this . timeout ( 8_000 ) ;
64-
85+ const testValues = {
86+ name : 'LargeDOMTraceLoad' ,
87+ values : [ ] as number [ ] ,
88+ } ;
6589 for ( let run = 1 ; run <= RUNS ; run ++ ) {
66- it ( 'run large dom trace load benchmark' , async ( { devToolsPage , inspectedPage } ) => {
67- await devToolsPage . reload ( ) ;
68- const duration = await timeFixture ( 'dom-size-long.json' , devToolsPage , inspectedPage ) ;
90+ it ( 'run large dom trace load benchmark' , async function ( ) {
91+ this . timeout ( 8_000 ) ;
92+ const duration = await timeFixture ( 'dom-size-long.json' ) ;
6993 // Ensure only 2 decimal places.
7094 const timeTaken = Number ( duration . toFixed ( 2 ) ) ;
71- measurements . LargeDOMTraceLoad . push ( timeTaken ) ;
95+ testValues . values . push ( timeTaken ) ;
7296 } ) ;
7397 }
98+ after ( ( ) => {
99+ allTestValues . push ( testValues ) ;
100+ } ) ;
101+ } ) ;
102+
103+ after ( async ( ) => {
104+ // Calculate statistics for each benchmark.
105+ for ( const testValues of allTestValues ) {
106+ const values = testValues . values ;
107+ const meanMeasure = Number ( mean ( values ) . toFixed ( 2 ) ) ;
108+ const percentile50 = Number ( percentile ( values , 0.5 ) . toFixed ( 2 ) ) ;
109+ const percentile90 = Number ( percentile ( values , 0.9 ) . toFixed ( 2 ) ) ;
110+ const percentile99 = Number ( percentile ( values , 0.99 ) . toFixed ( 2 ) ) ;
111+
112+ const benchmark : Benchmark = {
113+ key : { test : testValues . name , units : 'ms' } ,
114+ measurements : {
115+ stats : [
116+ {
117+ value : 'mean' ,
118+ measurement : meanMeasure ,
119+ } ,
120+ {
121+ value : 'percentile50' ,
122+ measurement : percentile50 ,
123+ } ,
124+ {
125+ value : 'percentile90' ,
126+ measurement : percentile90 ,
127+ } ,
128+ {
129+ value : 'percentile99' ,
130+ measurement : percentile99 ,
131+ } ,
132+ ] ,
133+ } ,
134+ } ;
135+ addBenchmarkResult ( benchmark ) ;
136+ /* eslint-disable no-console */
137+ console . log ( `Benchmark name: ${ testValues . name } ` ) ;
138+ console . log ( `Mean time: ${ meanMeasure } ms` ) ;
139+ console . log ( `50th percentile time: ${ percentile50 } ms` ) ;
140+ console . log ( `90th percentile time: ${ percentile90 } ms` ) ;
141+ console . log ( `99th percentile time: ${ percentile99 } ms` ) ;
142+ /* eslint-enable no-console */
143+ }
74144 } ) ;
75145} ) ;
0 commit comments