// Take the lock before disabling tracing.
CrstHolder _crst(GetLock());
+ DisableInternal(reinterpret_cast<EventPipeSessionID>(s_pSession));
+}
+
+void EventPipe::DisableInternal(EventPipeSessionID id)
+{
+ CONTRACTL
+ {
+ THROWS;
+ GC_TRIGGERS;
+ MODE_ANY;
+ PRECONDITION(GetLock()->OwnedByCurrentThread());
+ }
+ CONTRACTL_END;
if (s_pConfig != NULL && s_pConfig->Enabled())
{
}
CONTRACTL_END;
+ GCX_PREEMP();
+
// Take the lock control lock to make sure that tracing isn't disabled during this operation.
CrstHolder _crst(GetLock());
if (!Enabled() || s_pSession->GetSessionType() != EventPipeSessionType::IpcStream)
return;
- GCX_PREEMP();
-
if (CLRGetTickCount64() > (s_lastFlushSwitchTime + 100))
{
// Get the current time stamp.
s_lastFlushSwitchTime = CLRGetTickCount64();
}
+
+ if (s_pFile->HasErrors())
+ {
+ EX_TRY
+ {
+ DisableInternal(reinterpret_cast<EventPipeSessionID>(s_pSession));
+ }
+ EX_CATCH {}
+ EX_END_CATCH(SwallowAllExceptions);
+ }
}
EventPipeSession *EventPipe::GetSession(EventPipeSessionID id)
// The counterpart to WriteEvent which after the payload is constructed
static void WriteEventInternal(EventPipeEvent &event, EventPipeEventPayload &payload, LPCGUID pActivityId = NULL, LPCGUID pRelatedActivityId = NULL);
+ static void DisableInternal(EventPipeSessionID id);
+
// Enable the specified EventPipe session.
static EventPipeSessionID Enable(
LPCWSTR strOutputPath,
delete m_pSerializer;
}
+bool EventPipeFile::HasErrors() const
+{
+ LIMITED_METHOD_CONTRACT;
+ return (m_pSerializer == nullptr) || m_pSerializer->HasWriteErrors();
+}
+
void EventPipeFile::WriteEvent(EventPipeEventInstance &instance)
{
CONTRACTL
void WriteEvent(EventPipeEventInstance &instance);
void Flush();
+ bool HasErrors() const;
const char *GetTypeName() override
{
EX_TRY
{
uint32_t outCount;
- m_pStreamWriter->Write(pBuffer, length, outCount);
+ bool fSuccess = m_pStreamWriter->Write(pBuffer, length, outCount);
#ifdef _DEBUG
size_t prevPos = m_currentPos;
// This will cause us to stop writing to the file.
// The file will still remain open until shutdown so that we don't
// have to take a lock at this level when we touch the file stream.
- m_writeErrorEncountered = (length != outCount);
+ m_writeErrorEncountered = (length != outCount) || !fSuccess;
#ifdef _DEBUG
_ASSERTE(m_writeErrorEncountered || (prevPos < m_currentPos));
};
//!
-//! Implements a StreamWriter for writing bytes to an File.
+//! Implements a StreamWriter for writing bytes to a File.
//!
class FileStreamWriter final : public StreamWriter
{