Commit 457d6775 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

Reland "DevTools: Block SIGPROF during CPU throttling"

This is a reland of a5afd47a

Original change's description:
> DevTools: Block SIGPROF during CPU throttling
> 
> The V8 CPU profiler schedules SIGPROF signals. It is very likely that
> the signal handler for these will run while the throttling signal
> handler is already running. V8 can't properly read the stack when
> there is already a signal handler present.
> 
> Fix this by using sa_mask to block V8's SIGPROFs while the
> throttling handler is running. This makes more sense overall as well.
> Our CPU samples would be skewed by whichever stacks we encounter
> during throttling pauses.
> 
> Bug: 1027242
> Change-Id: I80e856ce1e7b4744a9af7e36c2022b6d8610cf60
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012280
> Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
> Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
> Commit-Queue: Peter Marshall <petermarshall@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#733592}

Bug: 1027242
Change-Id: I2c5c1e462f9f6f16739e773dda112bacd8b354f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014404
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734429}
parent fbc77338
...@@ -106,6 +106,9 @@ void ThreadCPUThrottler::ThrottlingThread::InstallSignalHandler() { ...@@ -106,6 +106,9 @@ void ThreadCPUThrottler::ThrottlingThread::InstallSignalHandler() {
struct sigaction sa; struct sigaction sa;
sa.sa_handler = &HandleSignal; sa.sa_handler = &HandleSignal;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
// Block SIGPROF while our handler is running so that the V8 CPU profiler
// doesn't try to sample the stack while our signal handler is active.
sigaddset(&sa.sa_mask, SIGPROF);
sa.sa_flags = SA_RESTART; sa.sa_flags = SA_RESTART;
signal_handler_installed_ = signal_handler_installed_ =
(sigaction(SIGUSR2, &sa, &old_signal_handler_) == 0); (sigaction(SIGUSR2, &sa, &old_signal_handler_) == 0);
......
(async function(testRunner) {
const {page, session, dp} = await testRunner.startBlank(
'Test that the profiler can record a profile with cpu throttling enabled.');
await dp.Emulation.setCPUThrottlingRate({rate: 4});
await dp.Profiler.enable();
await dp.Profiler.start();
// Run some JS for at least a second to give a chance for the two signals to
// overlap.
await session.evaluate(`
let count = 0;
const limit = 1e6;
let i = 0;
let target = new Date();
target.setSeconds(target.getSeconds() + 1);
let time = new Date();
while (i < limit && time < target) {
count += i;
i++;
time = new Date();
}
window.count = count;
`);
await dp.Profiler.stop();
testRunner.completeTest();
})
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