If IPC connections fails, then remove active session. (#24082)
[platform/upstream/coreclr.git] / src / vm / eventpipefile.h
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_FILE_H__
6 #define __EVENTPIPE_FILE_H__
7
8 #ifdef FEATURE_PERFTRACING
9
10 #include "eventpipe.h"
11 #include "eventpipeblock.h"
12 #include "eventpipeeventinstance.h"
13 #include "fastserializableobject.h"
14
15 class FastSerializer;
16
17 class EventPipeFile final : public FastSerializableObject
18 {
19 public:
20     EventPipeFile(StreamWriter *pStreamWriter);
21     ~EventPipeFile();
22
23     void WriteEvent(EventPipeEventInstance &instance);
24     void Flush();
25     bool HasErrors() const;
26
27     const char *GetTypeName() override
28     {
29         LIMITED_METHOD_CONTRACT;
30         return "Trace";
31     }
32
33     void FastSerialize(FastSerializer *pSerializer) override
34     {
35         CONTRACTL
36         {
37             NOTHROW;
38             GC_NOTRIGGER;
39             MODE_PREEMPTIVE;
40             PRECONDITION(pSerializer != NULL);
41         }
42         CONTRACTL_END;
43
44         pSerializer->WriteBuffer((BYTE *)&m_fileOpenSystemTime, sizeof(m_fileOpenSystemTime));
45         pSerializer->WriteBuffer((BYTE *)&m_fileOpenTimeStamp, sizeof(m_fileOpenTimeStamp));
46         pSerializer->WriteBuffer((BYTE *)&m_timeStampFrequency, sizeof(m_timeStampFrequency));
47
48         // the beginning of V3
49         pSerializer->WriteBuffer((BYTE *)&m_pointerSize, sizeof(m_pointerSize));
50         pSerializer->WriteBuffer((BYTE *)&m_currentProcessId, sizeof(m_currentProcessId));
51         pSerializer->WriteBuffer((BYTE *)&m_numberOfProcessors, sizeof(m_numberOfProcessors));
52         pSerializer->WriteBuffer((BYTE *)&m_samplingRateInNs, sizeof(m_samplingRateInNs));
53     }
54
55 private:
56     void WriteEnd();
57
58     unsigned int GenerateMetadataId();
59
60     unsigned int GetMetadataId(EventPipeEvent &event);
61
62     void SaveMetadataId(EventPipeEvent &event, unsigned int metadataId);
63
64     void WriteToBlock(EventPipeEventInstance &instance, unsigned int metadataId);
65
66     // The object responsible for serialization.
67     FastSerializer *m_pSerializer;
68
69     EventPipeBlock *m_pBlock;
70
71     // The system time when the file was opened.
72     SYSTEMTIME m_fileOpenSystemTime;
73
74     // The timestamp when the file was opened.  Used for calculating file-relative timestamps.
75     LARGE_INTEGER m_fileOpenTimeStamp;
76
77     // The frequency of the timestamps used for this file.
78     LARGE_INTEGER m_timeStampFrequency;
79
80     unsigned int m_pointerSize;
81
82     unsigned int m_currentProcessId;
83
84     unsigned int m_numberOfProcessors;
85
86     unsigned int m_samplingRateInNs;
87
88     // The serialization which is responsible for making sure only a single event
89     // or block of events gets written to the file at once.
90     SpinLock m_serializationLock;
91
92     // Hashtable of metadata labels.
93     MapSHashWithRemove<EventPipeEvent *, unsigned int> *m_pMetadataIds;
94
95     Volatile<LONG> m_metadataIdCounter;
96 };
97
98 #endif // FEATURE_PERFTRACING
99
100 #endif // __EVENTPIPE_FILE_H__