Summarize terminal perf benchmark reports (#4795)
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { basename } from 'node:path'
|
||||
|
||||
const reportPaths = process.argv.slice(2)
|
||||
if (reportPaths[0] === '--') {
|
||||
reportPaths.shift()
|
||||
}
|
||||
|
||||
if (reportPaths.length === 0) {
|
||||
console.error(
|
||||
'Usage: node config/scripts/summarize-terminal-perf-report.mjs <playwright-json>...'
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
function readJsonReport(path) {
|
||||
const raw = readFileSync(path, 'utf8')
|
||||
const start = raw.indexOf('{')
|
||||
const end = raw.lastIndexOf('}')
|
||||
if (start === -1 || end <= start) {
|
||||
throw new Error(`${path}: no JSON object found`)
|
||||
}
|
||||
return JSON.parse(raw.slice(start, end + 1))
|
||||
}
|
||||
|
||||
function parseAnnotationDescription(description) {
|
||||
const values = {}
|
||||
for (const part of description.split(/\s+/)) {
|
||||
const index = part.indexOf('=')
|
||||
if (index === -1) {
|
||||
continue
|
||||
}
|
||||
values[part.slice(0, index)] = part.slice(index + 1)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
function collectTerminalPerfRows(report, source) {
|
||||
const rows = []
|
||||
const visitSuite = (suite) => {
|
||||
for (const spec of suite.specs ?? []) {
|
||||
for (const test of spec.tests ?? []) {
|
||||
for (const annotation of test.annotations ?? []) {
|
||||
if (!annotation.type.startsWith('opencode-')) {
|
||||
continue
|
||||
}
|
||||
rows.push({
|
||||
source,
|
||||
scenario: annotation.type,
|
||||
...parseAnnotationDescription(annotation.description ?? '')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of suite.suites ?? []) {
|
||||
visitSuite(child)
|
||||
}
|
||||
}
|
||||
for (const suite of report.suites ?? []) {
|
||||
visitSuite(suite)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
function markdownCell(value) {
|
||||
return String(value ?? '').replaceAll('|', '\\|')
|
||||
}
|
||||
|
||||
function printMarkdownTable(rows) {
|
||||
const columns = [
|
||||
['Source', 'source'],
|
||||
['Scenario', 'scenario'],
|
||||
['Panes', 'panes'],
|
||||
['Frames', 'frames'],
|
||||
['Median', 'median'],
|
||||
['Worst', 'worst'],
|
||||
['Max Drift', 'maxTimerDrift'],
|
||||
['Hidden Skips', 'hiddenSkips'],
|
||||
['Hidden Chars', 'hiddenSkippedChars'],
|
||||
['Foreground Enqueues', 'deferredForegroundEnqueue'],
|
||||
['Foreground Writes', 'deferredForegroundWrite'],
|
||||
['Drains', 'scheduledDrains']
|
||||
]
|
||||
|
||||
console.log(`| ${columns.map(([label]) => label).join(' | ')} |`)
|
||||
console.log(`| ${columns.map(() => '---').join(' | ')} |`)
|
||||
for (const row of rows) {
|
||||
console.log(`| ${columns.map(([, key]) => markdownCell(row[key])).join(' | ')} |`)
|
||||
}
|
||||
}
|
||||
|
||||
const rows = reportPaths.flatMap((path) =>
|
||||
collectTerminalPerfRows(readJsonReport(path), basename(path))
|
||||
)
|
||||
|
||||
if (rows.length === 0) {
|
||||
console.error('No OpenCode terminal perf annotations found.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
printMarkdownTable(rows)
|
||||
@@ -62,6 +62,7 @@
|
||||
"test:e2e": "pnpm run ensure:electron-runtime && npx playwright test --config tests/playwright.config.ts --project electron-headless",
|
||||
"test:e2e:terminal-perf": "pnpm run ensure:electron-runtime && npx playwright test tests/e2e/terminal-typing-latency.spec.ts tests/e2e/terminal-foreground-redraw-freeze.spec.ts tests/e2e/terminal-output-scheduler.spec.ts tests/e2e/terminal-hidden-tui-visual-restore.spec.ts tests/e2e/artificial-opencode-terminal-load.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=2",
|
||||
"test:e2e:terminal-perf:scale": "pnpm run ensure:electron-runtime && node config/scripts/run-terminal-scale-perf-e2e.mjs",
|
||||
"test:e2e:terminal-perf:summarize": "node config/scripts/summarize-terminal-perf-report.mjs",
|
||||
"test:e2e:ssh-docker-perf": "node config/scripts/run-ssh-docker-perf-e2e.mjs",
|
||||
"test:e2e:headful": "pnpm run ensure:electron-runtime && npx playwright test --config tests/playwright.config.ts --project electron-headful",
|
||||
"test:e2e:computer": "vitest run --config tests/e2e/vitest.config.ts"
|
||||
|
||||
Reference in New Issue
Block a user