Skip to content

Commit

Permalink
[profiler] Reintroduce context filtering in blink
Browse files Browse the repository at this point in the history
Provide a non-null |v8::Context| param to filter profiles by originating
context, now that context filtering has been reintroduced in blink.
Modify existing WPTs to be compliant with this, as well as use a more
realistic test for filtering.

Bug: 956688
Change-Id: I60c23fdac29af9f452d21f57496fd2f8fc20826e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2852074
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Andrew Comminos <acomminos@fb.com>
Cr-Commit-Position: refs/heads/master@{#878111}
  • Loading branch information
acomminos authored and Chromium LUCI CQ committed Apr 30, 2021
1 parent b154c82 commit 6a72247
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 64 deletions.
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/timing/profiler_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Profiler* ProfilerGroup::CreateProfiler(ScriptState* script_state,
v8::kLeafNodeLineNumbers,
init_options.hasMaxBufferSize() ? init_options.maxBufferSize()
: v8::CpuProfilingOptions::kNoSampleLimit,
static_cast<int>(sample_interval_us), v8::MaybeLocal<v8::Context>());
static_cast<int>(sample_interval_us), script_state->GetContext());

v8::CpuProfilingStatus status = cpu_profiler_->StartProfiling(
V8String(isolate_, profiler_id), options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<iframe src="resources/child-frame.html"></iframe>

<script>
function parentCollectSample(profiler) {
ProfileUtils.forceSample(profiler);
}

promise_test(_ => new Promise(res => window.addEventListener('load', res)),
'wait for load event');

Expand All @@ -23,54 +19,17 @@
});

const iframe = frames[0];
function parentWrapper() {
iframe.childCollectSample(profiler);
}
parentWrapper();

const trace = await profiler.stop();

assert_true(ProfileUtils.containsFrame(trace, { name: 'parentWrapper' }),
'function from own (parent) context included in trace');

assert_true(ProfileUtils.containsFrame(trace, { name: 'childCollectSample' }),
'function from child context included in trace');

assert_true(ProfileUtils.containsFrame(trace, { name: 'parentCollectSample' }),
'sampling wrapper function from own (parent) context included in trace');

const childUrl = iframe.location.href;
assert_true(ProfileUtils.containsResource(trace, childUrl),
'child resources are included');
}, 'functions from child frame are included in profile created by parent frame');

promise_test(async t => {
const iframe = frames[0];
const profiler = await iframe.childCreateProfiler({
sampleInterval: 10,
});

(function parentWrapper() {
iframe.childCollectSample(profiler);
})();
await ProfileUtils.forceSampleFrame(iframe);

const trace = await profiler.stop();

assert_true(ProfileUtils.containsFrame(trace, { name: 'parentWrapper' }),
'function from parent context included in trace');

assert_true(ProfileUtils.containsFrame(trace, { name: 'childCollectSample' }),
'function from own (child) context included in trace');

assert_true(ProfileUtils.containsResource(trace,
window.location.href,
), 'parent resource is included');

assert_true(ProfileUtils.containsResource(trace,
iframe.location.href,
), 'child resource is included');
assert_false(ProfileUtils.containsFrame(trace, { name: 'sampleFromMessage' }),
'function from child context not included in trace');

}, 'functions from parent context are included in profile created by child frame');
const childUrl = iframe.src;
assert_false(ProfileUtils.containsResource(trace, childUrl),
'child resources are not included');
}, 'functions from child frame are not included in profile created by parent frame');
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
}, 'max buffer size is not exceeded');

promise_test(async t => {
const profiler = await performance.profile({
sampleInterval: 10,
maxBufferSize: 1,
});
const profiler = await performance.profile({
sampleInterval: 10,
maxBufferSize: 1,
});

const watcher = new EventWatcher(t, profiler, ['samplebufferfull']);

for (let i = 0; i < 10; i++) {
ProfileUtils.forceSample();
}

const watcher = new EventWatcher(t, profiler, ['samplebufferfull']);
return watcher.wait_for('samplebufferfull');
return watcher.wait_for('samplebufferfull');
}, 'executed samplebufferfull function');
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
<head>
</head>
<body>
<script>
function childCreateProfiler(options) {
return performance.profile(options);
}

function childCollectSample(profiler) {
top.parentCollectSample(profiler);
}
</script>
<script src="profile-utils.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@
(expected.column === undefined || expected.column === actual.column);
}

function forceSampleFrame(frame) {
const channel = new MessageChannel();
const replyPromise = new Promise(res => {
channel.port1.onmessage = res;
});
frame.postMessage('', '*', [channel.port2]);
return replyPromise;
}

window.addEventListener('message', message => {
// Force sample in response to messages received.
(function sampleFromMessage() {
ProfileUtils.forceSample();
message.ports[0].postMessage('');
})();
});

global.ProfileUtils = {
// Capturing
profileFunction,
Expand All @@ -93,6 +110,9 @@
containsSubstack,
containsResource,

// Cross-frame sampling
forceSampleFrame,

// Assertions
testFunction,
};
Expand Down

0 comments on commit 6a72247

Please sign in to comment.