Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fadd4ae

Browse files
authored
Only allow the rundown thread to write events during rundown to avoid corruption of the trace file. (#17358)
1 parent cc76b83 commit fadd4ae

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/vm/eventpipe.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ void EventPipe::WriteEventInternal(EventPipeEvent &event, EventPipeEventPayload
594594
}
595595
else if(s_pConfig->RundownEnabled())
596596
{
597+
// It is possible that some events that are enabled on rundown can be emitted from other threads.
598+
// We're not interested in these events and they can cause corrupted trace files because rundown
599+
// events are written synchronously and not under lock.
600+
// If we encounter an event that did not originate on the thread that is doing rundown, ignore it.
601+
if(!s_pConfig->IsRundownThread(pThread))
602+
{
603+
return;
604+
}
605+
597606
BYTE *pData = payload.GetFlatData();
598607
if (pData != NULL)
599608
{

src/vm/eventpipeconfiguration.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ EventPipeConfiguration::EventPipeConfiguration()
1919

2020
m_enabled = false;
2121
m_rundownEnabled = false;
22+
m_pRundownThread = NULL;
2223
m_pConfigProvider = NULL;
2324
m_pSession = NULL;
2425
m_pProviderList = new SList<SListElem<EventPipeProvider*>>();
@@ -409,6 +410,7 @@ void EventPipeConfiguration::Disable(EventPipeSession *pSession)
409410

410411
m_enabled = false;
411412
m_rundownEnabled = false;
413+
m_pRundownThread = NULL;
412414
m_pSession = NULL;
413415
}
414416

@@ -440,8 +442,10 @@ void EventPipeConfiguration::EnableRundown(EventPipeSession *pSession)
440442
// Build the rundown configuration.
441443
_ASSERTE(m_pSession == NULL);
442444

443-
// Enable rundown.
445+
// Enable rundown and keep track of the rundown thread.
444446
// TODO: Move this into EventPipeSession once Enable takes an EventPipeSession object.
447+
m_pRundownThread = GetThread();
448+
_ASSERTE(m_pRundownThread != NULL);
445449
m_rundownEnabled = true;
446450

447451
// Enable tracing.

src/vm/eventpipeconfiguration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class EventPipeConfiguration
8282
// Delete deferred providers.
8383
void DeleteDeferredProviders();
8484

85+
// Determine if the specified thread is the rundown thread.
86+
// Used during rundown to ignore events from all other threads so that we don't corrupt the trace file.
87+
inline bool IsRundownThread(Thread *pThread)
88+
{
89+
LIMITED_METHOD_CONTRACT;
90+
91+
return (pThread == m_pRundownThread);
92+
}
93+
8594
private:
8695

8796
// Get the provider without taking the lock.
@@ -111,6 +120,9 @@ class EventPipeConfiguration
111120

112121
// True if rundown is enabled.
113122
Volatile<bool> m_rundownEnabled;
123+
124+
// The rundown thread. If rundown is not enabled, this is NULL.
125+
Thread *m_pRundownThread;
114126
};
115127

116128
#endif // FEATURE_PERFTRACING

0 commit comments

Comments
 (0)