| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | #ifndef __EVENTPIPE_EVENTINSTANCE_H__ |
| 6 | #define __EVENTPIPE_EVENTINSTANCE_H__ |
| 7 | |
| 8 | #ifdef FEATURE_PERFTRACING |
| 9 | |
| 10 | #include "eventpipe.h" |
| 11 | #include "eventpipeevent.h" |
| 12 | #include "eventpipesession.h" |
| 13 | #include "eventpipeblock.h" |
| 14 | #include "fastserializableobject.h" |
| 15 | #include "fastserializer.h" |
| 16 | |
| 17 | class EventPipeEventInstance |
| 18 | { |
| 19 | // Declare friends. |
| 20 | friend EventPipeConfiguration; |
| 21 | |
| 22 | public: |
| 23 | |
| 24 | EventPipeEventInstance(EventPipeSession &session, EventPipeEvent &event, DWORD threadID, BYTE *pData, unsigned int length, LPCGUID pActivityId, LPCGUID pRelatedActivityId); |
| 25 | |
| 26 | StackContents* GetStack() |
| 27 | { |
| 28 | LIMITED_METHOD_CONTRACT; |
| 29 | |
| 30 | return &m_stackContents; |
| 31 | } |
| 32 | |
| 33 | EventPipeEvent* GetEvent() const |
| 34 | { |
| 35 | LIMITED_METHOD_CONTRACT; |
| 36 | |
| 37 | return m_pEvent; |
| 38 | } |
| 39 | |
| 40 | const LARGE_INTEGER* const GetTimeStamp() const |
| 41 | { |
| 42 | LIMITED_METHOD_CONTRACT; |
| 43 | |
| 44 | return &m_timeStamp; |
| 45 | } |
| 46 | |
| 47 | unsigned int GetMetadataId() const |
| 48 | { |
| 49 | LIMITED_METHOD_CONTRACT; |
| 50 | |
| 51 | return m_metadataId; |
| 52 | } |
| 53 | |
| 54 | void SetMetadataId(unsigned int metadataId) |
| 55 | { |
| 56 | LIMITED_METHOD_CONTRACT; |
| 57 | |
| 58 | m_metadataId = metadataId; |
| 59 | } |
| 60 | |
| 61 | DWORD GetThreadId() const |
| 62 | { |
| 63 | LIMITED_METHOD_CONTRACT; |
| 64 | |
| 65 | return m_threadID; |
| 66 | } |
| 67 | |
| 68 | const GUID* const GetActivityId() const |
| 69 | { |
| 70 | LIMITED_METHOD_CONTRACT; |
| 71 | |
| 72 | return &m_activityId; |
| 73 | } |
| 74 | |
| 75 | const GUID* const GetRelatedActivityId() const |
| 76 | { |
| 77 | LIMITED_METHOD_CONTRACT; |
| 78 | |
| 79 | return &m_relatedActivityId; |
| 80 | } |
| 81 | |
| 82 | const BYTE* const GetData() const |
| 83 | { |
| 84 | LIMITED_METHOD_CONTRACT; |
| 85 | |
| 86 | return m_pData; |
| 87 | } |
| 88 | |
| 89 | unsigned int GetDataLength() const |
| 90 | { |
| 91 | LIMITED_METHOD_CONTRACT; |
| 92 | |
| 93 | return m_dataLength; |
| 94 | } |
| 95 | |
| 96 | unsigned int GetStackSize() const |
| 97 | { |
| 98 | LIMITED_METHOD_CONTRACT; |
| 99 | |
| 100 | return m_stackContents.GetSize(); |
| 101 | } |
| 102 | |
| 103 | unsigned int GetAlignedTotalSize() const; |
| 104 | |
| 105 | #ifdef _DEBUG |
| 106 | // Serialize this event to the JSON file. |
| 107 | void SerializeToJsonFile(EventPipeJsonFile *pFile); |
| 108 | |
| 109 | bool EnsureConsistency(); |
| 110 | #endif // _DEBUG |
| 111 | |
| 112 | protected: |
| 113 | |
| 114 | #ifdef _DEBUG |
| 115 | unsigned int m_debugEventStart; |
| 116 | #endif // _DEBUG |
| 117 | |
| 118 | EventPipeEvent *m_pEvent; |
| 119 | unsigned int m_metadataId; |
| 120 | DWORD m_threadID; |
| 121 | LARGE_INTEGER m_timeStamp; |
| 122 | GUID m_activityId; |
| 123 | GUID m_relatedActivityId; |
| 124 | |
| 125 | BYTE *m_pData; |
| 126 | unsigned int m_dataLength; |
| 127 | StackContents m_stackContents; |
| 128 | |
| 129 | #ifdef _DEBUG |
| 130 | unsigned int m_debugEventEnd; |
| 131 | #endif // _DEBUG |
| 132 | |
| 133 | private: |
| 134 | |
| 135 | // This is used for metadata events by EventPipeConfiguration because |
| 136 | // the metadata event is created after the first instance of the event |
| 137 | // but must be inserted into the file before the first instance of the event. |
| 138 | void SetTimeStamp(LARGE_INTEGER timeStamp); |
| 139 | }; |
| 140 | |
| 141 | // A specific type of event instance for use by the SampleProfiler. |
| 142 | // This is needed because the SampleProfiler knows how to walk stacks belonging |
| 143 | // to threads other than the current thread. |
| 144 | class SampleProfilerEventInstance : public EventPipeEventInstance |
| 145 | { |
| 146 | |
| 147 | public: |
| 148 | |
| 149 | SampleProfilerEventInstance(EventPipeSession &session, EventPipeEvent &event, Thread *pThread, BYTE *pData, unsigned int length); |
| 150 | }; |
| 151 | |
| 152 | #endif // FEATURE_PERFTRACING |
| 153 | |
| 154 | #endif // __EVENTPIPE_EVENTINSTANCE_H__ |
| 155 | |