Skip to content

Commit 94a0f6b

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Fix hang during file recorder shutdown due to drain function never running.
TEST=ci, rr chaos mode Bug: #59620 Change-Id: I806f836dc5e21bb5b7048f49ebda5188e9ce340e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400002 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent b479087 commit 94a0f6b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

runtime/vm/timeline.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ TimelineEventFileRecorderBase::~TimelineEventFileRecorderBase() {
20282028
void TimelineEventFileRecorderBase::Drain() {
20292029
MonitorLocker ml(&monitor_);
20302030
thread_id_ = OSThread::GetCurrentThreadJoinId(OSThread::Current());
2031+
ml.Notify();
20312032
for (;;) {
20322033
if (head_ == nullptr) {
20332034
if (shutting_down_) {
@@ -2080,6 +2081,16 @@ void TimelineEventFileRecorderBase::CompleteEvent(TimelineEvent* event) {
20802081
ml.Notify();
20812082
}
20822083

2084+
void TimelineEventFileRecorderBase::StartUp(const char* name) {
2085+
OSThread::Start(name, TimelineEventFileRecorderBaseStart,
2086+
reinterpret_cast<uword>(this));
2087+
2088+
MonitorLocker ml(&monitor_);
2089+
while (thread_id_ == OSThread::kInvalidThreadJoinId) {
2090+
ml.Wait();
2091+
}
2092+
}
2093+
20832094
// Must be called in derived class destructors.
20842095
// See |~TimelineEventFileRecorderBase()| for an explanation.
20852096
void TimelineEventFileRecorderBase::ShutDown() {
@@ -2100,9 +2111,7 @@ TimelineEventFileRecorder::TimelineEventFileRecorder(const char* path)
21002111
// missing ending bracket in this form in case we don't cleanly end the
21012112
// trace.
21022113
Write("[\n");
2103-
OSThread::Start("TimelineEventFileRecorder",
2104-
TimelineEventFileRecorderBaseStart,
2105-
reinterpret_cast<uword>(this));
2114+
StartUp("TimelineEventFileRecorder");
21062115
}
21072116

21082117
TimelineEventFileRecorder::~TimelineEventFileRecorder() {
@@ -2151,9 +2160,7 @@ TimelineEventPerfettoFileRecorder::TimelineEventPerfettoFileRecorder(
21512160
WritePacket(&packet);
21522161
packet.Reset();
21532162

2154-
OSThread::Start("TimelineEventPerfettoFileRecorder",
2155-
TimelineEventFileRecorderBaseStart,
2156-
reinterpret_cast<uword>(this));
2163+
StartUp("TimelineEventPerfettoFileRecorder");
21572164
}
21582165

21592166
TimelineEventPerfettoFileRecorder::~TimelineEventPerfettoFileRecorder() {

runtime/vm/timeline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ class TimelineEventFileRecorderBase : public TimelineEventPlatformRecorder {
12541254
void Write(const char* buffer, intptr_t len) const;
12551255
void Write(const char* buffer) const { Write(buffer, strlen(buffer)); }
12561256
void CompleteEvent(TimelineEvent* event) final;
1257+
void StartUp(const char* name);
12571258
void ShutDown();
12581259

12591260
private:

0 commit comments

Comments
 (0)