Skip to content

Instantly share code, notes, and snippets.

@happyme531
Created September 15, 2023 07:21
Show Gist options
  • Select an option

  • Save happyme531/f847cd5fd2734aee99f4af11f5a5f332 to your computer and use it in GitHub Desktop.

Select an option

Save happyme531/f847cd5fd2734aee99f4af11f5a5f332 to your computer and use it in GitHub Desktop.
RK3588 GPU/NPU/DDR Load&Frequency viewer
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main() {
// 处理GPU
std::ifstream gpu_load("/sys/class/devfreq/fb000000.gpu/load");
std::string gpu;
gpu_load >> gpu;
int gpu_load_value;
float gpu_freq;
std::stringstream ss(gpu);
std::string token;
std::getline(ss, token, '@');
gpu_load_value = std::stoi(token);
std::getline(ss, token, 'H');
gpu_freq = std::stof(token) / 1000000000.0;
// 处理DDR
std::ifstream ddr_load("/sys/class/devfreq/dmc/load");
std::string ddr;
ddr_load >> ddr;
int ddr_load_value;
float ddr_freq;
std::stringstream ss2(ddr);
std::getline(ss2, token, '@');
ddr_load_value = std::stoi(token);
std::getline(ss2, token, 'H');
ddr_freq = std::stof(token) / 1000000000.0;
// 处理NPU
std::ifstream npu_load("/sys/kernel/debug/rknpu/load");
std::string npu;
std::getline(npu_load, npu);
std::cout << "3588PerfView by hallo1 @ 2023.9.11" << std::endl << std::endl;
std::cout << "GPU load: " << gpu_load_value << "%, freq: " << gpu_freq << "GHz" << std::endl;
std::cout << "DDR load: " << ddr_load_value << "%, freq: " << ddr_freq << "GHz" << std::endl;
std::cout << npu << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment