Skip to content

Commit 212dd95

Browse files
neildharfacebook-github-bot
authored andcommitted
Fix timer loop exit condition for sampling profiler
Summary: There is a bug in the timer loop implementation. If the profiler is disabled even before a single iteration of the loop can execute, it attempts to take a sample instead of exiting immediately. This has been a source of test flakiness. Reviewed By: dulinriley Differential Revision: D26108740 fbshipit-source-id: 9bf706c996288dff233288137cf3f17ffcb64b2f
1 parent 51241e9 commit 212dd95

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

lib/VM/Profiler/SamplingProfilerPosix.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,17 @@ void SamplingProfiler::GlobalProfiler::timerLoop() {
215215
kMeanMilliseconds, kStdDevMilliseconds};
216216
std::unique_lock<std::mutex> uniqueLock(profilerLock_);
217217

218-
while (true) {
218+
while (enabled_) {
219219
if (!sampleStack()) {
220220
return;
221221
}
222222

223223
const uint64_t millis = round(std::fabs(distribution(gen)));
224224
// TODO: make sampling rate configurable.
225-
bool disabled = enabledCondVar_.wait_for(
225+
enabledCondVar_.wait_for(
226226
uniqueLock, std::chrono::milliseconds(millis), [this]() {
227227
return !enabled_;
228228
});
229-
if (disabled) {
230-
// The sampling profiler was disabled: don't continue sampling.
231-
return;
232-
}
233-
// Else there was a timeout, which means enabled_ wasn't changed while this
234-
// function was waiting. Continue to sample the stack.
235229
}
236230
}
237231

0 commit comments

Comments
 (0)