-
Notifications
You must be signed in to change notification settings - Fork 14
refactor: use sharded WAL #1231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BioPhoton
wants to merge
37
commits into
main
Choose a base branch
from
feat/utils/sharded-profiling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,884
−3,448
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
022eeef
refactor: use sharded WAL
BioPhoton a66acf4
refactor: wip
BioPhoton a4eb05c
Merge branch 'refs/heads/main' into feat/utils/sharded-profiling
BioPhoton 6d9d5c1
refactor: wip
BioPhoton 6387ccc
refactor: wip
BioPhoton 02b9da8
refactor: wip
BioPhoton 6b638d9
refactor: wip
BioPhoton cdb745b
refactor: wip
BioPhoton ed64102
refactor: wip
BioPhoton 4950ca0
refactor: wip
BioPhoton 0a37c3c
refactor: wip
BioPhoton af5b8d2
refactor: wip
BioPhoton 35063f7
refactor: wip
BioPhoton f958a3e
Merge branch 'refs/heads/main' into feat/utils/sharded-profiling
BioPhoton 13529fc
refactor: wip
BioPhoton 8c3171e
refactor: wip
BioPhoton 5c644c2
refactor: wip
BioPhoton 96ccaa9
refactor: wip
BioPhoton c726123
refactor: wip
BioPhoton bb150e3
refactor: wip
BioPhoton ba87d94
refactor: wip
BioPhoton 4f01e32
refactor: wip
BioPhoton b74bdc2
refactor: wip
BioPhoton 3ba8619
refactor: wip
BioPhoton 9ed836c
refactor: wip
BioPhoton d8978e1
refactor: wip
BioPhoton 1321cbe
refactor: wip
BioPhoton f44086c
refactor: wip
BioPhoton 6567601
refactor: wip
BioPhoton 6a83e93
refactor: wip
BioPhoton 9fce5e5
refactor: wip
BioPhoton b801d91
refactor: wip
BioPhoton b16ded4
refactor: wip
BioPhoton 6e3445a
refactor: wip
BioPhoton 76f4bca
refactor: wip
BioPhoton beef91c
Update profiler.md
BioPhoton e03a7ac
Update profiler-node.ts
BioPhoton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Mocks | ||
|
|
||
| ## multiprocess-profiling | ||
|
|
||
| The `profiler-worker.mjs` script demonstrates multiprocess profiling by spawning N child processes that perform work and generate performance traces. | ||
|
|
||
| ### Expected Output | ||
|
|
||
| **Console:** | ||
|
|
||
| - JSON object containing profiler statistics (profiler state, shard info, queue stats, etc.) | ||
|
|
||
| **Files:** | ||
|
|
||
| - A timestamped directory in `CP_PROFILER_OUT_DIR` (e.g., `20260131-210017-052/`) | ||
| - `trace.<timestamp>.<pid>.<shard>.jsonl` - WAL format trace files (one per process) | ||
| - `trace.<timestamp>.json` - Consolidated trace file in Chrome DevTools format | ||
|
|
||
| ### Usage | ||
|
|
||
| ```bash | ||
| CP_PROFILING=true DEBUG=true CP_PROFILER_OUT_DIR=/path/to/output npx tsx packages/utils/mocks/multiprocess-profiling/profiler-worker.mjs <numProcesses> | ||
| ``` | ||
|
|
||
| **Example:** | ||
|
|
||
| ```bash | ||
| CP_PROFILING=true DEBUG=true CP_PROFILER_OUT_DIR=./tmp/int/utils npx tsx --tsconfig tsconfig.base.json packages/utils/mocks/multiprocess-profiling/profiler-worker.mjs 3 | ||
| ``` |
14 changes: 14 additions & 0 deletions
14
packages/utils/mocks/multiprocess-profiling/profiler-worker-child.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { NodejsProfiler } from '../../src/lib/profiler/profiler-node.js'; | ||
| import { | ||
| createBufferedEvents, | ||
| getProfilerConfig, | ||
| performDummyWork, | ||
| } from './utils.js'; | ||
|
|
||
| await createBufferedEvents(); | ||
|
|
||
| const profiler = new NodejsProfiler(getProfilerConfig()); | ||
|
|
||
| await performDummyWork(profiler); | ||
|
|
||
| profiler.close(); |
77 changes: 77 additions & 0 deletions
77
packages/utils/mocks/multiprocess-profiling/profiler-worker.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { spawn } from 'node:child_process'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { NodejsProfiler } from '../../src/lib/profiler/profiler-node.js'; | ||
| import { createBufferedEvents, getProfilerConfig } from './utils.js'; | ||
|
|
||
| const [numProcesses] = process.argv.slice(2); | ||
|
|
||
| if (!numProcesses) { | ||
| console.error('Usage: node profiler-worker.mjs <numProcesses>'); | ||
| // eslint-disable-next-line unicorn/no-process-exit,n/no-process-exit | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const numProcs = Number.parseInt(numProcesses, 10); | ||
| if (Number.isNaN(numProcs) || numProcs < 1) { | ||
| console.error('numProcesses must be a positive integer'); | ||
| // eslint-disable-next-line unicorn/no-process-exit,n/no-process-exit | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const workerScriptPath = path.join( | ||
| fileURLToPath(path.dirname(import.meta.url)), | ||
| './profiler-worker-child.mjs', | ||
| ); | ||
|
|
||
| let profiler; | ||
| try { | ||
| await createBufferedEvents(); | ||
|
|
||
| profiler = new NodejsProfiler(getProfilerConfig()); | ||
|
|
||
| await profiler.measureAsync('profiler-worker', async () => { | ||
| const processes = Array.from( | ||
| { length: numProcs }, | ||
| (_, i) => | ||
| new Promise((resolve, reject) => { | ||
| const child = spawn('npx', ['tsx', workerScriptPath], { | ||
| stdio: 'pipe', | ||
| shell: process.platform === 'win32', | ||
| }); | ||
|
|
||
| child.on('close', code => { | ||
| if (code === 0) { | ||
| resolve(code); | ||
| } else { | ||
| reject(new Error(`Process ${i + 1} exited with code ${code}`)); | ||
| } | ||
| }); | ||
|
|
||
| child.on('error', reject); | ||
| }), | ||
| ); | ||
| await Promise.all(processes); | ||
| }); | ||
|
|
||
| profiler.close(); | ||
| // eslint-disable-next-line no-console | ||
| console.log(JSON.stringify(profiler.stats, null, 2)); | ||
| } catch (error) { | ||
| // Ensure profiler is closed and stats are output even on error | ||
| if (profiler && profiler.stats.profilerState !== 'closed') { | ||
| profiler.close(); | ||
| } | ||
| // Output stats if profiler was initialized, otherwise exit with error | ||
| if (profiler) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(JSON.stringify(profiler.stats, null, 2)); | ||
| // Exit successfully since we've output the stats that the test needs | ||
| // eslint-disable-next-line unicorn/no-process-exit,n/no-process-exit | ||
| process.exit(0); | ||
| } else { | ||
| console.error('Failed to initialize profiler:', error); | ||
| // eslint-disable-next-line unicorn/no-process-exit,n/no-process-exit | ||
| process.exit(1); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options table lists
outBaseName, but there is no corresponding option inNodejsProfilerOptions/PersistOptions(and no code uses it). This is misleading API documentation; either implement the option or remove it from the docs.