Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability for profilers to listen to EventPipe events #37002

Merged
merged 24 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
40d9308
Proof of concept synchronous profiler EventPipe events
davmason May 24, 2020
7e2bbd8
Add provider callback and ability to query provider name
davmason May 25, 2020
a6ecda8
add guids to API
davmason May 26, 2020
af29c79
stop creating a buffer manager for synchronous sessions
davmason May 26, 2020
7198ac5
Take lock before adding provider to session
davmason May 26, 2020
7f3642c
fix linux build error
davmason May 26, 2020
1eb39d7
refactoring
davmason May 28, 2020
ce70d00
Get rid of enablecpusampling argument
davmason Jun 19, 2020
d644cba
move EventPipeProviderCreated profiler callback outside of lock
davmason Jun 19, 2020
8d1b5bc
refactor SuspendWriteEvent so it covers the synchronous callback case…
davmason Jun 20, 2020
7cb9a1a
after EventPipe starts shutting down return an error for EventPipeSta…
davmason Jun 21, 2020
c132d07
switch to spinlock since we can't use crst in gc_notrigger/coop
davmason Jun 22, 2020
ee9aee8
Add assert and remove unused variable
davmason Jun 23, 2020
540d8e3
Move storing null to the session array before EventPipeSession::Suspe…
davmason Jun 23, 2020
5eca5ef
remove spurious assert
davmason Jun 23, 2020
619f4b8
Fix SampleProfiler refcount issue, double profiler callback, remove u…
davmason Jun 24, 2020
7905bcf
remove the concept of m_writeEventSuspending from the buffer manager …
davmason Jun 24, 2020
96d8cc4
Add test
davmason May 26, 2020
87ceca4
add description of filter data format
davmason Jun 25, 2020
0cc9a28
fix x86 test build issues
davmason Jun 25, 2020
008dabd
exlcude test from mono
davmason Jun 26, 2020
68e3479
move waiting on threads to finish writing outside of the lock
davmason Jun 26, 2020
2c3429e
allow call to GetProviderInfo to get the length of the name
davmason Jun 27, 2020
5ab6fd0
Fix formatting
davmason Jun 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 73 additions & 7 deletions src/coreclr/src/inc/corprof.idl
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,14 @@ typedef enum
// Enables the large object allocation monitoring according to the LOH threshold.
COR_PRF_HIGH_MONITOR_LARGEOBJECT_ALLOCATED = 0x00000040,

COR_PRF_HIGH_MONITOR_EVENT_PIPE = 0x00000080,

COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED |
COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS |
COR_PRF_HIGH_BASIC_GC |
COR_PRF_HIGH_MONITOR_GC_MOVED_OBJECTS |
COR_PRF_HIGH_MONITOR_LARGEOBJECT_ALLOCATED,
COR_PRF_HIGH_MONITOR_LARGEOBJECT_ALLOCATED |
COR_PRF_HIGH_MONITOR_EVENT_PIPE,
davmason marked this conversation as resolved.
Show resolved Hide resolved

// MONITOR_IMMUTABLE represents all flags that may only be set during initialization.
// Trying to change any of these flags elsewhere will result in a
Expand Down Expand Up @@ -738,9 +741,11 @@ typedef enum

typedef UINT_PTR EVENTPIPE_PROVIDER;
typedef UINT_PTR EVENTPIPE_EVENT;
typedef UINT64 EVENTPIPE_SESSION;

typedef enum
{
COR_PRF_EVENTPIPE_OBJECT = 1, // Instance that isn't a value
davmason marked this conversation as resolved.
Show resolved Hide resolved
COR_PRF_EVENTPIPE_BOOLEAN = 3, // Boolean
COR_PRF_EVENTPIPE_CHAR = 4, // Unicode character
COR_PRF_EVENTPIPE_SBYTE = 5, // Signed 8-bit integer
Expand Down Expand Up @@ -770,6 +775,18 @@ typedef enum
COR_PRF_EVENTPIPE_VERBOSE = 5
} COR_PRF_EVENTPIPE_LEVEL;

typedef struct
{
const WCHAR* providerName;
UINT64 keywords;
UINT32 loggingLevel;
// filterData expects a semicolon delimited string that defines key value pairs
// such as "key1=value1;key2=value2;". Quotes can be used to escape the '=' and ';'
// characters. These key value pairs will be passed in the enable callback to event
// providers
const WCHAR* filterData;
davmason marked this conversation as resolved.
Show resolved Hide resolved
} COR_PRF_EVENTPIPE_PROVIDER_CONFIG;

typedef struct
{
UINT32 type;
Expand Down Expand Up @@ -2510,6 +2527,34 @@ interface ICorProfilerCallback9 : ICorProfilerCallback8
HRESULT DynamicMethodUnloaded([in] FunctionID functionId);
}

[
object,
uuid(CEC5B60E-C69C-495F-87F6-84D28EE16FFB),
pointer_default(unique),
local
]
interface ICorProfilerCallback10 : ICorProfilerCallback9
{
// This event is triggered whenever an EventPipe event is configured to be delivered.
//
// Documentation Note: All pointers are only valid during the callback

HRESULT EventPipeEventDelivered(
[in] EVENTPIPE_PROVIDER provider,
[in] DWORD eventId,
[in] DWORD eventVersion,
[in] ULONG cbMetadataBlob,
[in, size_is(cbMetadataBlob)] LPCBYTE metadataBlob,
[in] ULONG cbEventData,
[in, size_is(cbEventData)] LPCBYTE eventData,
[in] LPCGUID pActivityId,
[in] LPCGUID pRelatedActivityId,
[in] ThreadID eventThread,
[in] ULONG numStackFrames,
[in, length_is(numStackFrames)] UINT_PTR stackFrames[]);

HRESULT EventPipeProviderCreated([in] EVENTPIPE_PROVIDER provider);
davmason marked this conversation as resolved.
Show resolved Hide resolved
}

/*
* COR_PRF_CODEGEN_FLAGS controls various flags and hooks for a specific
Expand Down Expand Up @@ -4076,13 +4121,34 @@ interface ICorProfilerInfo11 : ICorProfilerInfo10
]
interface ICorProfilerInfo12 : ICorProfilerInfo11
{
HRESULT EventPipeStartSession(
[in] UINT32 cProviderConfigs,
[in, size_is(cProviderConfigs)]
COR_PRF_EVENTPIPE_PROVIDER_CONFIG pProviderConfigs[],
[in] BOOL requestRundown,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestMetadataDump?

[out] EVENTPIPE_SESSION* pSession);

HRESULT EventPipeAddProviderToSession(
davmason marked this conversation as resolved.
Show resolved Hide resolved
[in] EVENTPIPE_SESSION session,
[in] COR_PRF_EVENTPIPE_PROVIDER_CONFIG providerConfig);

HRESULT EventPipeStopSession(
[in] EVENTPIPE_SESSION session);

HRESULT EventPipeCreateProvider(
[in, string] const WCHAR *szName,
[out] EVENTPIPE_PROVIDER *pProviderHandle);
[in, string] const WCHAR *providerName,
[out] EVENTPIPE_PROVIDER *pProvider);

HRESULT EventPipeGetProviderInfo(
[in] EVENTPIPE_PROVIDER provider,
[in] ULONG cchName,
[out] ULONG *pcchName,
[out, annotation("_Out_writes_to_(cchName, *pcchName)")]
WCHAR providerName[]);

HRESULT EventPipeDefineEvent(
[in] EVENTPIPE_PROVIDER provHandle,
[in, string] const WCHAR *szName,
[in] EVENTPIPE_PROVIDER provider,
[in, string] const WCHAR *eventName,
[in] UINT32 eventID,
[in] UINT64 keywords,
[in] UINT32 eventVersion,
Expand All @@ -4092,10 +4158,10 @@ interface ICorProfilerInfo12 : ICorProfilerInfo11
[in] UINT32 cParamDescs,
[in, size_is(cParamDescs)]
COR_PRF_EVENTPIPE_PARAM_DESC pParamDescs[],
[out] EVENTPIPE_EVENT *pEventHandle);
[out] EVENTPIPE_EVENT *pEvent);

HRESULT EventPipeWriteEvent(
[in] EVENTPIPE_EVENT eventHandle,
[in] EVENTPIPE_EVENT event,
[in] UINT32 cData,
[in, size_is(cData)]
COR_PRF_EVENT_DATA data[],
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/src/inc/profilepriv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,20 @@ inline BOOL CORProfilerTrackGCMovedObjects()
((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_MONITOR_GC_MOVED_OBJECTS));
}

inline BOOL CORProfilerIsMonitoringEventPipe()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
CANNOT_TAKE_LOCK;
}
CONTRACTL_END;

return (CORProfilerPresent() &&
((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_MONITOR_EVENT_PIPE));
}

#if defined(PROFILING_SUPPORTED) && !defined(CROSSGEN_COMPILE)

#if defined(FEATURE_PROFAPI_ATTACH_DETACH)
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/src/pal/prebuilt/idl/corprof_i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#ifdef __cplusplus
extern "C"{
#endif
#endif


#include <rpc.h>
Expand Down Expand Up @@ -88,6 +88,9 @@ MIDL_DEFINE_GUID(IID, IID_ICorProfilerCallback8,0x5BED9B15,0xC079,0x4D47,0xBF,0x
MIDL_DEFINE_GUID(IID, IID_ICorProfilerCallback9,0x27583EC3,0xC8F5,0x482F,0x80,0x52,0x19,0x4B,0x8C,0xE4,0x70,0x5A);


MIDL_DEFINE_GUID(IID, IID_ICorProfilerCallback10,0xCEC5B60E,0xC69C,0x495F,0x87,0xF6,0x84,0xD2,0x8E,0xE1,0x6F,0xFB);


MIDL_DEFINE_GUID(IID, IID_ICorProfilerInfo,0x28B5557D,0x3F3F,0x48b4,0x90,0xB2,0x5F,0x9E,0xEA,0x2F,0x6C,0x48);


Expand Down
Loading