| 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 |  | 
|---|
| 6 | #ifndef __EVENTPIPE_FILE_H__ | 
|---|
| 7 | #define __EVENTPIPE_FILE_H__ | 
|---|
| 8 |  | 
|---|
| 9 | #ifdef FEATURE_PERFTRACING | 
|---|
| 10 |  | 
|---|
| 11 | #include "eventpipe.h" | 
|---|
| 12 | #include "eventpipeblock.h" | 
|---|
| 13 | #include "eventpipeeventinstance.h" | 
|---|
| 14 | #include "fastserializableobject.h" | 
|---|
| 15 | #include "fastserializer.h" | 
|---|
| 16 |  | 
|---|
| 17 | class EventPipeFile : public FastSerializableObject | 
|---|
| 18 | { | 
|---|
| 19 | public: | 
|---|
| 20 |  | 
|---|
| 21 | EventPipeFile(SString &outputFilePath); | 
|---|
| 22 | ~EventPipeFile(); | 
|---|
| 23 |  | 
|---|
| 24 | void WriteEvent(EventPipeEventInstance &instance); | 
|---|
| 25 |  | 
|---|
| 26 | void WriteEnd(); | 
|---|
| 27 |  | 
|---|
| 28 | const char* GetTypeName() | 
|---|
| 29 | { | 
|---|
| 30 | LIMITED_METHOD_CONTRACT; | 
|---|
| 31 | return "Trace"; | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | void FastSerialize(FastSerializer *pSerializer) | 
|---|
| 35 | { | 
|---|
| 36 | CONTRACTL | 
|---|
| 37 | { | 
|---|
| 38 | NOTHROW; | 
|---|
| 39 | GC_NOTRIGGER; | 
|---|
| 40 | MODE_PREEMPTIVE; | 
|---|
| 41 | PRECONDITION(pSerializer != NULL); | 
|---|
| 42 | } | 
|---|
| 43 | CONTRACTL_END; | 
|---|
| 44 |  | 
|---|
| 45 | pSerializer->WriteBuffer((BYTE*)&m_fileOpenSystemTime, sizeof(m_fileOpenSystemTime)); | 
|---|
| 46 | pSerializer->WriteBuffer((BYTE*)&m_fileOpenTimeStamp, sizeof(m_fileOpenTimeStamp)); | 
|---|
| 47 | pSerializer->WriteBuffer((BYTE*)&m_timeStampFrequency, sizeof(m_timeStampFrequency)); | 
|---|
| 48 |  | 
|---|
| 49 | // the beginning of V3 | 
|---|
| 50 | pSerializer->WriteBuffer((BYTE*)&m_pointerSize, sizeof(m_pointerSize)); | 
|---|
| 51 | pSerializer->WriteBuffer((BYTE*)&m_currentProcessId, sizeof(m_currentProcessId)); | 
|---|
| 52 | pSerializer->WriteBuffer((BYTE*)&m_numberOfProcessors, sizeof(m_numberOfProcessors)); | 
|---|
| 53 | pSerializer->WriteBuffer((BYTE*)&m_samplingRateInNs, sizeof(m_samplingRateInNs)); | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | private: | 
|---|
| 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__ | 
|---|
| 101 |  | 
|---|