diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 881e10841bd387..4b3d7099f1b5d5 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -22342,6 +22342,27 @@ size_t gc_heap::exponential_smoothing (int gen, size_t collection_count, size_t //internal part of gc used by the serial and concurrent version void gc_heap::gc1() { +#ifdef FEATURE_EVENT_TRACE + EventArray arr1; + arr1.Count = 10; + arr1.Data = new (nothrow) uint8_t[10]; + for (uint8_t i = 0; i < 10; i++) + { + arr1.Data[i] = i * i + i + 1; + } + + EventArray arr2; + arr2.Count = 6; + arr2.Data = new (nothrow) uint16_t[6]; + for (uint16_t i = 0; i < 6; i++) + { + arr2.Data[i] = i * (i + 1); + } + + GCEventFireTestArray_V1 (arr1, arr2); + delete[] arr1.Data; + delete[] arr2.Data; +#endif //FEATURE_EVENT_TRACE #ifdef BACKGROUND_GC assert (settings.concurrent == (uint32_t)(bgc_thread_id.IsCurrentThread())); #endif //BACKGROUND_GC diff --git a/src/coreclr/gc/gcevent_serializers.h b/src/coreclr/gc/gcevent_serializers.h index 707df8ec8d6f9f..af280c40a8f778 100644 --- a/src/coreclr/gc/gcevent_serializers.h +++ b/src/coreclr/gc/gcevent_serializers.h @@ -48,15 +48,22 @@ #define ByteSwap64 __builtin_bswap64 #endif // MSC_VER -namespace gc_event +template +class EventArray { +public: + uint8_t Count; + T* Data; +}; +namespace gc_event +{ /* - * `EventSerializatonTraits` is a trait implemented by types that - * can be serialized to the payload of a dynamic event. + * `PrimitiveEventSerializatonTraits` is a trait implemented by types that + * can be serialized to the payload of a dynamic event with a fixed size. */ template -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { /* * Serializes the value `value` to the buffer `buffer`, incrementing @@ -66,22 +73,21 @@ struct EventSerializationTraits * large enough to accommodate the serialized form of T. */ static void Serialize(const T& value, uint8_t** buffer) = delete; - /* - * Returns the size of the value `value` if it were to be serialized. + * Returns the size required for serializing this type. */ - static size_t SerializedSize(const T& value) = delete; + static size_t SerializedSize() = delete; }; /* - * EventSerializationTraits implementation for uint16_t. Other integral types + * PrimitiveEventSerializationTraits implementation for uint8_t. Other integral types * can follow this pattern. * * The convention here is that integral types are always serialized as * little-endian. */ template<> -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { static void Serialize(const uint8_t& value, uint8_t** buffer) { @@ -89,14 +95,14 @@ struct EventSerializationTraits *buffer += sizeof(uint8_t); } - static size_t SerializedSize(const uint8_t& value) + static size_t SerializedSize() { return sizeof(uint8_t); } }; template<> -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { static void Serialize(const uint16_t& value, uint8_t** buffer) { @@ -109,14 +115,14 @@ struct EventSerializationTraits *buffer += sizeof(uint16_t); } - static size_t SerializedSize(const uint16_t& value) + static size_t SerializedSize() { return sizeof(uint16_t); } }; template<> -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { static void Serialize(const uint32_t& value, uint8_t** buffer) { @@ -129,14 +135,14 @@ struct EventSerializationTraits *buffer += sizeof(uint32_t); } - static size_t SerializedSize(const uint32_t& value) + static size_t SerializedSize() { return sizeof(uint32_t); } }; template<> -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { static void Serialize(const uint64_t& value, uint8_t** buffer) { @@ -149,14 +155,14 @@ struct EventSerializationTraits *buffer += sizeof(uint64_t); } - static size_t SerializedSize(const uint64_t& value) + static size_t SerializedSize() { return sizeof(uint64_t); } }; template<> -struct EventSerializationTraits +struct PrimitiveEventSerializationTraits { static void Serialize(const float& value, uint8_t** buffer) { @@ -164,12 +170,61 @@ struct EventSerializationTraits *buffer += sizeof(float); } - static size_t SerializedSize(const float& value) + static size_t SerializedSize() { return sizeof(float); } }; +/* + * `EventSerializatonTraits` is a trait implemented by types that + * can be serialized to the payload of a dynamic event. + */ +template +struct EventSerializationTraits +{ + /* + * Serializes the value `value` to the buffer `buffer`, incrementing + * the buffer double-pointer to point to the next byte to be written. + * + * It is the responsibility of the caller to ensure that the buffer is + * large enough to accommodate the serialized form of T. + */ + static void Serialize(const T& value, uint8_t** buffer) + { + PrimitiveEventSerializationTraits::Serialize(value, buffer); + } + + /* + * Returns the size of the value `value` if it were to be serialized. + */ + static size_t SerializedSize(const T& value) + { + return PrimitiveEventSerializationTraits::SerializedSize(); + } +}; + +template +struct EventSerializationTraits> +{ + static void Serialize(const EventArray& value, uint8_t** pBuffer) + { + uint8_t* buffer = *pBuffer; + buffer[0] = value.Count; + buffer += 1; + for (uint8_t i = 0; i < value.Count; i++) + { + PrimitiveEventSerializationTraits::Serialize(value.Data[i], &buffer); + } + *pBuffer = buffer; + } + + static size_t SerializedSize(const EventArray& value) + { + return sizeof(uint8_t) + PrimitiveEventSerializationTraits::SerializedSize() * value.Count; + } +}; + /* * Helper routines for serializing lists of arguments. */ diff --git a/src/coreclr/gc/gcevents.h b/src/coreclr/gc/gcevents.h index d09eaa3c692dad..8f058a8e5373c5 100644 --- a/src/coreclr/gc/gcevents.h +++ b/src/coreclr/gc/gcevents.h @@ -52,6 +52,7 @@ DYNAMIC_EVENT(CommittedUsage, GCEventLevel_Information, GCEventKeyword_GC, 1) DYNAMIC_EVENT(SizeAdaptationTuning, GCEventLevel_Information, GCEventKeyword_GC, 1) DYNAMIC_EVENT(SizeAdaptationFullGCTuning, GCEventLevel_Information, GCEventKeyword_GC, 1) DYNAMIC_EVENT(SizeAdaptationSample, GCEventLevel_Information, GCEventKeyword_GC, 1) +DYNAMIC_EVENT(TestArray, GCEventLevel_Information, GCEventKeyword_GC, 1) #undef KNOWN_EVENT #undef DYNAMIC_EVENT