()
| 566 | } |
| 567 | |
| 568 | async function main() { |
| 569 | await prepareDesktopBuild() |
| 570 | |
| 571 | const tempRoot = configuredTempRoot ?? await mkdtemp(join(tmpdir(), 'zennotes-desktop-perf-')) |
| 572 | if (configuredTempRoot) await mkdir(tempRoot, { recursive: true }) |
| 573 | const vaultRoot = externalVaultRoot ?? join(tempRoot, 'vault') |
| 574 | const userDataRoot = join(tempRoot, 'user-data') |
| 575 | if (externalVaultRoot) await access(vaultRoot, constants.R_OK) |
| 576 | else await mkdir(vaultRoot, { recursive: true }) |
| 577 | |
| 578 | const debugPort = await getFreePort() |
| 579 | let electron = null |
| 580 | let client = null |
| 581 | |
| 582 | try { |
| 583 | const seedStartedAt = performance.now() |
| 584 | if (!externalVaultRoot) { |
| 585 | if (skipSyntheticSeed) await access(vaultRoot, constants.R_OK) |
| 586 | else await seedVault(vaultRoot, noteCount) |
| 587 | } |
| 588 | await seedUserData(userDataRoot, vaultRoot) |
| 589 | const seedMs = round(performance.now() - seedStartedAt) |
| 590 | |
| 591 | electron = startDesktopRuntime({ |
| 592 | debugPort, |
| 593 | userDataRoot, |
| 594 | disablePersistedMetaCache: Boolean(externalVaultRoot), |
| 595 | appPath: packagedAppPath |
| 596 | }) |
| 597 | client = await connectToElectronPage(debugPort) |
| 598 | |
| 599 | const consoleMessages = [] |
| 600 | const networkScripts = [] |
| 601 | client.on('Runtime.consoleAPICalled', (event) => { |
| 602 | const text = event.args?.map((arg) => arg.value ?? arg.description ?? '').join(' ') ?? '' |
| 603 | if (event.type === 'error' || text.includes('[zen:perf]')) { |
| 604 | consoleMessages.push({ type: event.type, text }) |
| 605 | } |
| 606 | }) |
| 607 | client.on('Network.requestWillBeSent', (event) => { |
| 608 | const script = scriptNameFromUrl(event.request?.url ?? '') |
| 609 | if (script) networkScripts.push(script) |
| 610 | }) |
| 611 | |
| 612 | await Promise.all([ |
| 613 | client.send('Page.enable'), |
| 614 | client.send('Runtime.enable'), |
| 615 | client.send('Network.enable'), |
| 616 | client.send('Performance.enable') |
| 617 | ]) |
| 618 | if (cpuThrottleRate !== 1) { |
| 619 | await client.send('Emulation.setCPUThrottlingRate', { rate: cpuThrottleRate }) |
| 620 | } |
| 621 | await client.send('Page.addScriptToEvaluateOnNewDocument', { |
| 622 | source: ` |
| 623 | (() => { |
| 624 | try { window.localStorage.setItem('zen:perf', '1') } catch {} |
| 625 | window.__ZEN_RUNTIME_PERF__ = { longTasks: [] }; |
no test coverage detected