Skip to content

Commit aa00387

Browse files
committed
Support emitting array in dynamic event
1 parent eda5f37 commit aa00387

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22279,6 +22279,27 @@ size_t gc_heap::exponential_smoothing (int gen, size_t collection_count, size_t
2227922279
//internal part of gc used by the serial and concurrent version
2228022280
void gc_heap::gc1()
2228122281
{
22282+
#ifdef FEATURE_EVENT_TRACE
22283+
EventArray<uint8_t> arr1;
22284+
arr1.Count = 10;
22285+
arr1.Data = new (nothrow) uint8_t[10];
22286+
for (uint8_t i = 0; i < 10; i++)
22287+
{
22288+
arr1.Data[i] = i * i + i + 1;
22289+
}
22290+
22291+
EventArray<uint16_t> arr2;
22292+
arr2.Count = 6;
22293+
arr2.Data = new (nothrow) uint16_t[6];
22294+
for (uint16_t i = 0; i < 6; i++)
22295+
{
22296+
arr2.Data[i] = i * (i + 1);
22297+
}
22298+
22299+
GCEventFireTestArray_V1 (arr1, arr2);
22300+
delete[] arr1.Data;
22301+
delete[] arr2.Data;
22302+
#endif //FEATURE_EVENT_TRACE
2228222303
#ifdef BACKGROUND_GC
2228322304
assert (settings.concurrent == (uint32_t)(bgc_thread_id.IsCurrentThread()));
2228422305
#endif //BACKGROUND_GC

src/coreclr/gc/gcevent_serializers.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,16 @@
4848
#define ByteSwap64 __builtin_bswap64
4949
#endif // MSC_VER
5050

51-
namespace gc_event
51+
template<class T>
52+
class EventArray
5253
{
54+
public:
55+
uint8_t Count;
56+
T* Data;
57+
};
5358

59+
namespace gc_event
60+
{
5461
/*
5562
* `EventSerializatonTraits` is a trait implemented by types that
5663
* can be serialized to the payload of a dynamic event.
@@ -170,6 +177,45 @@ struct EventSerializationTraits<float>
170177
}
171178
};
172179

180+
template<class T>
181+
struct EventSerializationTraits<EventArray<T>>
182+
{
183+
static void Serialize(const EventArray<T>& value, uint8_t** pBuffer)
184+
{
185+
uint8_t* buffer = *pBuffer;
186+
buffer[0] = value.Count;
187+
buffer += 1;
188+
for (uint8_t i = 0; i < value.Count; i++)
189+
{
190+
EventSerializationTraits<T>::Serialize(value.Data[i], &buffer);
191+
}
192+
*pBuffer = buffer;
193+
}
194+
195+
static size_t SerializedSize(const EventArray<T>& value)
196+
{
197+
if (value.Count == 0)
198+
{
199+
return sizeof(uint8_t);
200+
}
201+
else
202+
{
203+
size_t elementSize = EventSerializationTraits<T>::SerializedSize(value.Data[0]);
204+
#ifdef DEBUG
205+
//
206+
// To support fast deserialization, we explicitly do not support arrays with
207+
// unequal element size.
208+
//
209+
for (int i = 1; i < value.Count; i++)
210+
{
211+
assert (elementSize == EventSerializationTraits<T>::SerializedSize(value.Data[i]));
212+
}
213+
#endif //DEBUG
214+
return sizeof(uint8_t) + elementSize * value.Count;
215+
}
216+
}
217+
};
218+
173219
/*
174220
* Helper routines for serializing lists of arguments.
175221
*/

src/coreclr/gc/gcevents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ DYNAMIC_EVENT(CommittedUsage, GCEventLevel_Information, GCEventKeyword_GC, 1)
5252
DYNAMIC_EVENT(SizeAdaptationTuning, GCEventLevel_Information, GCEventKeyword_GC, 1)
5353
DYNAMIC_EVENT(SizeAdaptationFullGCTuning, GCEventLevel_Information, GCEventKeyword_GC, 1)
5454
DYNAMIC_EVENT(SizeAdaptationSample, GCEventLevel_Information, GCEventKeyword_GC, 1)
55+
DYNAMIC_EVENT(TestArray, GCEventLevel_Information, GCEventKeyword_GC, 1)
5556

5657
#undef KNOWN_EVENT
5758
#undef DYNAMIC_EVENT

0 commit comments

Comments
 (0)