Is it possible to read the internal processor count with C #?

I have a multi-threaded program in C # where I need to register how many ticks of each thread are spent on a specific wait lock.

I know that there are methods for this from C or assembler, but is it possible from accessing the same counter directly from C # in some way, that is, without going through the Stopwatch class (I assume that Start / Stop on is called that has some overhead and I'm not sure how accurate this is)?

+3
source share
3 answers

Before "eliminating" the use of System.Diagnostics.Stopwatch: does your test system support a high-resolution stopwatch ?: see MSDN in 'StopWatch: check-out:' Frequency and 'IsHighResolution .

Excellent SO stream when getting the “best” from StopWatch: SO stream does not miss Eric Lippert's comments

Accuracy and Accuracy in Time Measurement .net: SO-stream: Accuracy and accuracy of .NET time measurement can be useful.

"Cost" of API calls in C # API for Win32: QueryPerformanceFrequency and QueryPerformanceCounter: compared to StopWatch?

One example API from C # here on Codeproject: 2006 code, the author in a comment says that he did not consider thread safety

, SO, , JIT- ( " " ), .. .

+8

QueryPerformanceCounter QueryPerformenceFrequency.
.

System.Diagnostics.Stopwatch .
Compact Framework, .

+4

StopWatch , API * QueryPerformance **, .

MSDN:

The stopwatch class helps manipulate the synchronization of performance counters in managed code. In particular, the frequency field and the GetTimestamp method can be used instead of the unmanaged Win32 API QueryPerformanceFrequency and QueryPerformanceCounter.

In addition, the results compiled by Christoph Verbist are noteworthy.

+2
source

Source: https://habr.com/ru/post/1727931/


All Articles