summaryrefslogtreecommitdiff
path: root/src/vm/eventpipeeventinstance.h
blob: a7fd4975f8f661f8c91e8a340ecc8aa21dbbf3e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// 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.

#ifndef __EVENTPIPE_EVENTINSTANCE_H__
#define __EVENTPIPE_EVENTINSTANCE_H__

#ifdef FEATURE_PERFTRACING

#include "eventpipe.h"
#include "eventpipeevent.h"
#include "eventpipesession.h"
#include "eventpipeblock.h"
#include "eventpipethread.h"
#include "fastserializableobject.h"
#include "fastserializer.h"

class EventPipeJsonFile;

class EventPipeEventInstance
{
    // Declare friends.
    friend EventPipeConfiguration;

public:

    EventPipeEventInstance(EventPipeEvent &event, 
                           unsigned int procNumber,
                           ULONGLONG threadID,
                           BYTE *pData,
                           unsigned int length,
                           LPCGUID pActivityId,
                           LPCGUID pRelatedActivityId);

    void EnsureStack(const EventPipeSession &session);

    StackContents* GetStack()
    {
        LIMITED_METHOD_CONTRACT;

        return &m_stackContents;
    }

    EventPipeEvent* GetEvent() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_pEvent;
    }

    const LARGE_INTEGER* GetTimeStamp() const
    {
        LIMITED_METHOD_CONTRACT;

        return &m_timeStamp;
    }

    unsigned int GetMetadataId() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_metadataId;
    }

    void SetMetadataId(unsigned int metadataId)
    {
        LIMITED_METHOD_CONTRACT;

        m_metadataId = metadataId;
    }

    unsigned int GetProcNumber() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_procNumber;
    }

    DWORD GetThreadId32() const
    {
        LIMITED_METHOD_CONTRACT;

        return (DWORD)m_threadId;
    }

    ULONGLONG GetThreadId64() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_threadId;
    }

    const GUID* GetActivityId() const
    {
        LIMITED_METHOD_CONTRACT;

        return &m_activityId;
    }

    const GUID* GetRelatedActivityId() const
    {
        LIMITED_METHOD_CONTRACT;

        return &m_relatedActivityId;
    }

    const BYTE* GetData() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_pData;
    }

    unsigned int GetDataLength() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_dataLength;
    }

    unsigned int GetStackSize() const
    {
        LIMITED_METHOD_CONTRACT;

        return m_stackContents.GetSize();
    }

    unsigned int GetAlignedTotalSize(EventPipeSerializationFormat format) const;

#ifdef _DEBUG
    // Serialize this event to the JSON file.
    void SerializeToJsonFile(EventPipeJsonFile *pFile);

    bool EnsureConsistency();
#endif // _DEBUG

protected:

#ifdef _DEBUG
    unsigned int m_debugEventStart;
#endif // _DEBUG

    EventPipeEvent *m_pEvent;
    unsigned int m_metadataId;
    unsigned int m_procNumber;
    ULONGLONG m_threadId;
    LARGE_INTEGER m_timeStamp;
    GUID m_activityId;
    GUID m_relatedActivityId;

    BYTE *m_pData;
    unsigned int m_dataLength;
    StackContents m_stackContents;

#ifdef _DEBUG
    unsigned int m_debugEventEnd;
#endif // _DEBUG

private:

    // This is used for metadata events by EventPipeConfiguration because
    // the metadata event is created after the first instance of the event
    // but must be inserted into the file before the first instance of the event.
    void SetTimeStamp(LARGE_INTEGER timeStamp);
};

typedef MapSHash<EventPipeThreadSessionState *, unsigned int> ThreadSequenceNumberMap;

// A point in time marker that is used as a boundary when emitting events.
// The events in a Nettrace file are not emitted in a fully sorted order
// but we do guarantee that all events before a sequence point are emitted
// prior to any events after the sequence point
struct EventPipeSequencePoint
{
    // Entry in EventPipeBufferManager m_sequencePointList 
    SLink m_Link;

    // The timestamp the sequence point was captured
    LARGE_INTEGER TimeStamp;
    ThreadSequenceNumberMap ThreadSequenceNumbers;

    EventPipeSequencePoint();
    ~EventPipeSequencePoint();
};

#endif // FEATURE_PERFTRACING

#endif // __EVENTPIPE_EVENTINSTANCE_H__