Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
inspector: implement --heap-prof#27596
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -173,6 +173,19 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { | ||
| } | ||
| } | ||
| if (!heap_prof) { | ||
| if (!heap_prof_name.empty()) { | ||
| errors->push_back("--heap-prof-name must be used with --heap-prof"); | ||
joyeecheung marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| if (!heap_prof_dir.empty()) { | ||
| errors->push_back("--heap-prof-dir must be used with --heap-prof"); | ||
| } | ||
| // We can't catch the case where the value passed is the default value, | ||
| // then the option just becomes a noop which is fine. | ||
| if (heap_prof_interval != kDefaultHeapProfInterval) { | ||
| errors->push_back("--heap-prof-interval must be used with --heap-prof"); | ||
| } | ||
| } | ||
| debug_options_.CheckOptions(errors); | ||
| #endif // HAVE_INSPECTOR | ||
| } | ||
| @@ -378,6 +391,24 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | ||
| "Directory where the V8 profiles generated by --cpu-prof will be " | ||
| "placed. Does not affect --prof.", | ||
| &EnvironmentOptions::cpu_prof_dir); | ||
| AddOption( | ||
| "--heap-prof", | ||
| "Start the V8 heap profiler on start up, and write the heap profile " | ||
| "to disk before exit. If --heap-prof-dir is not specified, write " | ||
| "the profile to the current working directory.", | ||
| &EnvironmentOptions::heap_prof); | ||
| AddOption("--heap-prof-name", | ||
| "specified file name of the V8 CPU profile generated with " | ||
| "--heap-prof", | ||
| &EnvironmentOptions::heap_prof_name); | ||
| AddOption("--heap-prof-dir", | ||
| "Directory where the V8 heap profiles generated by --heap-prof " | ||
| "will be placed.", | ||
| &EnvironmentOptions::heap_prof_dir); | ||
| AddOption("--heap-prof-interval", | ||
| "specified sampling interval in bytes for the V8 heap " | ||
| "profile generated with --heap-prof. (default: 512 * 1024)", | ||
| &EnvironmentOptions::heap_prof_interval); | ||
| #endif // HAVE_INSPECTOR | ||
| AddOption("--redirect-warnings", | ||
| "write warnings to file instead of stderr", | ||
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,17 @@ | ||
| 'use strict'; | ||
| const util = require('util'); | ||
| const total = parseInt(process.env.TEST_ALLOCATION) || 100; | ||
| let count = 0; | ||
| let string = ''; | ||
| function runAllocation() { | ||
| string += util.inspect(process.env); | ||
| if (count++ < total) { | ||
| setTimeout(runAllocation, 1); | ||
| } else { | ||
| console.log(string.length); | ||
| process.exit(55); | ||
| } | ||
| } | ||
| setTimeout(runAllocation, 1); |
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,17 @@ | ||
| 'use strict'; | ||
| const util = require('util'); | ||
| const total = parseInt(process.env.TEST_ALLOCATION) || 100; | ||
| let count = 0; | ||
| let string = ''; | ||
| function runAllocation() { | ||
| string += util.inspect(process.env); | ||
| if (count++ < total) { | ||
| setTimeout(runAllocation, 1); | ||
| } else { | ||
| console.log(string.length); | ||
| process.kill(process.pid, "SIGINT"); | ||
| } | ||
| } | ||
| setTimeout(runAllocation, 1); |
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,11 @@ | ||
| 'use strict'; | ||
| const { Worker } = require('worker_threads'); | ||
| const path = require('path'); | ||
| new Worker(path.join(__dirname, 'allocation.js'), { | ||
| execArgv: [ | ||
| '--heap-prof', | ||
| '--heap-prof-interval', | ||
| process.HEAP_PROF_INTERVAL || '128', | ||
| ] | ||
| }); |
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,5 @@ | ||
| 'use strict'; | ||
| const { Worker } = require('worker_threads'); | ||
| const path = require('path'); | ||
| new Worker(path.join(__dirname, 'allocation.js')); |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
@ofrobots See here and
V8ProfilerConnection:ParseProfile(). Because the response returned from the protocol is:We need to do
JSON::Parseand thenJSON::Stringifyto get to the profile. It would be better if the profile is formatted directly from the C++ data and since we already know about the schema of the returned object, we can serialize it more efficiently (similar to how heap snapshots are serialized in the API). That may be useful for a particularly big profile.