用c++查linux与windows上的显存利用率,内存使用率,cpu占有率,gpu占有率

一、显存利用率

Windows

https://blog.csdn.net/paopaoc/article/details/9093125

linux

https://blog.csdn.net/paopaoc/article/details/9093125

二、GPU占用率

Windows

https://blog.csdn.net/paopaoc/article/details/9093125

linux

https://blog.csdn.net/paopaoc/article/details/9093125

三、cpu占有率

Windows

https://www.cnblogs.com/lidabo/p/7554455.html

linux

https://blog.csdn.net/sinat_37853238/article/details/112851761
https://blog.csdn.net/qq_28256407/article/details/119153779

四、内存使用率

Windows

https://www.cnblogs.com/lidabo/p/7554455.html

linux

https://blog.csdn.net/sinat_37853238/article/details/112851761

  • 11
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux系统中,获取CPU使用率内存使用率可以通过读取/proc/stat和/proc/meminfo文件来实现。下面是Linux平台下获取CPU使用率内存使用率的示例代码: 获取CPU使用率: ```c++ #include <fstream> #include <iostream> #include <sstream> #include <string> #include <unistd.h> using namespace std; double getCpuUsage() { static unsigned long long lastTotalUser, lastTotalUserLow, lastTotalSys, lastTotalIdle; ifstream fileStat("/proc/stat"); string line; getline(fileStat, line); istringstream ss(line); ss.ignore(5); // skip "cpu" word unsigned long long totalUser, totalUserLow, totalSys, totalIdle, totalIOwait, totalIRQ, totalSoftIRQ; ss >> totalUser >> totalUserLow >> totalSys >> totalIdle >> totalIOwait >> totalIRQ >> totalSoftIRQ; if (totalUser < lastTotalUser || totalUserLow < lastTotalUserLow || totalSys < lastTotalSys || totalIdle < lastTotalIdle) { // Overflow detection. Just skip this value. return -1.0; } unsigned long long total = totalUser - lastTotalUser + totalUserLow - lastTotalUserLow + totalSys - lastTotalSys; double cpuUsage = total; total += totalIdle - lastTotalIdle; cpuUsage /= total; lastTotalUser = totalUser; lastTotalUserLow = totalUserLow; lastTotalSys = totalSys; lastTotalIdle = totalIdle; return cpuUsage * 100.0; } int main() { while (true) { double cpuUsage = getCpuUsage(); cout << "CPU usage: " << cpuUsage << "%" << endl; usleep(1000000); } return 0; } ``` 获取内存使用率: ```c++ #include <fstream> #include <iostream> #include <sstream> #include <string> #include <unistd.h> using namespace std; double getMemoryUsage() { ifstream fileMem("/proc/meminfo"); string line; getline(fileMem, line); istringstream ss(line); ss.ignore(256, ' '); unsigned long long totalMem; ss >> totalMem; totalMem *= 1024; // convert to bytes getline(fileMem, line); ss.str(line); ss.clear(); ss.ignore(256, ' '); unsigned long long freeMem; ss >> freeMem; freeMem *= 1024; double memoryUsage = 100.0 * (totalMem - freeMem) / totalMem; return memoryUsage; } int main() { while (true) { double memoryUsage = getMemoryUsage(); cout << "Memory usage: " << memoryUsage << "%" << endl; usleep(1000000); } return 0; } ``` 以上示例代码只是提供了一个简单的思路,实际应用中还需要对获取到的数据进行处理和显示。另外,Linux系统提供了更为底层的API函数,如getrusage()和sysinfo()等,也可以用于获取系统资源使用情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值