-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
worker: add worker.getHeapStatistics() #57888
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
Merged
nodejs-github-bot
merged 19 commits into
nodejs:main
from
mcollina:worker-heap-statistics
Apr 17, 2025
+219
−0
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
94ec4e6
worker: add worker.getHeapStatistics()
mcollina 852078c
fixup
mcollina c73d1b6
fixup
mcollina 599fb2c
fixup
mcollina d219327
fixup
mcollina 8b1266a
fixup
mcollina 09741f2
macros
mcollina 76d4027
object initialization
mcollina 47bd934
refactor to use an interrupt
mcollina ea24ef4
fixup
mcollina 821744f
fixup
mcollina 8236424
linting
mcollina ab5f978
fixup
mcollina a3e2066
fixup
mcollina 99c6b80
fixup
mcollina c7ab253
Update src/node_worker.cc
mcollina e40a220
review feedbacks
mcollina 645d972
fixup
mcollina df57fa3
fixup
mcollina 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
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
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,63 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const { | ||
Worker, | ||
isMainThread, | ||
} = require('worker_threads'); | ||
|
||
if (!isMainThread) { | ||
common.skip('This test only works on a main thread'); | ||
} | ||
|
||
// Ensures that worker.getHeapStatistics() returns valid data | ||
|
||
const assert = require('assert'); | ||
|
||
if (isMainThread) { | ||
const name = 'Hello Thread'; | ||
const worker = new Worker(fixtures.path('worker-name.js'), { | ||
name, | ||
}); | ||
worker.once('message', common.mustCall(async (message) => { | ||
const stats = await worker.getHeapStatistics(); | ||
const keys = [ | ||
`total_heap_size`, | ||
`total_heap_size_executable`, | ||
`total_physical_size`, | ||
`total_available_size`, | ||
`used_heap_size`, | ||
`heap_size_limit`, | ||
`malloced_memory`, | ||
`peak_malloced_memory`, | ||
`does_zap_garbage`, | ||
`number_of_native_contexts`, | ||
`number_of_detached_contexts`, | ||
`total_global_handles_size`, | ||
`used_global_handles_size`, | ||
`external_memory`, | ||
].sort(); | ||
assert.deepStrictEqual(keys, Object.keys(stats).sort()); | ||
for (const key of keys) { | ||
if (key === 'does_zap_garbage') { | ||
assert.strictEqual(typeof stats[key], 'boolean', `Expected ${key} to be a boolean`); | ||
continue; | ||
} | ||
assert.strictEqual(typeof stats[key], 'number', `Expected ${key} to be a number`); | ||
assert.ok(stats[key] >= 0, `Expected ${key} to be >= 0`); | ||
} | ||
|
||
worker.postMessage('done'); | ||
})); | ||
|
||
worker.once('exit', common.mustCall(async (code) => { | ||
assert.strictEqual(code, 0); | ||
await assert.rejects(worker.getHeapStatistics(), { | ||
code: 'ERR_WORKER_NOT_RUNNING' | ||
}); | ||
})); | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.