Skip to content

Commit 4c361ca

Browse files
Bikramjeet Vigfacebook-github-bot
Bikramjeet Vig
authored andcommitted
Fix data races flagged by tsan in ProfilerTest
Summary: Fixes a few data races flagged by tsan. Differential Revision: D54083227
1 parent ffd136f commit 4c361ca

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

velox/common/process/Profiler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ DEFINE_string(profiler_perf_flags, "", "Extra flags for Linux perf");
5454

5555
namespace facebook::velox::process {
5656

57-
bool Profiler::profileStarted_;
57+
tsan_atomic<bool> Profiler::profileStarted_;
5858
std::thread Profiler::profileThread_;
5959
std::mutex Profiler::profileMutex_;
6060
std::shared_ptr<velox::filesystems::FileSystem> Profiler::fileSystem_;
61-
bool Profiler::isSleeping_;
61+
tsan_atomic<bool> Profiler::isSleeping_;
6262
std::string Profiler::resultPath_;
63-
bool Profiler::shouldStop_;
63+
tsan_atomic<bool> Profiler::shouldStop_;
6464
folly::Promise<bool> Profiler::sleepPromise_;
65-
bool Profiler::shouldSaveResult_;
65+
tsan_atomic<bool> Profiler::shouldSaveResult_;
6666
int64_t Profiler::sampleStartTime_;
6767
int64_t Profiler::cpuAtSampleStart_;
6868
int64_t Profiler::cpuAtLastCheck_;

velox/common/process/Profiler.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ class Profiler {
4646
static void stopSample(std::thread thread);
4747
static void threadFunction();
4848

49-
static bool profileStarted_;
49+
static tsan_atomic<bool> profileStarted_;
5050
static std::thread profileThread_;
5151
static std::mutex profileMutex_;
5252
static std::shared_ptr<velox::filesystems::FileSystem> fileSystem_;
53-
static bool isSleeping_;
54-
static bool shouldStop_;
53+
static tsan_atomic<bool> isSleeping_;
54+
static tsan_atomic<bool> shouldStop_;
5555
static folly::Promise<bool> sleepPromise_;
5656

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

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

6464
// Time of starting the profile. Seconds from epoch.
6565
static int64_t sampleStartTime_;

velox/common/process/tests/ProfilerTest.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ TEST(ProfilerTest, basic) {
5656
return;
5757
#endif
5858
filesystems::registerLocalFileSystem();
59-
Profiler::start("/tmp/profilertest");
6059
// We have seconds of busy and idle activity. We set the profiler to
6160
// check every second and to trigger after 1s at 200%. A burst of
6261
// under 2s is not recorded and a new file is started after every 4s

0 commit comments

Comments
 (0)