V.B.
V.B.

Reputation: 6382

C# Get CPU cache miss performance counter

I know that CPUs count all L1/2/3 cache misses, and this info is accessible in principle. E.g. there is a performance viewer from Intel. I just cannot find an example in C#. Is this data accessible from .NET?

Upvotes: 6

Views: 3584

Answers (1)

Evk
Evk

Reputation: 101443

Well you can do this (on windows at least) using Intel Perfomance Counter Monitor. In addition to other tools which come bundled with it, it contains PCM-Service - windows service which adds PCM windows perfomance counters. Once you downloaded, compiled and installed this service, you can access L2 cache misses (for example), as easy as this:

var pc = new PerformanceCounter("PCM Core Counters", "L2 Cache Misses", "total_"); // instead of total_ you can use number of core
var value = pc.RawValue; // or pc.NextValue() and so on.

Intel PCM adds much more interesting counters than just cache misses of course, all of which are accessible from .NET.

Upvotes: 5

Related Questions