| 236 | } |
| 237 | |
| 238 | async function diagnose(browser, server, result, dir, isInterrupted) { |
| 239 | for (let scenario of result.scenarios) { |
| 240 | for (let arm of Object.keys(result.builds)) { |
| 241 | if (isInterrupted()) { |
| 242 | return; |
| 243 | } |
| 244 | let file = `${scenario.id}-${arm}.trace.json`; |
| 245 | let current; |
| 246 | try { |
| 247 | current = await openPage( |
| 248 | browser, |
| 249 | server, |
| 250 | scenario, |
| 251 | arm, |
| 252 | result.options, |
| 253 | result.builds[arm], |
| 254 | true |
| 255 | ); |
| 256 | // Match the measured trials' warm state before the traced trial. |
| 257 | for (let warmup = 0; warmup < result.options.warmup; warmup++) { |
| 258 | await prepare(current.page, scenario, current.size); |
| 259 | await perform(current, scenario); |
| 260 | } |
| 261 | await prepare(current.page, scenario, current.size); |
| 262 | await saveTrace(current.session, path.join(dir, file), () => perform(current, scenario)); |
| 263 | if (current.errors.length) { |
| 264 | throw new Error(current.errors.join('\n')); |
| 265 | } |
| 266 | let summary = summarizeTrace(JSON.parse(await fs.readFile(path.join(dir, file), 'utf8'))); |
| 267 | result.diagnostics.push({scenario: scenario.id, arm, file, summary}); |
| 268 | } catch (error) { |
| 269 | result.diagnostics.push({scenario: scenario.id, arm, error: error.message}); |
| 270 | } finally { |
| 271 | await current?.context.close(); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | export async function run(options) { |
| 278 | let selected = scenarios.filter( |