Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Get CPU cache miss performance counter

Tags:

c#

.net

cpu-cache

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?

like image 842
V.B. Avatar asked Oct 19 '22 02:10

V.B.


1 Answers

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.

like image 66
Evk Avatar answered Nov 12 '22 22:11

Evk