System metrics: learning to avoid pitfalls
summary
Benchmarks show System.Diagnostics.Process queries allocate megabytes and take milliseconds (one test wastes ~1.5 MB per call) while calling native GetProcessMemoryInfo returns the same numbers five orders of magnitude faster; reading per-process metrics via Performance Counters hits the registry, returns all instances and causes large allocations (category calls ~26 ms and ~4 MB alloc), whereas Performance Data Helpers cuts many counters to microseconds but process-category stays slow; switch to ETW/runtime events for low-overhead GC and runtime telemetry, but watch session limits and localization traps.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:10Memory metrics pitfalls
- 5:08Process.Diagnostics.Process issues
- 7:40Performance Counters overview
- 10:11Performance Counters in code
- 15:38Performance Counters pitfalls
- 26:42Performance Counters vs WinAPI
- 28:05Summary of Performance Counters
- 29:10ETW tracing introduction
- 31:22ETW tracing details
- 34:14ETW tracing limitations
- 36:47Runtime Events in .NET Core
- 38:53Conclusion and recommendations
- 41:04Q&A
