Commit 62bee2d7 authored by Naman Gupta's avatar Naman Gupta Committed by Facebook Github Bot

Don't record stack position for ASAN builds

Summary: Disable recording highWaterMark for asan builds. I discovered this while using getHighWatermark method on test runs (build with ASAN).  It gave bogus value (>90MB), when stack size was only 24k.

Reviewed By: andriigrynenko

Differential Revision: D9687204

fbshipit-source-id: 7ca311acb6f310694850f065febc3998a11d036a
parent 97290bca
......@@ -112,6 +112,9 @@ Fiber::~Fiber() {
}
void Fiber::recordStackPosition() {
// For ASAN builds, functions may run on fake stack.
// So we cannot get meaningful stack position.
#ifndef FOLLY_SANITIZE_ADDRESS
int stackDummy;
auto currentPosition = static_cast<size_t>(
fiberStackLimit_ + fiberStackSize_ -
......@@ -119,6 +122,7 @@ void Fiber::recordStackPosition() {
fiberManager_.stackHighWatermark_ =
std::max(fiberManager_.stackHighWatermark_, currentPosition);
VLOG(4) << "Stack usage: " << currentPosition;
#endif
}
[[noreturn]] void Fiber::fiberFunc() {
......
......@@ -2177,14 +2177,29 @@ TEST(TimedMutex, ThreadFiberDeadlockRace) {
EXPECT_EQ(0, fm.hasTasks());
}
namespace {
// Checks whether stackHighWatermark is set for non-ASAN builds,
// and not set for ASAN builds.
#ifndef FOLLY_SANITIZE_ADDRESS
void expectStackHighWatermark(size_t minStackSize, size_t stackHighWatermark) {
// Check that we properly accounted fiber stack usage
EXPECT_NE(0, stackHighWatermark);
EXPECT_LT(minStackSize, stackHighWatermark);
}
#else
void expectStackHighWatermark(size_t, size_t stackHighWatermark) {
// For ASAN, stackHighWatermark is not tracked.
EXPECT_EQ(0, stackHighWatermark);
}
#endif
} // namespace
/**
* Test that we can properly track fiber stack usage.
*
* This functionality can only be enabled when ASAN is disabled, so avoid
* running this test with ASAN.
* Test that we can properly track fiber stack usage, via recordStackEvery
* For ASAN builds, it is not recorded.
*/
#ifndef FOLLY_SANITIZE_ADDRESS
TEST(FiberManager, recordStack) {
TEST(FiberManager, highWaterMarkViaRecordStackEvery) {
auto f = [] {
folly::fibers::FiberManager::Options opts;
opts.recordStackEvery = 1;
......@@ -2208,10 +2223,39 @@ TEST(FiberManager, recordStack) {
(void)s;
loopController.loop([&]() { loopController.stop(); });
expectStackHighWatermark(n * sizeof(int), fm.stackHighWatermark());
};
std::thread(f).join();
}
// Check that we properly accounted fiber stack usage.
EXPECT_LT(n * sizeof(int), fm.stackHighWatermark());
/**
* Test that we can properly track fiber stack usage,
* via current position estimate. For ASAN builds, it is not recorded.
*/
TEST(FiberManager, highWaterMarkViaRecordCurrentPosition) {
auto f = [] {
FiberManager fm(std::make_unique<SimpleLoopController>());
auto& loopController =
dynamic_cast<SimpleLoopController&>(fm.loopController());
static constexpr size_t n = 1000;
int s = 0;
fm.addTask([&]() {
int b[n] = {0};
for (size_t i = 0; i < n; ++i) {
b[i] = i;
}
for (size_t i = 0; i + 1 < n; ++i) {
s += b[i] * b[i + 1];
}
// Calls preempt, which calls recordStackPosition.
fm.runInMainContext([]() {});
});
(void)s;
loopController.loop([&]() { loopController.stop(); });
expectStackHighWatermark(n * sizeof(int), fm.stackHighWatermark());
};
std::thread(f).join();
}
#endif
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