| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | |
| | | 3 | | namespace NGql.Core.Observability; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Specialized observability for pooling operations with detailed cache performance tracking |
| | | 7 | | /// </summary> |
| | | 8 | | internal static class PoolingObservability |
| | | 9 | | { |
| | | 10 | | // Cache levels for standardized naming |
| | | 11 | | private const string ThreadLocalCache = "thread_local"; |
| | | 12 | | private const string GlobalPool = "global_pool"; |
| | | 13 | | private const string Allocation = "allocation"; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Records a thread-local cache hit with observability |
| | | 17 | | /// </summary> |
| | | 18 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 19 | | internal static void RecordThreadLocalHit(string poolType) |
| | | 20 | | { |
| | | 21 | | // Metrics |
| | 7629 | 22 | | NGqlTelemetry.RecordPoolOperation(poolType, "get", ThreadLocalCache, -1); |
| | | 23 | | |
| | | 24 | | // Tracing (only if active listener exists) |
| | 7629 | 25 | | using var activity = NGqlActivity.StartPooling(poolType, "get") |
| | 7629 | 26 | | .WithPoolingTags(poolType, ThreadLocalCache, -1); |
| | 15258 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Records a global pool hit with observability |
| | | 31 | | /// </summary> |
| | | 32 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 33 | | internal static void RecordGlobalPoolHit(string poolType, int currentPoolSize) |
| | | 34 | | { |
| | | 35 | | // Metrics |
| | 1818 | 36 | | NGqlTelemetry.RecordPoolOperation(poolType, "get", GlobalPool, currentPoolSize); |
| | | 37 | | |
| | | 38 | | // Tracing (only if active listener exists) |
| | 1818 | 39 | | using var activity = NGqlActivity.StartPooling(poolType, "get") |
| | 1818 | 40 | | .WithPoolingTags(poolType, GlobalPool, currentPoolSize); |
| | 3636 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Records a new allocation (cache miss) with observability |
| | | 45 | | /// </summary> |
| | | 46 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 47 | | internal static void RecordAllocation(string poolType) |
| | | 48 | | { |
| | | 49 | | // Metrics |
| | 1290 | 50 | | NGqlTelemetry.RecordPoolOperation(poolType, "allocate", Allocation, 0); |
| | | 51 | | |
| | | 52 | | // Tracing (only if active listener exists) |
| | 1290 | 53 | | using var activity = NGqlActivity.StartPooling(poolType, "allocate") |
| | 1290 | 54 | | .WithPoolingTags(poolType, Allocation, 0); |
| | 2580 | 55 | | } |
| | | 56 | | |
| | | 57 | | } |