diff options
author | David Mason <davmason@microsoft.com> | 2019-07-09 22:33:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-09 22:33:24 -0700 |
commit | d61a380bbfde580986f416d8bf3e687104cd5701 (patch) | |
tree | d0e68c614ddb138ae2cd01a988df07d6bb22b4cc /src/vm/eventpipesession.cpp | |
parent | 27790ab2dbee25d2e9c6fc41863aa7e983552a3f (diff) | |
download | coreclr-d61a380bbfde580986f416d8bf3e687104cd5701.tar.gz coreclr-d61a380bbfde580986f416d8bf3e687104cd5701.tar.bz2 coreclr-d61a380bbfde580986f416d8bf3e687104cd5701.zip |
Let EventPipe threads sleep when no events are available (#25601)
Don't spin forever in EventListener when listening for EventPipe data
Diffstat (limited to 'src/vm/eventpipesession.cpp')
-rw-r--r-- | src/vm/eventpipesession.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/vm/eventpipesession.cpp b/src/vm/eventpipesession.cpp index ca007dc570..8d2ff65fa1 100644 --- a/src/vm/eventpipesession.cpp +++ b/src/vm/eventpipesession.cpp @@ -164,6 +164,7 @@ DWORD WINAPI EventPipeSession::ThreadProc(void *args) Thread *const pThisThread = pEventPipeSession->GetIpcStreamingThread(); bool fSuccess = true; + CLREvent *waitEvent = pEventPipeSession->GetWaitEvent(); { GCX_PREEMP(); @@ -171,12 +172,19 @@ DWORD WINAPI EventPipeSession::ThreadProc(void *args) { while (pEventPipeSession->IsIpcStreamingEnabled()) { - if (!pEventPipeSession->WriteAllBuffersToFile()) + bool eventsWritten = false; + if (!pEventPipeSession->WriteAllBuffersToFile(&eventsWritten)) { fSuccess = false; break; } + if (!eventsWritten) + { + // No events were available, sleep until more are available + waitEvent->Wait(INFINITE, FALSE); + } + // Wait until it's time to sample again. PlatformSleep(); } @@ -274,7 +282,7 @@ EventPipeSessionProvider *EventPipeSession::GetSessionProvider(const EventPipePr return m_pProviderList->GetSessionProvider(pProvider); } -bool EventPipeSession::WriteAllBuffersToFile() +bool EventPipeSession::WriteAllBuffersToFile(bool *pEventsWritten) { CONTRACTL { @@ -292,7 +300,7 @@ bool EventPipeSession::WriteAllBuffersToFile() // the current timestamp are written into the file. LARGE_INTEGER stopTimeStamp; QueryPerformanceCounter(&stopTimeStamp); - m_pBufferManager->WriteAllBuffersToFile(m_pFile, stopTimeStamp); + m_pBufferManager->WriteAllBuffersToFile(m_pFile, stopTimeStamp, pEventsWritten); return !m_pFile->HasErrors(); } @@ -350,6 +358,13 @@ EventPipeEventInstance *EventPipeSession::GetNextEvent() return m_pBufferManager->GetNextEvent(); } +CLREvent *EventPipeSession::GetWaitEvent() +{ + LIMITED_METHOD_CONTRACT; + + return m_pBufferManager->GetWaitEvent(); +} + void EventPipeSession::Enable() { CONTRACTL @@ -430,6 +445,9 @@ void EventPipeSession::DisableIpcStreamingThread() // when profiling is disabled. m_ipcStreamingEnabled = false; + // Thread could be waiting on the event that there is new data to read. + m_pBufferManager->GetWaitEvent()->Set(); + // Wait for the sampling thread to clean itself up. m_threadShutdownEvent.Wait(INFINITE, FALSE /* bAlertable */); m_threadShutdownEvent.CloseEvent(); @@ -448,7 +466,8 @@ void EventPipeSession::Disable() if ((m_SessionType == EventPipeSessionType::IpcStream) && m_ipcStreamingEnabled) DisableIpcStreamingThread(); - WriteAllBuffersToFile(); + bool ignored; + WriteAllBuffersToFile(&ignored); m_pProviderList->Clear(); } |