Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do time fields in CounterSample mean?

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.
like image 278
Jonathan Avatar asked Apr 03 '12 15:04

Jonathan


1 Answers

(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.

like image 65
triple.vee Avatar answered Sep 28 '22 10:09

triple.vee