summaryrefslogtreecommitdiff
path: root/src/vm/eventpipeblock.h
diff options
context:
space:
mode:
authorAdam Sitnik <adam.sitnik@gmail.com>2018-02-02 23:07:25 +0100
committerGitHub <noreply@github.com>2018-02-02 23:07:25 +0100
commitf6ba335278bb966e8e5f9cd33f51818c6fac44fa (patch)
tree34f19451c962381c3d834fa8db5f334556390756 /src/vm/eventpipeblock.h
parent70bf6a4586b3cad9cf8cc26ca85ec6d552123202 (diff)
downloadcoreclr-f6ba335278bb966e8e5f9cd33f51818c6fac44fa.tar.gz
coreclr-f6ba335278bb966e8e5f9cd33f51818c6fac44fa.tar.bz2
coreclr-f6ba335278bb966e8e5f9cd33f51818c6fac44fa.zip
Event Pipe File V3 (#16107)
* write missing information to the event pipe file (pointer size to make it work fo x86) * define where the events start, not only where they end * include process Id in the event pipe file, bump the version so old consumers get clear error message * write the missing EndObject tag to close the header * include expected CPU sampling rate in the event pipe header file * include keywords in V3 of EventPipe metadata, fixes #11934 * remove forward references * entry object comes after the header and ends after it's data, before the event block objects * introduce event block * fix the GC contracts * generate metadata ids * end the file with null reference tag * getting it work * 4 byte alignment of serialized event data * Revert "include keywords in V3 of EventPipe metadata, fixes #11934" This reverts commit 98ef2f588e271f928fd051e96da526dc1e0f017c. * remove event Id and event version from metadata buffer (it was duplicated with native code) * increase the block size to be the same as buffer size * Write the last event block to the file after disabling the event pipe, right after last events * include the sife in itself * the native part was supposed to not duplicate the event id and version, not manged * ensure 4 byte alignment * build metadata when it's not provided, so payload is never empty (no need to serialize length) * this todo is no longer valid * don't align everything, just the content of event block as suggested by @vancem * improvements after code review * update TraceEvent dependency, make the test verify new feature * InterlockedIncrement(Int32) is not available for non-Windows OSes * code improvements after Skype code review from @jorive
Diffstat (limited to 'src/vm/eventpipeblock.h')
-rw-r--r--src/vm/eventpipeblock.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/vm/eventpipeblock.h b/src/vm/eventpipeblock.h
new file mode 100644
index 0000000000..30bd458f38
--- /dev/null
+++ b/src/vm/eventpipeblock.h
@@ -0,0 +1,92 @@
+// 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_BLOCK_H__
+#define __EVENTPIPE_BLOCK_H__
+
+#ifdef FEATURE_PERFTRACING
+
+#include "eventpipeeventinstance.h"
+#include "fastserializableobject.h"
+#include "fastserializer.h"
+
+class EventPipeBlock : public FastSerializableObject
+{
+ public:
+ EventPipeBlock(unsigned int maxBlockSize);
+
+ ~EventPipeBlock();
+
+ // Write an event to the block.
+ // Returns:
+ // - true: The write succeeded.
+ // - false: The write failed. In this case, the block should be considered full.
+ bool WriteEvent(EventPipeEventInstance &instance);
+
+ void Clear();
+
+ const char* GetTypeName()
+ {
+ LIMITED_METHOD_CONTRACT;
+ return "EventBlock";
+ }
+
+ void FastSerialize(FastSerializer *pSerializer)
+ {
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_NOTRIGGER;
+ MODE_PREEMPTIVE;
+ PRECONDITION(pSerializer != NULL);
+ }
+ CONTRACTL_END;
+
+ if (m_pBlock == NULL)
+ {
+ return;
+ }
+
+ unsigned int eventsSize = (unsigned int)(m_pWritePointer - m_pBlock);
+ pSerializer->WriteBuffer((BYTE*)&eventsSize, sizeof(eventsSize));
+
+ if (eventsSize == 0)
+ {
+ return;
+ }
+
+ size_t currentPosition = pSerializer->GetCurrentPosition();
+ if (currentPosition % ALIGNMENT_SIZE != 0)
+ {
+ BYTE maxPadding[ALIGNMENT_SIZE - 1] = {}; // it's longest possible padding, we are going to use only part of it
+ unsigned int paddingLength = ALIGNMENT_SIZE - (currentPosition % ALIGNMENT_SIZE);
+ pSerializer->WriteBuffer(maxPadding, paddingLength); // we write zeros here, the reader is going to always read from the first aligned address of the serialized content
+
+ _ASSERTE(pSerializer->GetCurrentPosition() % ALIGNMENT_SIZE == 0);
+ }
+
+ pSerializer->WriteBuffer(m_pBlock, eventsSize);
+ }
+
+ private:
+ BYTE *m_pBlock;
+ BYTE *m_pWritePointer;
+ BYTE *m_pEndOfTheBuffer;
+
+ unsigned int GetSize() const
+ {
+ LIMITED_METHOD_CONTRACT;
+
+ if (m_pBlock == NULL)
+ {
+ return 0;
+ }
+
+ return (unsigned int)(m_pEndOfTheBuffer - m_pBlock);
+ }
+};
+
+#endif // FEATURE_PERFTRACING
+
+#endif // __EVENTPIPE_BLOCK_H__