Skip to content

Commit

Permalink
Fix data races flagged by tsan in ProfilerTest
Browse files Browse the repository at this point in the history
Summary: Fixes a few data races flagged by tsan.

Differential Revision: D54083227
  • Loading branch information
Bikramjeet Vig authored and facebook-github-bot committed Feb 22, 2024
1 parent ffd136f commit 4c361ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions velox/common/process/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ DEFINE_string(profiler_perf_flags, "", "Extra flags for Linux perf");

namespace facebook::velox::process {

bool Profiler::profileStarted_;
tsan_atomic<bool> Profiler::profileStarted_;
std::thread Profiler::profileThread_;
std::mutex Profiler::profileMutex_;
std::shared_ptr<velox::filesystems::FileSystem> Profiler::fileSystem_;
bool Profiler::isSleeping_;
tsan_atomic<bool> Profiler::isSleeping_;
std::string Profiler::resultPath_;
bool Profiler::shouldStop_;
tsan_atomic<bool> Profiler::shouldStop_;
folly::Promise<bool> Profiler::sleepPromise_;
bool Profiler::shouldSaveResult_;
tsan_atomic<bool> Profiler::shouldSaveResult_;
int64_t Profiler::sampleStartTime_;
int64_t Profiler::cpuAtSampleStart_;
int64_t Profiler::cpuAtLastCheck_;
Expand Down
8 changes: 4 additions & 4 deletions velox/common/process/Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ class Profiler {
static void stopSample(std::thread thread);
static void threadFunction();

static bool profileStarted_;
static tsan_atomic<bool> profileStarted_;
static std::thread profileThread_;
static std::mutex profileMutex_;
static std::shared_ptr<velox::filesystems::FileSystem> fileSystem_;
static bool isSleeping_;
static bool shouldStop_;
static tsan_atomic<bool> isSleeping_;
static tsan_atomic<bool> shouldStop_;
static folly::Promise<bool> sleepPromise_;

// Directory where results are deposited. Results have unique names within
// this.
static std::string resultPath_;

// indicates if the results of the the profile should be saved at stop.
static bool shouldSaveResult_;
static tsan_atomic<bool> shouldSaveResult_;

// Time of starting the profile. Seconds from epoch.
static int64_t sampleStartTime_;
Expand Down
1 change: 0 additions & 1 deletion velox/common/process/tests/ProfilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ TEST(ProfilerTest, basic) {
return;
#endif
filesystems::registerLocalFileSystem();
Profiler::start("/tmp/profilertest");
// We have seconds of busy and idle activity. We set the profiler to
// check every second and to trigger after 1s at 200%. A burst of
// under 2s is not recorded and a new file is started after every 4s
Expand Down

0 comments on commit 4c361ca

Please sign in to comment.