Inspector protocol: Add optional parameter to expose internals

Deprecate the existing parameter to treat global objects as roots as
this is implied by exposing internals.

Bug: chromium:1321620
Change-Id: I73a8124d63f87599dee7080980844c418eb3b5e4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3637797
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80456}
This commit is contained in:
Michael Lippautz 2022-05-10 16:41:04 +02:00 committed by V8 LUCI CQ
parent fa86b6d36e
commit 09f39ae00d
3 changed files with 31 additions and 11 deletions

View File

@ -713,18 +713,24 @@ experimental domain HeapProfiler
# If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken
# when the tracking is stopped.
optional boolean reportProgress
optional boolean treatGlobalObjectsAsRoots
# Deprecated in favor of `exposeInternals`.
deprecated optional boolean treatGlobalObjectsAsRoots
# If true, numerical values are included in the snapshot
optional boolean captureNumericValue
# If true, exposes internals of the snapshot.
experimental optional boolean exposeInternals
command takeHeapSnapshot
parameters
# If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken.
optional boolean reportProgress
# If true, a raw snapshot without artificial roots will be generated
optional boolean treatGlobalObjectsAsRoots
# If true, a raw snapshot without artificial roots will be generated.
# Deprecated in favor of `exposeInternals`.
deprecated optional boolean treatGlobalObjectsAsRoots
# If true, numerical values are included in the snapshot
optional boolean captureNumericValue
# If true, exposes internals of the snapshot.
experimental optional boolean exposeInternals
event addHeapSnapshotChunk
parameters

View File

@ -235,11 +235,11 @@ Response V8HeapProfilerAgentImpl::startTrackingHeapObjects(
Response V8HeapProfilerAgentImpl::stopTrackingHeapObjects(
Maybe<bool> reportProgress, Maybe<bool> treatGlobalObjectsAsRoots,
Maybe<bool> captureNumericValue) {
Maybe<bool> captureNumericValue, Maybe<bool> exposeInternals) {
requestHeapStatsUpdate();
takeHeapSnapshot(std::move(reportProgress),
std::move(treatGlobalObjectsAsRoots),
std::move(captureNumericValue));
std::move(captureNumericValue), std::move(exposeInternals));
stopTrackingHeapObjectsInternal();
return Response::Success();
}
@ -263,7 +263,7 @@ Response V8HeapProfilerAgentImpl::disable() {
Response V8HeapProfilerAgentImpl::takeHeapSnapshot(
Maybe<bool> reportProgress, Maybe<bool> treatGlobalObjectsAsRoots,
Maybe<bool> captureNumericValue) {
Maybe<bool> captureNumericValue, Maybe<bool> exposeInternals) {
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) return Response::ServerError("Cannot access v8 heap profiler");
std::unique_ptr<HeapSnapshotProgress> progress;
@ -271,9 +271,21 @@ Response V8HeapProfilerAgentImpl::takeHeapSnapshot(
progress.reset(new HeapSnapshotProgress(&m_frontend));
GlobalObjectNameResolver resolver(m_session);
const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(
progress.get(), &resolver, treatGlobalObjectsAsRoots.fromMaybe(true),
captureNumericValue.fromMaybe(false));
v8::HeapProfiler::HeapSnapshotOptions options;
options.global_object_name_resolver = &resolver;
options.control = progress.get();
options.snapshot_mode =
exposeInternals.fromMaybe(false) ||
// Not treating global objects as roots results into exposing
// internals.
!treatGlobalObjectsAsRoots.fromMaybe(true)
? v8::HeapProfiler::HeapSnapshotMode::kExposeInternals
: v8::HeapProfiler::HeapSnapshotMode::kRegular;
options.numerics_mode =
captureNumericValue.fromMaybe(false)
? v8::HeapProfiler::NumericsMode::kExposeNumericValues
: v8::HeapProfiler::NumericsMode::kHideNumericValues;
const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(options);
if (!snapshot) return Response::ServerError("Failed to take heap snapshot");
HeapSnapshotOutputStream stream(&m_frontend);
snapshot->Serialize(&stream);

View File

@ -38,13 +38,15 @@ class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend {
Response startTrackingHeapObjects(Maybe<bool> trackAllocations) override;
Response stopTrackingHeapObjects(Maybe<bool> reportProgress,
Maybe<bool> treatGlobalObjectsAsRoots,
Maybe<bool> captureNumericValue) override;
Maybe<bool> captureNumericValue,
Maybe<bool> exposeInternals) override;
Response disable() override;
Response takeHeapSnapshot(Maybe<bool> reportProgress,
Maybe<bool> treatGlobalObjectsAsRoots,
Maybe<bool> captureNumericValue) override;
Maybe<bool> captureNumericValue,
Maybe<bool> exposeInternals) override;
Response getObjectByHeapObjectId(
const String16& heapSnapshotObjectId, Maybe<String16> objectGroup,