Commit 8ae9d020 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

Sampling Heap Profiler: Expose browser heap sampling profiles over DT protocol

The Memory.getBrowserSamplingProfile command is introduced.

BUG=803276

Change-Id: I4cc1ede9ace572971102b681f5d9e9bc693e08f0
Reviewed-on: https://chromium-review.googlesource.com/912323
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535969}
parent 0ba932e5
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/memory/memory_pressure_listener.h" #include "base/memory/memory_pressure_listener.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "third_party/WebKit/common/sampling_heap_profiler/sampling_heap_profiler.h"
namespace content { namespace content {
namespace protocol { namespace protocol {
...@@ -21,6 +22,29 @@ void MemoryHandler::Wire(UberDispatcher* dispatcher) { ...@@ -21,6 +22,29 @@ void MemoryHandler::Wire(UberDispatcher* dispatcher) {
Memory::Dispatcher::wire(dispatcher, this); Memory::Dispatcher::wire(dispatcher, this);
} }
Response MemoryHandler::GetBrowserSamplingProfile(
std::unique_ptr<Memory::SamplingProfile>* out_profile) {
std::unique_ptr<Array<Memory::SamplingProfileNode>> samples =
Array<Memory::SamplingProfileNode>::create();
std::vector<blink::SamplingHeapProfiler::Sample> raw_samples =
blink::SamplingHeapProfiler::GetInstance()->GetSamples(0);
for (auto& sample : raw_samples) {
std::unique_ptr<Array<String>> stack = Array<String>::create();
for (auto* frame : sample.stack)
stack->addItem(base::StringPrintf("%p", frame));
samples->addItem(Memory::SamplingProfileNode::Create()
.SetSize(sample.size)
.SetCount(sample.count)
.SetStack(std::move(stack))
.Build());
}
*out_profile =
Memory::SamplingProfile::Create().SetSamples(std::move(samples)).Build();
return Response::OK();
}
Response MemoryHandler::SetPressureNotificationsSuppressed( Response MemoryHandler::SetPressureNotificationsSuppressed(
bool suppressed) { bool suppressed) {
if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
......
...@@ -20,6 +20,8 @@ class MemoryHandler : public DevToolsDomainHandler, ...@@ -20,6 +20,8 @@ class MemoryHandler : public DevToolsDomainHandler,
void Wire(UberDispatcher* dispatcher) override; void Wire(UberDispatcher* dispatcher) override;
Response GetBrowserSamplingProfile(
std::unique_ptr<Memory::SamplingProfile>* out_profile) override;
Response SetPressureNotificationsSuppressed(bool suppressed) override; Response SetPressureNotificationsSuppressed(bool suppressed) override;
Response SimulatePressureNotification(const std::string& level) override; Response SimulatePressureNotification(const std::string& level) override;
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
}, },
{ {
"domain": "Memory", "domain": "Memory",
"include": ["setPressureNotificationsSuppressed", "simulatePressureNotification"] "include": ["getBrowserSamplingProfile", "setPressureNotificationsSuppressed", "simulatePressureNotification"]
}, },
{ {
"domain": "Network", "domain": "Network",
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "content/browser/devtools/protocol/input_handler.h" #include "content/browser/devtools/protocol/input_handler.h"
#include "content/browser/devtools/protocol/inspector_handler.h" #include "content/browser/devtools/protocol/inspector_handler.h"
#include "content/browser/devtools/protocol/io_handler.h" #include "content/browser/devtools/protocol/io_handler.h"
#include "content/browser/devtools/protocol/memory_handler.h"
#include "content/browser/devtools/protocol/network_handler.h" #include "content/browser/devtools/protocol/network_handler.h"
#include "content/browser/devtools/protocol/page_handler.h" #include "content/browser/devtools/protocol/page_handler.h"
#include "content/browser/devtools/protocol/protocol.h" #include "content/browser/devtools/protocol/protocol.h"
...@@ -329,6 +330,7 @@ void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { ...@@ -329,6 +330,7 @@ void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) {
session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); session->AddHandler(base::WrapUnique(new protocol::InspectorHandler()));
session->AddHandler(base::WrapUnique(new protocol::IOHandler( session->AddHandler(base::WrapUnique(new protocol::IOHandler(
GetIOContext()))); GetIOContext())));
session->AddHandler(base::WrapUnique(new protocol::MemoryHandler()));
session->AddHandler(base::WrapUnique(new protocol::NetworkHandler(GetId()))); session->AddHandler(base::WrapUnique(new protocol::NetworkHandler(GetId())));
session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); session->AddHandler(base::WrapUnique(new protocol::SchemaHandler()));
session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler())); session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler()));
......
...@@ -6999,7 +6999,17 @@ ...@@ -6999,7 +6999,17 @@
}, },
{ {
"name": "getAllTimeSamplingProfile", "name": "getAllTimeSamplingProfile",
"description": "Retrieve native memory allocations profile collected since process startup.", "description": "Retrieve native memory allocations profile\ncollected since renderer process startup.",
"returns": [
{
"name": "profile",
"$ref": "SamplingProfile"
}
]
},
{
"name": "getBrowserSamplingProfile",
"description": "Retrieve native memory allocations profile\ncollected since browser process startup.",
"returns": [ "returns": [
{ {
"name": "profile", "name": "profile",
......
...@@ -1019,7 +1019,7 @@ experimental domain CSS ...@@ -1019,7 +1019,7 @@ experimental domain CSS
# Enables the selector recording. # Enables the selector recording.
command startRuleUsageTracking command startRuleUsageTracking
# Stop tracking rule usage and return the list of rules that were used since last call to # Stop tracking rule usage and return the list of rules that were used since last call to
# `takeCoverageDelta` (or since start of coverage instrumentation) # `takeCoverageDelta` (or since start of coverage instrumentation)
command stopRuleUsageTracking command stopRuleUsageTracking
returns returns
...@@ -3166,11 +3166,18 @@ experimental domain Memory ...@@ -3166,11 +3166,18 @@ experimental domain Memory
# Stop collecting native memory profile. # Stop collecting native memory profile.
command stopSampling command stopSampling
# Retrieve native memory allocations profile collected since process startup. # Retrieve native memory allocations profile
# collected since renderer process startup.
command getAllTimeSamplingProfile command getAllTimeSamplingProfile
returns returns
SamplingProfile profile SamplingProfile profile
# Retrieve native memory allocations profile
# collected since browser process startup.
command getBrowserSamplingProfile
returns
SamplingProfile profile
# Retrieve native memory allocations profile collected since last # Retrieve native memory allocations profile collected since last
# `startSampling` call. # `startSampling` call.
command getSamplingProfile command getSamplingProfile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment