C#Performance Counter帮助,Nvidia GPU [英] C# Performance Counter Help, Nvidia GPU

查看:466
本文介绍了C#Performance Counter帮助,Nvidia GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在用C#测试性能计数器类,并且在探测CPU计数器以及Windows性能监视器中可以找到的几乎所有东西方面都取得了巨大的成功.但是,我无法访问"NVIDIA GPU"类别...

例如,下面的代码行通常是这样工作的.

PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");

该代码可以正常工作,但是C#无法访问出现在性能监视器中的GPU类别,就像处理器类别一样.以下代码行尝试访问它.

PerformanceCounter gpuCounter = new PerformanceCounter("NVIDIA GPU", "% GPU Usage","#0 Quadro K1100M(id=1, NVAPI ID=256)");

相反,它引发类别不存在"异常...

这是性能监视器中的外观

该类别显然存在,所以我的问题是...我如何访问此计数器?

解决方案

在此上花费了六个小时之后,我准备分享我的结果.有几种测试方法可用来搜索缺少的性能指标.

1)首先是非常简单的关键字搜索.这包括PerformaceCounterCategory以及在我的系统上运行的每个性能计数器实例(其中约有12,000个).这种方法没有找到与GPU或NVIDIA相关的任何东西,但是对于CPU而言却完美无缺.

2)通过以非常特定的使用率运行GPU来执行下一个测试,并执行搜索以评估在狭窄值范围内运行的每个性能百分比计数器.这种方法也没有返回任何与GPU相关的信息,但是对于CPU来说仍然可以完美地工作.

得出一个结论. 即使没有假别名,GPU确实没有性能计数器.


解决方案:

没有任何地方表明性能监视器必须显式使用性能计数器,而对此的一小段提示却一直困扰着我们.性能监视器中的实例变量标记为"NVAPI ID = 256". NVIDIA API旨在允许对NVIDIA硬件进行性能监视.尽管它可以执行类似于性能计数器的操作,但它不会使用相同的数据类型来执行其任务.现在,我们有证据表明性能监视器正在使用NVAPI来收集信息,而不是使用性能计数器.这非常容易引起误解,因为其他所有条目都对应一个计数器.因此,我们可以得出结论,访问这些变量的唯一正确方法是通过NVAPI.

首先从NVIDIA网站此处. >

接下来,我使用一些发现的示例代码此处来自使用Open Hardware Monitor源代码的博客作者,并且在此处来自该网站上的另一篇文章.

代码是用C ++编写的,但是在移动了一些库并制作了一些.dll的所有内容之后,这些代码很好地移植到了C#中.

这里是结果的图片.谢谢大家的帮助和支持!

So I've been experimenting with the performance counter class in C# and have had great success probing the CPU counters and almost everything I can find in the windows performance monitor. HOWEVER, I cannot gain access to the "NVIDIA GPU" category...

So for example, the following line of code is how it usually works.

PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");

That code works fine, but the GPU category that appeared in the performance monitor, just as the processor category did, is not accessible by C#. The following line of code attempts to access it.

PerformanceCounter gpuCounter = new PerformanceCounter("NVIDIA GPU", "% GPU Usage","#0 Quadro K1100M(id=1, NVAPI ID=256)");

Instead it throws a "Category does not exist" exception...

Here is what it looks like from within the Performance Monitor

The category clearly exists, so my question is... how do I access this counter?

解决方案

After spending six hours on this, I am ready to share my results. There were several testing methods used to search for this missing performance counter.

1) The first was a very simple search for keywords. This included PerformaceCounterCategory's as well as every single instance of performance counter running on my system (around 12,000 of them). This method did not find anything GPU or NVIDIA related, but worked flawlessly for the CPU.

2) The next test was performed by running the GPU at a very specific % usage and a search was performed that evaluated every percentage performance counter running within a narrow range of values. This method also did not return anything GPU related, but again worked flawlessly for the CPU.

This lead to one conclusion. There truly is no performance counter for the GPU, not even under a false alias.


Solution:

Nowhere does it state that the performance monitor must explicitly use performance counters, and a small hint to this was staring us in the face this entire time. The instance variable in the performance monitor was labeled "NVAPI ID=256". The NVIDIA API was designed to allow performance monitoring capabilities to NVIDIA hardware. Although it can perform actions similar to performance counters, it does not use the same data types to perform its task. We now have evidence that the Performance Monitor was using the NVAPI to gather information instead of using a performance counter. This was very misleading because every other entry corresponds to a counter. So we can conclude that the only proper way to access these variables is through the NVAPI.

I was able to do this successfully by first downloading the NVAPI from the NVIDIA website here.

Next I used some sample code found here from a blogger that is using Open Hardware Monitor source code, and here from another post on this site.

The code is written in C++, but after moving some libraries around and making a few .dll's everything ports nicely to C#.

Here is a picture of the result. Thank you everyone for your help and support!

这篇关于C#Performance Counter帮助,Nvidia GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆