From 2551faa0b5f0712d7790b4090488b2cbe9366044 Mon Sep 17 00:00:00 2001 From: verdie-g Date: Sat, 11 May 2024 13:51:17 -0400 Subject: [PATCH] Add thread sample event --- EventPipe/KnownEvent.cs | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/EventPipe/KnownEvent.cs b/EventPipe/KnownEvent.cs index 5d71e9d..f9ca5b2 100644 --- a/EventPipe/KnownEvent.cs +++ b/EventPipe/KnownEvent.cs @@ -15,6 +15,7 @@ internal class KnownEvent { public const string RuntimeProvider = "Microsoft-Windows-DotNETRuntime"; public const string RundownProvider = "Microsoft-Windows-DotNETRuntimeRundown"; + public const string SampleProfilerProvider = "Microsoft-DotNETCore-SampleProfiler"; public const string TplProvider = "System.Threading.Tasks.TplEventSource"; public static readonly FrozenDictionary All = new Dictionary @@ -68,6 +69,7 @@ internal class KnownEvent [new Key(RundownProvider, 156, 1)] = new("AssemblyDCEnd", null, AssemblyLoadUnloadRundownV1Payload.FieldDefinitions, AssemblyLoadUnloadRundownV1Payload.Parse), [new Key(RundownProvider, 158, 1)] = new("AppDomainDCEnd", null, AppDomainLoadUnloadRundownV1Payload.FieldDefinitions, AppDomainLoadUnloadRundownV1Payload.Parse), [new Key(RundownProvider, 187, 0)] = new("RuntimeInformationDCStart", null, RuntimeInformationRundownPayload.FieldDefinitions, RuntimeInformationRundownPayload.Parse), + [new Key(SampleProfilerProvider, 0, 0)] = new("ThreadSample", null, ThreadSamplePayload.FieldDefinitions, ThreadSamplePayload.Parse), [new Key(TplProvider, 7, 1)] = new("TaskScheduled", EventOpcode.Send, TaskScheduledPayload.FieldDefinitions, TaskScheduledPayload.Parse), [new Key(TplProvider, 8, 0)] = new("TaskStarted", null, TaskStartedPayload.FieldDefinitions, TaskStartedPayload.Parse), [new Key(TplProvider, 9, 1)] = new("TaskCompleted", null, TaskCompletedPayload.FieldDefinitions, TaskCompletedPayload.Parse), @@ -4740,6 +4742,70 @@ private IEnumerable> GetKeyValues() } } + private class ThreadSamplePayload : IReadOnlyDictionary + { + public static EventFieldDefinition[] FieldDefinitions { get; } = + [ + new("Type", TypeCode.Int32), + ]; + + public static IReadOnlyDictionary Parse(ref FastSerializerSequenceReader reader) + { + return new ThreadSamplePayload( + reader.ReadInt32()); + } + + private readonly int _type; + + private ThreadSamplePayload(int type) + { + _type = type; + } + + public int Count => FieldDefinitions.Length; + + public object this[string key] => TryGetValue(key, out object? val) + ? val + : throw new KeyNotFoundException($"The given key '{key}' was not present in the dictionary."); + + public IEnumerable Keys => FieldDefinitions.Select(d => d.Name); + + public bool ContainsKey(string key) + { + return TryGetValue(key, out _); + } + + public bool TryGetValue(string key, [MaybeNullWhen(false)] out object value) + { + switch (key) + { + case "Type": + value = _type; + return true; + default: + value = null; + return false; + } + } + + public IEnumerable Values => GetKeyValues().Select(kvp => kvp.Value); + + public IEnumerator> GetEnumerator() + { + return GetKeyValues().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + private IEnumerable> GetKeyValues() + { + yield return new KeyValuePair("Type", _type); + } + } + private class TaskScheduledPayload : IReadOnlyDictionary { public static EventFieldDefinition[] FieldDefinitions { get; } =