I have an instance of PerformanceCounter
, I call NextSample()
on it and get a CounterSample
. In it, there are several time-related fields: CounterFrequency, SystemFrequency, CounterTimeStamp, Timestamp and TimeStamp100nSec.
The MSDN page for CounterSample only says "Gets the raw counter frequency" and similar unhelpful descriptions, and a sample that prints the value without explanations.
DateTime.FromX()
functions, but none produces a reasonable result.(sample2.Timestamp - sample1.Timestamp) / sample2.SystemFrequency = elapsed seconds
(sample2.TimeStamp100nSec - sample1.TimeStamp100nSec) / 10000000 = elapsed seconds
I was able to reverse engineer this when I was analyzing how LOGMAN.EXE would read perf counters and store them in a SQL database. CounterSample class (from various disassemblies) wraps this C structure
PDH_RAW_COUNTER
In this C structure, SecondValue has either TimeStamp or TimeStamp100nSec depending on the counter type. By the time it gets wrapped in .NET CounterSample struct, you can get either via the properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With