<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />

Instrument<T>

public abstract class Instrument<T> : Instrument where T : struct
The base class for all non-observable instruments.
using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Diagnostics.Metrics { public abstract class Instrument<T> : Instrument where T : struct { [ThreadStatic] private static KeyValuePair<string, object>[] ts_tags; private const int MaxTagsCount = 8; [System.Runtime.CompilerServices.NullableContext(1)] protected Instrument(Meter meter, string name, [System.Runtime.CompilerServices.Nullable(2)] string unit, [System.Runtime.CompilerServices.Nullable(2)] string description) : this(meter, name, unit, description, (IEnumerable<KeyValuePair<string, object>>)null) { } [System.Runtime.CompilerServices.NullableContext(1)] protected Instrument(Meter meter, string name, [System.Runtime.CompilerServices.Nullable(2)] string unit, [System.Runtime.CompilerServices.Nullable(2)] string description, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1, 2 })] IEnumerable<KeyValuePair<string, object>> tags) : base(meter, name, unit, description, tags) { Instrument.ValidateTypeParameter<T>(); } protected void RecordMeasurement(T measurement) { RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(Instrument.EmptyTags)); } protected void RecordMeasurement(T measurement, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1, 2 })] ReadOnlySpan<KeyValuePair<string, object>> tags) { for (DiagNode<ListenerSubscription> diagNode = _subscriptions.First; diagNode != null; diagNode = diagNode.Next) { diagNode.Value.Listener.NotifyMeasurement<T>((Instrument)this, measurement, tags, diagNode.Value.State); } } protected void RecordMeasurement(T measurement, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag) { KeyValuePair<string, object>[] array = ts_tags ?? new KeyValuePair<string, object>[8]; ts_tags = null; array[0] = tag; RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(array, 0, 1)); ts_tags = array; } protected void RecordMeasurement(T measurement, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2) { KeyValuePair<string, object>[] array = ts_tags ?? new KeyValuePair<string, object>[8]; ts_tags = null; array[0] = tag1; array[1] = tag2; RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(array, 0, 2)); ts_tags = array; } protected void RecordMeasurement(T measurement, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag1, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag2, [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 2 })] KeyValuePair<string, object> tag3) { KeyValuePair<string, object>[] array = ts_tags ?? new KeyValuePair<string, object>[8]; ts_tags = null; array[0] = tag1; array[1] = tag2; array[2] = tag3; RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(array, 0, 3)); ts_tags = array; } protected void RecordMeasurement(T measurement, [In] [System.Runtime.CompilerServices.IsReadOnly] ref TagList tagList) { KeyValuePair<string, object>[] tags = tagList.Tags; if (tags != null) RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(tags, 0, tagList.Count)); else { tags = (ts_tags ?? new KeyValuePair<string, object>[8]); switch (tagList.Count) { default: return; case 0: return; case 8: tags[7] = tagList.Tag8; goto case 7; case 7: tags[6] = tagList.Tag7; goto case 6; case 6: tags[5] = tagList.Tag6; goto case 5; case 5: tags[4] = tagList.Tag5; goto case 4; case 4: tags[3] = tagList.Tag4; goto case 3; case 3: tags[2] = tagList.Tag3; goto case 2; case 2: tags[1] = tagList.Tag2; break; case 1: break; } tags[0] = tagList.Tag1; ts_tags = null; RecordMeasurement(measurement, MemoryExtensions.AsSpan<KeyValuePair<string, object>>(tags, 0, tagList.Count)); ts_tags = tags; } } } }