summaryrefslogtreecommitdiff
path: root/src/vm/eventpipeeventsource.cpp
diff options
context:
space:
mode:
authorBrian Robbins <brianrob@microsoft.com>2018-03-21 13:31:04 -0700
committerGitHub <noreply@github.com>2018-03-21 13:31:04 -0700
commitb82063e24b34c875891916a1bbc01728b9022bf3 (patch)
tree8af81814d735831c09ed7b354b0c1b00ff331783 /src/vm/eventpipeeventsource.cpp
parent166258a0b07246bb829695cebb1223b057339b49 (diff)
downloadcoreclr-b82063e24b34c875891916a1bbc01728b9022bf3.tar.gz
coreclr-b82063e24b34c875891916a1bbc01728b9022bf3.tar.bz2
coreclr-b82063e24b34c875891916a1bbc01728b9022bf3.zip
Add More Process Information to EventPipe Traces (#17080)
Diffstat (limited to 'src/vm/eventpipeeventsource.cpp')
-rw-r--r--src/vm/eventpipeeventsource.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/vm/eventpipeeventsource.cpp b/src/vm/eventpipeeventsource.cpp
new file mode 100644
index 0000000000..1a5cf2a3f3
--- /dev/null
+++ b/src/vm/eventpipeeventsource.cpp
@@ -0,0 +1,118 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "common.h"
+#include "eventpipeeventsource.h"
+#include "eventpipe.h"
+#include "eventpipeevent.h"
+#include "eventpipemetadatagenerator.h"
+#include "eventpipeprovider.h"
+#include "eventpipesession.h"
+
+#ifdef FEATURE_PERFTRACING
+
+const WCHAR* EventPipeEventSource::s_pProviderName = W("Microsoft-DotNETCore-EventPipe");
+const WCHAR* EventPipeEventSource::s_pProcessInfoEventName = W("ProcessInfo");
+
+EventPipeEventSource::EventPipeEventSource()
+{
+ CONTRACTL
+ {
+ THROWS;
+ GC_NOTRIGGER;
+ MODE_ANY;
+ }
+ CONTRACTL_END;
+
+ m_pProvider = EventPipe::CreateProvider(SL(s_pProviderName), NULL, NULL);
+
+ // Generate metadata.
+ const unsigned int numParams = 1;
+ EventPipeParameterDesc params[numParams];
+ params[0].Type = EventPipeParameterType::String;
+ params[0].Name = W("CommandLine");
+
+ size_t metadataLength = 0;
+ BYTE *pMetadata = EventPipeMetadataGenerator::GenerateEventMetadata(
+ 1, /* eventID */
+ s_pProcessInfoEventName,
+ 0, /* keywords */
+ 0, /* version */
+ EventPipeEventLevel::LogAlways,
+ params,
+ numParams,
+ metadataLength);
+
+ // Add the event.
+ m_pProcessInfoEvent = m_pProvider->AddEvent(
+ 1, /* eventID */
+ 0, /* keywords */
+ 0, /* eventVersion */
+ EventPipeEventLevel::LogAlways,
+ pMetadata,
+ (unsigned int)metadataLength);
+
+ // Delete the metadata after the event is created.
+ // The metadata blob will be copied into EventPipe-owned memory.
+ delete(pMetadata);
+}
+
+EventPipeEventSource::~EventPipeEventSource()
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_TRIGGERS;
+ MODE_ANY;
+ }
+ CONTRACTL_END;
+
+ // Delete the provider and associated events.
+ // This is called in the shutdown path which can't throw.
+ // Catch exceptions and ignore failures.
+ EX_TRY
+ {
+ EventPipe::DeleteProvider(m_pProvider);
+ }
+ EX_CATCH { }
+ EX_END_CATCH(SwallowAllExceptions);
+}
+
+void EventPipeEventSource::Enable(EventPipeSession *pSession)
+{
+ CONTRACTL
+ {
+ THROWS;
+ GC_TRIGGERS;
+ MODE_ANY;
+ PRECONDITION(pSession != NULL);
+ }
+ CONTRACTL_END;
+
+ EventPipeSessionProvider *pSessionProvider = new EventPipeSessionProvider(
+ s_pProviderName,
+ -1,
+ EventPipeEventLevel::LogAlways);
+ pSession->AddSessionProvider(pSessionProvider);
+}
+
+void EventPipeEventSource::SendProcessInfo(LPCWSTR pCommandLine)
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_NOTRIGGER;
+ MODE_ANY;
+ }
+ CONTRACTL_END;
+
+ EventData data[1];
+ data[0].Ptr = (UINT64) pCommandLine;
+ data[0].Size = (unsigned int)(wcslen(pCommandLine) + 1) * 2;
+ data[0].Reserved = 0;
+
+ EventPipe::WriteEvent(*m_pProcessInfoEvent, data, 1);
+}
+
+#endif // FEATURE_PERFTRACING