Class BaseTelemetryProvider
- Namespace
- DotCompute.Core.Telemetry
- Assembly
- DotCompute.Core.dll
Unified base telemetry provider that consolidates common telemetry patterns across all backend implementations (Metal, CUDA, OpenCL, CPU, LINQ). Eliminates over 2,500 lines of duplicate telemetry code.
public abstract class BaseTelemetryProvider : ITelemetryProvider, IDisposable
- Inheritance
-
BaseTelemetryProvider
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
BaseTelemetryProvider(ILogger, TelemetryConfiguration, string, string)
protected BaseTelemetryProvider(ILogger logger, TelemetryConfiguration configuration, string serviceName, string serviceVersion)
Parameters
loggerILoggerconfigurationTelemetryConfigurationserviceNamestringserviceVersionstring
Fields
ActivitySource
protected readonly ActivitySource ActivitySource
Field Value
Configuration
protected readonly TelemetryConfiguration Configuration
Field Value
Logger
protected readonly ILogger Logger
Field Value
Meter
protected readonly Meter Meter
Field Value
Methods
AddBackendSpecificActivityContext(Activity)
Adds backend-specific context to activities.
protected virtual void AddBackendSpecificActivityContext(Activity activity)
Parameters
activityActivity
CalculateOverheadPercentage()
Calculates telemetry overhead percentage.
protected virtual double CalculateOverheadPercentage()
Returns
CreateTagList(IDictionary<string, object?>)
Creates a TagList from a dictionary for metrics.
protected static TagList CreateTagList(IDictionary<string, object?> tags)
Parameters
tagsIDictionary<string, object>
Returns
Dispose()
Disposes the telemetry provider and releases all resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
ExtractKernelCategory(string)
Extracts kernel category from name for classification.
protected static string ExtractKernelCategory(string kernelName)
Parameters
kernelNamestring
Returns
GetAcceleratorCategory(string)
Gets accelerator category from type.
protected static string GetAcceleratorCategory(string acceleratorType)
Parameters
acceleratorTypestring
Returns
GetBackendType()
Gets the backend type identifier (e.g., "CUDA", "Metal", "OpenCL", "CPU").
protected abstract string GetBackendType()
Returns
GetGCType(int)
Gets garbage collection type from generation.
protected static string GetGCType(int generation)
Parameters
generationint
Returns
GetMeter(string, string?)
Gets a specific meter for advanced scenarios.
public virtual Meter GetMeter(string name, string? version = null)
Parameters
Returns
GetPerformanceMetrics()
Gets comprehensive telemetry performance metrics.
public virtual TelemetryPerformanceMetrics GetPerformanceMetrics()
Returns
GetTransferType(string)
Gets transfer type from direction.
protected static string GetTransferType(string direction)
Parameters
directionstring
Returns
HandleTelemetryError(Exception, string, string)
Handles telemetry errors consistently across all operations.
protected virtual void HandleTelemetryError(Exception ex, string operation, string context)
Parameters
IncrementCounter(string, long, IDictionary<string, object?>?)
Increments a counter with optimized performance and error handling.
public virtual void IncrementCounter(string name, long increment = 1, IDictionary<string, object?>? tags = null)
Parameters
namestringincrementlongtagsIDictionary<string, object>
InitializeStandardMetrics()
Initializes standard metrics used across all backends.
protected void InitializeStandardMetrics()
OnAcceleratorUtilizationRecorded(string, double, long, Dictionary<string, object?>)
Called when accelerator utilization is recorded - override for backend-specific tracking.
protected virtual void OnAcceleratorUtilizationRecorded(string acceleratorType, double utilization, long memoryUsed, Dictionary<string, object?> tags)
Parameters
OnGarbageCollectionRecorded(int, TimeSpan, long, long, Dictionary<string, object?>)
Called when garbage collection is recorded - override for backend-specific tracking.
protected virtual void OnGarbageCollectionRecorded(int generation, TimeSpan duration, long memoryBefore, long memoryAfter, Dictionary<string, object?> tags)
Parameters
OnKernelExecuted(string, TimeSpan, long, Dictionary<string, object?>)
Called when kernel execution is recorded - override for backend-specific tracking.
protected virtual void OnKernelExecuted(string kernelName, TimeSpan duration, long operationCount, Dictionary<string, object?> tags)
Parameters
OnMemoryAllocated(long, string?, Dictionary<string, object?>)
Called when memory is allocated - override for backend-specific tracking.
protected virtual void OnMemoryAllocated(long bytes, string? allocationType, Dictionary<string, object?> tags)
Parameters
byteslongallocationTypestringtagsDictionary<string, object>
OnMemoryTransferRecorded(string, long, TimeSpan, Dictionary<string, object?>)
Called when memory transfer is recorded - override for backend-specific tracking.
protected virtual void OnMemoryTransferRecorded(string direction, long bytes, TimeSpan duration, Dictionary<string, object?> tags)
Parameters
ProcessEventSync(TelemetryEvent)
Processes an event synchronously.
protected virtual void ProcessEventSync(TelemetryEvent telemetryEvent)
Parameters
telemetryEventTelemetryEvent
RecordAcceleratorUtilization(string, double, long)
Records accelerator utilization with backend-specific context.
public virtual void RecordAcceleratorUtilization(string acceleratorType, double utilization, long memoryUsed)
Parameters
RecordEvent(string, IDictionary<string, object?>?)
Records an event with structured data and performance tracking.
public virtual void RecordEvent(string name, IDictionary<string, object?>? attributes = null)
Parameters
namestringattributesIDictionary<string, object>
RecordGarbageCollection(int, TimeSpan, long, long)
Records garbage collection metrics with generation analysis.
public virtual void RecordGarbageCollection(int generation, TimeSpan duration, long memoryBefore, long memoryAfter)
Parameters
RecordHistogram(string, double, IDictionary<string, object?>?)
Records a histogram value with performance optimization.
public virtual void RecordHistogram(string name, double value, IDictionary<string, object?>? tags = null)
Parameters
namestringvaluedoubletagsIDictionary<string, object>
RecordKernelExecution(string, TimeSpan, long)
Records kernel execution with comprehensive performance tracking.
public virtual void RecordKernelExecution(string kernelName, TimeSpan duration, long operationCount)
Parameters
RecordMemoryAllocation(long, string?)
Records memory allocation with unified tracking across all backends.
public virtual void RecordMemoryAllocation(long bytes, string? allocationType = null)
Parameters
RecordMemoryTransfer(string, long, TimeSpan)
Records memory transfer with bandwidth analysis.
public virtual void RecordMemoryTransfer(string direction, long bytes, TimeSpan duration)
Parameters
RecordMetric(string, double, IDictionary<string, object?>?)
Records a metric value with comprehensive error handling and performance tracking.
public virtual void RecordMetric(string name, double value, IDictionary<string, object?>? tags = null)
Parameters
namestringvaluedoubletagsIDictionary<string, object>
StartActivity(string, ActivityKind)
Starts an activity with comprehensive context and error handling.
public virtual Activity? StartActivity(string name, ActivityKind kind = ActivityKind.Internal)
Parameters
namestringkindActivityKind
Returns
StartTimer(string, IDictionary<string, object?>?)
Starts a performance timer with comprehensive tracking.
public virtual IOperationTimer StartTimer(string operationName, IDictionary<string, object?>? tags = null)
Parameters
operationNamestringtagsIDictionary<string, object>
Returns
UpdateTelemetryOverhead(long)
Updates telemetry overhead tracking.
protected void UpdateTelemetryOverhead(long startTicks)
Parameters
startTickslong