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);
25 bool HasErrors() const;
27 const char *GetTypeName() override
29 LIMITED_METHOD_CONTRACT;
33 void FastSerialize(FastSerializer *pSerializer) override
40 PRECONDITION(pSerializer != NULL);
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));
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));
58 unsigned int GenerateMetadataId();
60 unsigned int GetMetadataId(EventPipeEvent &event);
62 void SaveMetadataId(EventPipeEvent &event, unsigned int metadataId);
64 void WriteToBlock(EventPipeEventInstance &instance, unsigned int metadataId);
66 // The object responsible for serialization.
67 FastSerializer *m_pSerializer;
69 EventPipeBlock *m_pBlock;
71 // The system time when the file was opened.
72 SYSTEMTIME m_fileOpenSystemTime;
74 // The timestamp when the file was opened. Used for calculating file-relative timestamps.
75 LARGE_INTEGER m_fileOpenTimeStamp;
77 // The frequency of the timestamps used for this file.
78 LARGE_INTEGER m_timeStampFrequency;
80 unsigned int m_pointerSize;
82 unsigned int m_currentProcessId;
84 unsigned int m_numberOfProcessors;
86 unsigned int m_samplingRateInNs;
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;
92 // Hashtable of metadata labels.
93 MapSHashWithRemove<EventPipeEvent *, unsigned int> *m_pMetadataIds;
95 Volatile<LONG> m_metadataIdCounter;
98 #endif // FEATURE_PERFTRACING
100 #endif // __EVENTPIPE_FILE_H__