speedometer3.js (4880B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* eslint-env node */ 6 7 const { logTest, logTask } = require("./utils/profiling"); 8 const { 9 initializeMeasurements, 10 startMeasurements, 11 stopMeasurements, 12 finalizeMeasurements, 13 } = require("./utils/support_measurements"); 14 15 module.exports = logTest( 16 "speedometer 3 test", 17 async function (context, commands) { 18 context.log.info("Starting Speedometer 3 test"); 19 let url = context.options.browsertime.url; 20 let page_cycles = context.options.browsertime.page_cycles; 21 let page_cycle_delay = context.options.browsertime.page_cycle_delay; 22 let post_startup_delay = context.options.browsertime.post_startup_delay; 23 let page_timeout = context.options.timeouts.pageLoad; 24 let expose_profiler = context.options.browsertime.expose_profiler; 25 26 await initializeMeasurements( 27 context, 28 commands, 29 true, 30 context.options.browsertime.power_test, 31 true 32 ); 33 34 context.log.info( 35 "Waiting for %d ms (post_startup_delay)", 36 post_startup_delay 37 ); 38 await commands.wait.byTime(post_startup_delay); 39 40 for (let count = 0; count < page_cycles; count++) { 41 await logTask(context, "cycle " + count, async function () { 42 context.log.info("Navigating to about:blank"); 43 await commands.navigate("about:blank"); 44 45 context.log.info( 46 "Cycle %d, waiting for %d ms", 47 count, 48 page_cycle_delay 49 ); 50 await commands.wait.byTime(page_cycle_delay); 51 52 context.log.info("Cycle %d, starting the measure", count); 53 if (expose_profiler === "true") { 54 context.log.info("Custom profiler start!"); 55 if (context.options.browser === "firefox") { 56 await commands.profiler.start(); 57 } else if (context.options.browser === "chrome") { 58 await commands.trace.start(); 59 } 60 } 61 await commands.measure.start(url); 62 await startMeasurements(context, commands); 63 64 // Measure the GC perfstats counters over the entire sp3 run. 65 if (context.options.browser === "firefox") { 66 await commands.perfStats.start([ 67 "MinorGC", 68 "MajorGC", 69 "NonIdleMajorGC", 70 ]); 71 } 72 73 await commands.js.runAndWait(` 74 this.benchmarkClient.start() 75 `); 76 77 let data_exists = false; 78 let starttime = await commands.js.run(`return performance.now();`); 79 while ( 80 !data_exists && 81 (await commands.js.run(`return performance.now();`)) - starttime < 82 page_timeout 83 ) { 84 let wait_time = 3000; 85 context.log.info( 86 "Waiting %d ms for data from speedometer...", 87 wait_time 88 ); 89 await commands.wait.byTime(wait_time); 90 data_exists = await commands.js.run( 91 "return !(this.benchmarkClient._isRunning)" 92 ); 93 } 94 if (expose_profiler === "true") { 95 context.log.info("Custom profiler stop!"); 96 if (context.options.browser === "firefox") { 97 await commands.profiler.stop(); 98 } else if (context.options.browser === "chrome") { 99 await commands.trace.stop(); 100 } 101 } 102 if ( 103 !data_exists && 104 (await commands.js.run(`return performance.now();`)) - starttime >= 105 page_timeout 106 ) { 107 context.log.error("Benchmark timed out. Aborting..."); 108 return false; 109 } 110 await stopMeasurements(); 111 112 let perfStatsResults = undefined; 113 if (context.options.browser === "firefox") { 114 perfStatsResults = await commands.perfStats.collect(); 115 await commands.perfStats.stop(); 116 } 117 118 let internal_data = await commands.js.run( 119 `return this.benchmarkClient._measuredValuesList;` 120 ); 121 context.log.info( 122 "Value of internal benchmark iterations: ", 123 internal_data 124 ); 125 126 let data = await commands.js.run(` 127 const values = this.benchmarkClient._computeResults(this.benchmarkClient._measuredValuesList, "ms"); 128 const score = this.benchmarkClient._computeResults(this.benchmarkClient._measuredValuesList, "score"); 129 return { 130 score, 131 values: values.formattedMean, 132 }; 133 `); 134 context.log.info("Value of summarized benchmark data: ", data); 135 136 commands.measure.addObject({ 137 s3: data, 138 s3_internal: internal_data, 139 ...(perfStatsResults !== undefined && { 140 perfstats: perfStatsResults, 141 }), 142 }); 143 144 return true; 145 }); 146 } 147 await finalizeMeasurements(); 148 149 return true; 150 } 151 );