What do time fields in CounterSample mean?
Asked Answered
T

1

7

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.

  • What do these mean exactly?
  • In what units are they? I tried all DateTime.FromX() functions, but none produces a reasonable result.
Taveda answered 3/4, 2012 at 15:22 Comment(3)
have a look at the doc of PerformanceCounterCallaghan
As the question indicates, the MSDN documentation on this is useless.Graver
You can get the UTC timestamp of the counter sample from the following expression: DateTime.FromFileTimeUtc(sample.TimeStamp100nSec).Auto
I
6
(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.

Ira answered 18/10, 2012 at 19:49 Comment(1)
this pretty much confirms my findings: typedescriptor.net/browse/members/…Ira

© 2022 - 2024 — McMap. All rights reserved.