Commit 0ed5a808 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Introduce Memory.getAllTimeSamplingProfile command

It retrieves the currently collected native heap sampling snapshot.
The renderer process had to be started with --sampling-heap-profiler flag to
obtain the snapshot.

BUG=803276

Change-Id: I26ffe5e366abb33245d2f83ffa02bd4350737b7a
Reviewed-on: https://chromium-review.googlesource.com/882290
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532233}
parent f77d64b3
...@@ -66,4 +66,7 @@ crbug.com/577889 [ Linux ] fast/js/typed-array-allocation-failure.html [ Crash ] ...@@ -66,4 +66,7 @@ crbug.com/577889 [ Linux ] fast/js/typed-array-allocation-failure.html [ Crash ]
# Memory allocation hooks are disabled on ASAN/MSAN # Memory allocation hooks are disabled on ASAN/MSAN
crbug.com/803276 inspector-protocol/memory/sampling-native-profile.js [ Skip ] crbug.com/803276 inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
...@@ -86,3 +86,7 @@ crbug.com/798957 [ Linux ] http/tests/devtools/audits2/audits2-successful-run.js ...@@ -86,3 +86,7 @@ crbug.com/798957 [ Linux ] http/tests/devtools/audits2/audits2-successful-run.js
# Memory allocation hooks are disabled on ASAN/MSAN # Memory allocation hooks are disabled on ASAN/MSAN
crbug.com/803276 inspector-protocol/memory/sampling-native-profile.js [ Skip ] crbug.com/803276 inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
...@@ -620,6 +620,9 @@ crbug.com/767269 [ Win ] inspector-protocol/layout-fonts/cjk-ideograph-fallback- ...@@ -620,6 +620,9 @@ crbug.com/767269 [ Win ] inspector-protocol/layout-fonts/cjk-ideograph-fallback-
crbug.com/788110 [ Linux Win10 ] inspector-protocol/layout-fonts/unicode-range-combining-chars-fallback.js [ Pass Failure ] crbug.com/788110 [ Linux Win10 ] inspector-protocol/layout-fonts/unicode-range-combining-chars-fallback.js [ Pass Failure ]
crbug.com/803276 [ Mac Win ] inspector-protocol/memory/sampling-native-profile.js [ Skip ] crbug.com/803276 [ Mac Win ] inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 [ Mac Win ] inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
crbug.com/803276 [ Mac Win ] virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-profile.js [ Skip ]
crbug.com/803276 [ Mac Win ] virtual/sampling-heap-profiler/inspector-protocol/memory/sampling-native-snapshot.js [ Skip ]
# Run these tests with under virtual/scalefactor... only. # Run these tests with under virtual/scalefactor... only.
crbug.com/567837 fast/hidpi/static [ Skip ] crbug.com/567837 fast/hidpi/static [ Skip ]
......
...@@ -653,5 +653,10 @@ ...@@ -653,5 +653,10 @@
"prefix": "htxg-with-network-service", "prefix": "htxg-with-network-service",
"base": "http/tests/loading/htxg/", "base": "http/tests/loading/htxg/",
"args": ["--enable-features=SignedHTTPExchange,NetworkService"] "args": ["--enable-features=SignedHTTPExchange,NetworkService"]
},
{
"prefix": "sampling-heap-profiler",
"base": "inspector-protocol/memory",
"args": ["--sampling-heap-profiler"]
} }
] ]
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(`Test sampling native memory snapshot.`);
// --sampling-heap-profiler enables sampling with interval 128KiB
// Maximum interval afterval after randomization is 20x, which is 2560KiB.
// That corresponds to a canvas of size 640x1024 with 32bits per pixel.
await session.evaluate(`
const canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 1024;
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 10, 10);
document.body.appendChild(canvas);
`);
const message = await dp.Memory.getAllTimeSamplingProfile();
const profile = message.result.profile;
const foundTheSample = profile.samples.some(sample =>
sample.size >= 640 * 1024 && sample.stack.some(frame => frame.includes('HTMLCanvasElement')));
testRunner.log('Found sample: ' + foundTheSample);
testRunner.completeTest();
})
# This suite runs the tests in virtual/sampling-heap-profiler/inspector-protocol/memory with
# --sampling-heap-profiler since the tests require sampling heap profiler being run since
# renderer process start.
...@@ -120,32 +120,42 @@ Response InspectorMemoryAgent::stopSampling() { ...@@ -120,32 +120,42 @@ Response InspectorMemoryAgent::stopSampling() {
return Response::OK(); return Response::OK();
} }
Response InspectorMemoryAgent::getAllTimeSamplingProfile(
std::unique_ptr<protocol::Memory::SamplingProfile>* out_profile) {
*out_profile = GetSamplingProfileById(0);
return Response::OK();
}
Response InspectorMemoryAgent::getSamplingProfile( Response InspectorMemoryAgent::getSamplingProfile(
std::unique_ptr<protocol::Memory::SamplingProfile>* out_profile) { std::unique_ptr<protocol::Memory::SamplingProfile>* out_profile) {
*out_profile = GetSamplingProfileById(profile_id_);
return Response::OK();
}
std::unique_ptr<protocol::Memory::SamplingProfile>
InspectorMemoryAgent::GetSamplingProfileById(uint32_t id) {
std::unique_ptr<protocol::Array<protocol::Memory::SamplingProfileNode>> std::unique_ptr<protocol::Array<protocol::Memory::SamplingProfileNode>>
samples = samples =
protocol::Array<protocol::Memory::SamplingProfileNode>::create(); protocol::Array<protocol::Memory::SamplingProfileNode>::create();
std::vector<SamplingNativeHeapProfiler::Sample> raw_samples = std::vector<SamplingNativeHeapProfiler::Sample> raw_samples =
SamplingNativeHeapProfiler::GetInstance()->GetSamples(profile_id_); SamplingNativeHeapProfiler::GetInstance()->GetSamples(id);
for (auto it = raw_samples.begin(); it != raw_samples.end(); ++it) { for (auto& it : raw_samples) {
std::unique_ptr<protocol::Array<protocol::String>> stack = std::unique_ptr<protocol::Array<protocol::String>> stack =
protocol::Array<protocol::String>::create(); protocol::Array<protocol::String>::create();
std::vector<std::string> source_stack = Symbolize(it->stack); std::vector<std::string> source_stack = Symbolize(it.stack);
for (auto it2 = source_stack.begin(); it2 != source_stack.end(); ++it2) for (auto& it2 : source_stack)
stack->addItem(it2->c_str()); stack->addItem(it2.c_str());
samples->addItem(protocol::Memory::SamplingProfileNode::create() samples->addItem(protocol::Memory::SamplingProfileNode::create()
.setSize(it->size) .setSize(it.size)
.setCount(it->count) .setCount(it.count)
.setStack(std::move(stack)) .setStack(std::move(stack))
.build()); .build());
} }
std::unique_ptr<protocol::Memory::SamplingProfile> result =
protocol::Memory::SamplingProfile::create() return protocol::Memory::SamplingProfile::create()
.setSamples(std::move(samples)) .setSamples(std::move(samples))
.build(); .build();
*out_profile = std::move(result);
return Response::OK();
} }
std::vector<std::string> InspectorMemoryAgent::Symbolize( std::vector<std::string> InspectorMemoryAgent::Symbolize(
......
...@@ -70,16 +70,19 @@ class CORE_EXPORT InspectorMemoryAgent final ...@@ -70,16 +70,19 @@ class CORE_EXPORT InspectorMemoryAgent final
protocol::Response stopSampling() override; protocol::Response stopSampling() override;
protocol::Response getSamplingProfile( protocol::Response getSamplingProfile(
std::unique_ptr<protocol::Memory::SamplingProfile>*) override; std::unique_ptr<protocol::Memory::SamplingProfile>*) override;
protocol::Response getAllTimeSamplingProfile(
std::unique_ptr<protocol::Memory::SamplingProfile>*) override;
private: private:
explicit InspectorMemoryAgent(InspectedFrames*); explicit InspectorMemoryAgent(InspectedFrames*);
std::vector<std::string> Symbolize(const std::vector<void*>& addresses); std::vector<std::string> Symbolize(const std::vector<void*>& addresses);
std::unique_ptr<protocol::Memory::SamplingProfile> GetSamplingProfileById(
uint32_t id);
std::unique_ptr<BlinkLeakDetector> detector_; std::unique_ptr<BlinkLeakDetector> detector_;
std::unique_ptr<PrepareForLeakDetectionCallback> callback_; std::unique_ptr<PrepareForLeakDetectionCallback> callback_;
Member<InspectedFrames> frames_; Member<InspectedFrames> frames_;
std::map<void*, std::string> symbols_cache_;
uint32_t profile_id_ = 0; uint32_t profile_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(InspectorMemoryAgent); DISALLOW_COPY_AND_ASSIGN(InspectorMemoryAgent);
......
...@@ -6997,9 +6997,19 @@ ...@@ -6997,9 +6997,19 @@
"name": "stopSampling", "name": "stopSampling",
"description": "Stop collecting native memory profile." "description": "Stop collecting native memory profile."
}, },
{
"name": "getAllTimeSamplingProfile",
"description": "Retrieve native memory allocations profile collected since process startup.",
"returns": [
{
"name": "profile",
"$ref": "SamplingProfile"
}
]
},
{ {
"name": "getSamplingProfile", "name": "getSamplingProfile",
"description": "Retrieve collected native memory profile.", "description": "Retrieve native memory allocations profile collected since last\n`startSampling` call.",
"returns": [ "returns": [
{ {
"name": "profile", "name": "profile",
......
...@@ -3165,7 +3165,13 @@ experimental domain Memory ...@@ -3165,7 +3165,13 @@ experimental domain Memory
# Stop collecting native memory profile. # Stop collecting native memory profile.
command stopSampling command stopSampling
# Retrieve collected native memory profile. # Retrieve native memory allocations profile collected since process startup.
command getAllTimeSamplingProfile
returns
SamplingProfile profile
# Retrieve native memory allocations profile collected since last
# `startSampling` call.
command getSamplingProfile command getSamplingProfile
returns returns
SamplingProfile profile SamplingProfile profile
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
}, },
{ {
"domain": "Memory", "domain": "Memory",
"include": ["getDOMCounters", "prepareForLeakDetection", "startSampling", "stopSampling", "getSamplingProfile"], "include": ["getDOMCounters", "prepareForLeakDetection", "startSampling", "stopSampling", "getSamplingProfile", "getAllTimeSamplingProfile"],
"async": ["prepareForLeakDetection"] "async": ["prepareForLeakDetection"]
}, },
{ {
......
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