【问题标题】:How can I read the GPU load?如何读取 GPU 负载?
【发布时间】:2012-09-01 01:26:26
【问题描述】:

我正在编写一个程序来监控计算机的各种资源,例如 CPU 使用率等。我还想监控 GPU 使用情况(GPU 负载,而不是温度)。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DannyGeneral;


namespace CpuUsage
{
    public partial class Form1 : Form
    {
        private bool processEnded;
        private Process[] processList;
        private string timeStarted;
        private string timeEnded;
        private List<float> processValues;
        private bool alreadyRun;
        private DateTime dt;
        private DateTime dt1;
        private PerformanceCounter theCPUCounter;
        private PerformanceCounter theMemCounter;
        private PerformanceCounter specProcessCPUCounter;
        private float cpuUsage;
        private float memUsage;
        private List<float> Values;

        public Form1()
        {
            InitializeComponent();

            processEnded = false;
            processList = Process.GetProcesses();
            for (int i = 0; i < processList.Count(); i++)
            {
                listView1.Items.Add(processList[i].ProcessName);
            }
            processValues = new List<float>();
            alreadyRun = false;
            dt = DateTime.Now;


            Values = new List<float>();
                theCPUCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                theMemCounter = new PerformanceCounter("Memory", "Available MBytes");
                specProcessCPUCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);

                Logger.Write("The Program Started At ***   " + DateTime.Now.ToShortTimeString());

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            memUsage = theMemCounter.NextValue();
            label1.Text = memUsage.ToString();
            Logger.Write("Memory Usage   " + memUsage.ToString());
            cpuUsage = this.theCPUCounter.NextValue();
            label2.Text = cpuUsage.ToString();
            Logger.Write("Cpu Usage   " + this.cpuUsage.ToString());
            Values.Add(cpuUsage);
            isProcessRunning();
            if (alreadyRun == true)
            {
                processValues.Add(cpuUsage);
            }

        }

【问题讨论】:

  • 对于未来的问题,请考虑提供仅包含相关代码的较小示例。你现在的那个有太多与 UI 相关的东西,简单的Console.Write("CPU usage:{0}", new PerformanceCounter("Processor", "% Processor Time", "_Total"); .NextValue()) 就足够了。
  • 我使用以下答案来读取 CPU 负载:stackoverflow.com/a/71481615/171846

标签: c# performance gpu video-card


【解决方案1】:

video card's own CPU 称为GPU

查找与此相关的性能计数器或video(使用Start-&gt;Run-&gt;PerfMon 或在Start 菜单的搜索框中输入PerfMon;右键单击图表并选择Add Counter...)。

如果您的显卡制造商没有为 GPU 提供任何性能计数器,那么您将没有任何性能计数器。

【讨论】:

  • 当然,性能计数器不是有关正在运行的系统的唯一信息来源。
  • @BenVoigt:我从没想过要说他们是。我建议作为来源,基于发布的其他代码。随意提供他人。 :-)
  • 我不确定你的最后一句话是什么意思。无论如何,有 RivaTuner,它带有一个 API 以编程方式访问数据,以及许多其他无需性能计数器即可获取这些数据的监控程序。
  • @BenVoigt 我的意思是“如果您寻找视频或 GPU 的性能计数器但没有找到,那么您的显卡制造商没有提供一个”。我不确定其中哪一部分不清楚 - 我怎样才能更清楚地表达它?
  • 在 .NET 中获取 GPU 使用情况的属性名称/键名称是什么?
猜你喜欢
  • 2013-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2019-10-17
  • 1970-01-01
  • 2012-01-15
相关资源
最近更新 更多