Add isolated CPU and allocation profiles for core workloads #36
Mergedtannerlinsleymerged 5 commits into
main fromtaren/core-workload-profiles-20261101merged by tannerlinsley - scripts/profile-core.mjs line 18OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,18 @@1+import assert from 'node:assert/strict'2+import { Session } from 'node:inspector'3+import { createHash } from 'node:crypto'4+import { execFileSync } from 'node:child_process'5+import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'6+import { resolve, relative } from 'node:path'7+import { fileURLToPath } from 'node:url'8+import { gzipSync } from 'node:zlib'9+import { parseMarkdown } from '../src/parser.ts'10+import { renderHtml } from '../src/html.ts'11+import { streamingMarkdownExtension } from '../src/extensions/streaming.ts'12+13+const root = fileURLToPath(new URL('..', import.meta.url))14+const directory = resolve(process.argv[2] || 'artifacts/core-profiles')15+const smoke = process.argv.includes('--smoke')16+assert.equal(typeof global.gc, 'function', 'Run Node with --expose-gc')17+await mkdir(directory, { recursive: true })18+assert.equal((await readdir(directory)).length, 0, 'Output directory must be empty to preserve earlier profiles')scripts/profile-core.mjs lines 104 to 108OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +88,21 @@88+ for (let index = 0; index < iterations; index++) consume(workload.run())89+ const { profile: allocation } = await post('HeapProfiler.stopSampling')90+ await writeFile(resolve(directory, workload.name + '.heapprofile.json.gz'), gzipSync(JSON.stringify(allocation), { level: 9 }))91+ const allocationTop = []92+ function visit(node) { allocationTop.push({ ...frame(node.callFrame), sampledSelfBytes: node.selfSize }); for (const child of node.children || []) visit(child) }93+ visit(allocation.head)94+ allocationTop.sort((a, b) => b.sampledSelfBytes - a.sampledSelfBytes)95+ const sampledBytes = allocation.samples.reduce((sum, sample) => sum + sample.size, 0)96+ assert.equal(sha(JSON.stringify(workload.run())), expected, 'Nondeterministic completed output: ' + workload.name)97+ assert.equal(workload.trace?.(), expectedTrace, 'Nondeterministic progressive output: ' + workload.name)98+ rows.push({ name: workload.name, streamTraceSHA256: expectedTrace, sourceBytes: Buffer.byteLength(workload.source), sourceSHA256: sha(workload.source), outputSHA256: expected, cpuCompletedOperations: completed, cpuTop, allocationIterations: iterations, sampledBytes, sampledBytesPerOperation: sampledBytes / iterations, allocationTop: allocationTop.slice(0, 20) })99+ }100+} finally {101+ session.disconnect()102+}103+const sourceFiles = execFileSync('git', ['ls-files', 'src'], { cwd: root, encoding: 'utf8' }).trim().split('\n').filter(Boolean)104+const sources = Object.fromEntries(await Promise.all(sourceFiles.map(async path => [path, sha(await readFile(resolve(root, path)))])))105+const receipt = {106+ schemaVersion: 1, smoke, commit: execFileSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8' }).trim(),107+ trackedDirtyState: execFileSync('git', ['status', '--porcelain', '--untracked-files=no'], { cwd: root, encoding: 'utf8' }),108+ node: process.version, versions: process.versions, lockfileSHA256: sha(await readFile(resolve(root, 'pnpm-lock.yaml'))), sources,
tannerlinsley merged thisf99165e
tannerlinsley closed this
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: 5ed51e48a39da91e651bb6727c65d9cdc13da279
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR