gpt4 book ai didi

c# - 如何读取 GPU 负载?

转载 作者:太空狗 更新时间:2023-10-29 23:33:07 29 4
gpt4 key购买 nike

我正在写一个程序,监控计算机的各种资源,比如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);
}

}

最佳答案

显卡自身的 CPU 称为 GPU

查找与该视频或video 相关的性能计数器(使用Start->Run->PerfMon 或在 中键入PerfMon开始 菜单的搜索框;右击图形并选择添加计数器...)。

如果您的视频卡制造商没有为 GPU 提供任何性能计数器,您也无法获得任何性能计数器。

关于c# - 如何读取 GPU 负载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12224181/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com