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.
5 #ifndef __EVENTPIPE_FILE_H__
6 #define __EVENTPIPE_FILE_H__
8 #ifdef FEATURE_PERFTRACING
10 #include "eventpipe.h"
11 #include "eventpipeblock.h"
12 #include "eventpipeeventinstance.h"
13 #include "fastserializableobject.h"
17 class EventPipeFile final : public FastSerializableObject
20 EventPipeFile(StreamWriter *pStreamWriter);
23 void WriteEvent(EventPipeEventInstance &instance);
26 const char *GetTypeName() override
28 LIMITED_METHOD_CONTRACT;
32 void FastSerialize(FastSerializer *pSerializer) override
39 PRECONDITION(pSerializer != NULL);
43 pSerializer->WriteBuffer((BYTE *)&m_fileOpenSystemTime, sizeof(m_fileOpenSystemTime));
44 pSerializer->WriteBuffer((BYTE *)&m_fileOpenTimeStamp, sizeof(m_fileOpenTimeStamp));
45 pSerializer->WriteBuffer((BYTE *)&m_timeStampFrequency, sizeof(m_timeStampFrequency));
47 // the beginning of V3
48 pSerializer->WriteBuffer((BYTE *)&m_pointerSize, sizeof(m_pointerSize));
49 pSerializer->WriteBuffer((BYTE *)&m_currentProcessId, sizeof(m_currentProcessId));
50 pSerializer->WriteBuffer((BYTE *)&m_numberOfProcessors, sizeof(m_numberOfProcessors));
51 pSerializer->WriteBuffer((BYTE *)&m_samplingRateInNs, sizeof(m_samplingRateInNs));
57 unsigned int GenerateMetadataId();
59 unsigned int GetMetadataId(EventPipeEvent &event);
61 void SaveMetadataId(EventPipeEvent &event, unsigned int metadataId);
63 void WriteToBlock(EventPipeEventInstance &instance, unsigned int metadataId);
65 // The object responsible for serialization.
66 FastSerializer *m_pSerializer;
68 EventPipeBlock *m_pBlock;
70 // The system time when the file was opened.
71 SYSTEMTIME m_fileOpenSystemTime;
73 // The timestamp when the file was opened. Used for calculating file-relative timestamps.
74 LARGE_INTEGER m_fileOpenTimeStamp;
76 // The frequency of the timestamps used for this file.
77 LARGE_INTEGER m_timeStampFrequency;
79 unsigned int m_pointerSize;
81 unsigned int m_currentProcessId;
83 unsigned int m_numberOfProcessors;
85 unsigned int m_samplingRateInNs;
87 // The serialization which is responsible for making sure only a single event
88 // or block of events gets written to the file at once.
89 SpinLock m_serializationLock;
91 // Hashtable of metadata labels.
92 MapSHashWithRemove<EventPipeEvent *, unsigned int> *m_pMetadataIds;
94 Volatile<LONG> m_metadataIdCounter;
97 #endif // FEATURE_PERFTRACING
99 #endif // __EVENTPIPE_FILE_H__