ProfilerSession

Models & Types · AiDotNet.Diagnostics

Instance-based performance profiler for ML operations.

How It Works

Overview: ProfilerSession provides comprehensive performance monitoring for machine learning workloads including timing, memory tracking, and hierarchical call analysis.

Facade Pattern: This class follows the AiDotNet facade pattern. Users don’t create ProfilerSession directly; instead, they configure profiling through AiModelBuilder.ConfigureProfiling() and access results through AiModelResult.ProfilingReport.

Production-Ready Features:

  • O(1) streaming statistics using Welford’s algorithm
  • Bounded memory with reservoir sampling for percentiles
  • Configurable sampling rate for high-frequency operations
  • Thread-safe timing collection
  • Hierarchical call tree tracking
  • Memory allocation monitoring
  • Statistical aggregation (min, max, mean, p95, p99)
  • Profile scope pattern (using blocks)

Internal Usage Example:

Constructors

Constructor Summary
ProfilerSession(ProfilingConfig config) Creates a new profiler session with the specified configuration.

Properties

Property Summary
ProfilingConfig Config { get; } Gets the configuration for this profiler session.
TimeSpan Elapsed { get; } Gets the elapsed time since this session started.
bool IsEnabled { get; } Gets whether the profiler session is currently enabled.
int OperationCount { get; } Gets the total number of unique operations tracked.

Methods

Method Summary
IReadOnlyList<string> GetOperationNames() Gets all operation names that have been profiled.
ProfileReport GetReport() Gets a comprehensive profiling report.
ProfilerSessionScope Scope(string name) Creates a scoped profiler that automatically records duration.
ProfilerSessionTimer Start(string name) Starts a manual profiler timer.
ProfilerStats GetStats(string name) Gets timing statistics for a specific operation.
string GetSummary() Gets a summary string of profiling results.
void Disable() Disables profiling for this session.
void Enable() Enables profiling for this session.
void Reset() Resets all collected profiling data.