< Summary

Information
Class: NGql.Core.Observability.PoolingObservability
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Observability/PoolingObservability.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 96
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RecordThreadLocalHit(...)100%11100%
RecordGlobalPoolHit(...)100%11100%
RecordAllocation(...)100%11100%
RecordPoolEfficiency(...)100%11100%
.ctor(...)100%66100%

File(s)

/home/runner/work/NGql/NGql/src/Core/Observability/PoolingObservability.cs

#LineLine coverage
 1using System.Diagnostics;
 2using System.Runtime.CompilerServices;
 3
 4namespace NGql.Core.Observability;
 5
 6/// <summary>
 7/// Specialized observability for pooling operations with detailed cache performance tracking
 8/// </summary>
 9internal static class PoolingObservability
 10{
 11    // Cache levels for standardized naming
 12    private const string ThreadLocalCache = "thread_local";
 13    private const string GlobalPool = "global_pool";
 14    private const string Allocation = "allocation";
 15
 16    /// <summary>
 17    /// Records a thread-local cache hit with observability
 18    /// </summary>
 19    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 20    internal static void RecordThreadLocalHit(string poolType)
 21    {
 22        // Metrics
 755123        NGqlTelemetry.RecordPoolOperation(poolType, "get", ThreadLocalCache, -1);
 24
 25        // Tracing (only if active listener exists)
 755126        using var activity = NGqlActivity.StartPooling(poolType, "get")
 755127            .WithPoolingTags(poolType, ThreadLocalCache, -1);
 1510228    }
 29
 30    /// <summary>
 31    /// Records a global pool hit with observability
 32    /// </summary>
 33    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 34    internal static void RecordGlobalPoolHit(string poolType, int currentPoolSize)
 35    {
 36        // Metrics
 185737        NGqlTelemetry.RecordPoolOperation(poolType, "get", GlobalPool, currentPoolSize);
 38
 39        // Tracing (only if active listener exists)
 185740        using var activity = NGqlActivity.StartPooling(poolType, "get")
 185741            .WithPoolingTags(poolType, GlobalPool, currentPoolSize);
 371442    }
 43
 44    /// <summary>
 45    /// Records a new allocation (cache miss) with observability
 46    /// </summary>
 47    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 48    internal static void RecordAllocation(string poolType)
 49    {
 50        // Metrics
 124251        NGqlTelemetry.RecordPoolOperation(poolType, "allocate", Allocation, 0);
 52
 53        // Tracing (only if active listener exists)
 124254        using var activity = NGqlActivity.StartPooling(poolType, "allocate")
 124255            .WithPoolingTags(poolType, Allocation, 0);
 248456    }
 57
 58    /// <summary>
 59    /// Records pool efficiency statistics for monitoring
 60    /// </summary>
 61    internal static void RecordPoolEfficiency(string poolType, PoolEfficiencyStats stats)
 62    {
 1263        using var activity = NGqlActivity.StartPooling(poolType, "efficiency_report")
 1264            .WithTag("pool.thread_local_hit_rate", stats.ThreadLocalHitRate)
 1265            .WithTag("pool.global_pool_hit_rate", stats.GlobalPoolHitRate)
 1266            .WithTag("pool.allocation_rate", stats.AllocationRate)
 1267            .WithTag("pool.total_operations", stats.TotalOperations);
 68
 69        // These could be exposed as gauges for monitoring dashboards
 1270        activity.AddEvent("efficiency_calculated", new ActivityTagsCollection
 1271        {
 1272            ["thread_local_efficiency"] = stats.ThreadLocalHitRate,
 1273            ["global_pool_efficiency"] = stats.GlobalPoolHitRate,
 1274            ["cache_effectiveness"] = stats.ThreadLocalHitRate + stats.GlobalPoolHitRate
 1275        });
 2476    }
 77
 78    /// <summary>
 79    /// Pool efficiency statistics for detailed monitoring
 80    /// </summary>
 81    internal readonly struct PoolEfficiencyStats
 82    {
 83        public readonly double ThreadLocalHitRate;
 84        public readonly double GlobalPoolHitRate;
 85        public readonly double AllocationRate;
 86        public readonly long TotalOperations;
 87
 88        public PoolEfficiencyStats(long threadLocalHits, long globalHits, long allocations)
 89        {
 1890            TotalOperations = threadLocalHits + globalHits + allocations;
 1891            ThreadLocalHitRate = TotalOperations > 0 ? (double)threadLocalHits / TotalOperations : 0;
 1892            GlobalPoolHitRate = TotalOperations > 0 ? (double)globalHits / TotalOperations : 0;
 1893            AllocationRate = TotalOperations > 0 ? (double)allocations / TotalOperations : 0;
 1894        }
 95    }
 96}