Skip to content

Commit 22c7523

Browse files
17314642flightlessmango
authored andcommitted
gpu_fdinfo: fix formatting
1 parent 1cad9c8 commit 22c7523

File tree

2 files changed

+69
-57
lines changed

2 files changed

+69
-57
lines changed

src/gpu_fdinfo.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "gpu_fdinfo.h"
22
namespace fs = ghc::filesystem;
33

4-
void GPU_fdinfo::find_fd() {
4+
void GPU_fdinfo::find_fd()
5+
{
56
auto path = fs::path("/proc/self/fdinfo");
67

78
if (!fs::exists(path)) {
@@ -33,7 +34,8 @@ void GPU_fdinfo::find_fd() {
3334
fdinfo.push_back(std::ifstream(fd));
3435
}
3536

36-
uint64_t GPU_fdinfo::get_gpu_time() {
37+
uint64_t GPU_fdinfo::get_gpu_time()
38+
{
3739
uint64_t total_val = 0;
3840

3941
for (auto& fd : fdinfo) {
@@ -52,7 +54,8 @@ uint64_t GPU_fdinfo::get_gpu_time() {
5254
return total_val;
5355
}
5456

55-
float GPU_fdinfo::get_vram_usage() {
57+
float GPU_fdinfo::get_vram_usage()
58+
{
5659
uint64_t total_val = 0;
5760

5861
for (auto& fd : fdinfo) {
@@ -71,7 +74,8 @@ float GPU_fdinfo::get_vram_usage() {
7174
return (float)total_val / 1024 / 1024;
7275
}
7376

74-
void GPU_fdinfo::find_intel_hwmon() {
77+
void GPU_fdinfo::find_intel_hwmon()
78+
{
7579
std::string device = "/sys/bus/pci/devices/";
7680
device += pci_dev;
7781
device += "/hwmon";
@@ -104,7 +108,8 @@ void GPU_fdinfo::find_intel_hwmon() {
104108
SPDLOG_DEBUG("Intel hwmon: failed to open {}", hwmon);
105109
}
106110

107-
float GPU_fdinfo::get_power_usage() {
111+
float GPU_fdinfo::get_power_usage()
112+
{
108113
if (!energy_stream.is_open())
109114
return 0.f;
110115

@@ -123,7 +128,8 @@ float GPU_fdinfo::get_power_usage() {
123128
return (float)energy_input / 1'000'000;
124129
}
125130

126-
void GPU_fdinfo::get_load() {
131+
void GPU_fdinfo::get_load()
132+
{
127133
while (!stop_thread) {
128134
std::unique_lock<std::mutex> lock(metrics_mutex);
129135
cond_var.wait(lock, [this]() { return !paused || stop_thread; });

src/gpu_fdinfo.h

+57-51
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,77 @@
11
#pragma once
2-
#include <sys/stat.h>
3-
#include <thread>
42
#include <filesystem.h>
53
#include <inttypes.h>
4+
#include <sys/stat.h>
5+
#include <thread>
66
#ifdef TEST_ONLY
77
#include <../src/mesa/util/os_time.h>
88
#else
99
#include <mesa/util/os_time.h>
1010
#endif
11-
#include <spdlog/spdlog.h>
1211
#include "gpu_metrics_util.h"
1312
#include <atomic>
13+
#include <spdlog/spdlog.h>
1414

1515
class GPU_fdinfo {
16-
private:
17-
bool init = false;
18-
struct gpu_metrics metrics;
19-
std::vector<std::ifstream> fdinfo;
20-
const std::string module;
21-
const std::string pci_dev;
22-
void find_fd();
23-
void find_intel_hwmon();
24-
std::ifstream energy_stream;
25-
std::thread thread;
26-
std::condition_variable cond_var;
27-
std::atomic<bool> stop_thread{false};
28-
std::atomic<bool> paused{false};
29-
mutable std::mutex metrics_mutex;
16+
private:
17+
bool init = false;
18+
struct gpu_metrics metrics;
19+
std::vector<std::ifstream> fdinfo;
20+
const std::string module;
21+
const std::string pci_dev;
22+
void find_fd();
23+
void find_intel_hwmon();
24+
std::ifstream energy_stream;
25+
std::thread thread;
26+
std::condition_variable cond_var;
27+
std::atomic<bool> stop_thread { false };
28+
std::atomic<bool> paused { false };
29+
mutable std::mutex metrics_mutex;
3030

31-
uint64_t get_gpu_time();
32-
void get_load();
33-
std::string drm_engine_type = "EMPTY";
34-
std::string drm_memory_type = "EMPTY";
35-
float get_vram_usage();
36-
float get_power_usage();
31+
uint64_t get_gpu_time();
32+
void get_load();
33+
std::string drm_engine_type = "EMPTY";
34+
std::string drm_memory_type = "EMPTY";
35+
float get_vram_usage();
36+
float get_power_usage();
3737

38-
public:
39-
GPU_fdinfo(const std::string module, const std::string pci_dev) : module(module), pci_dev(pci_dev) {
40-
if (module == "i915") {
41-
drm_engine_type = "drm-engine-render";
42-
drm_memory_type = "drm-total-local0";
43-
find_intel_hwmon();
44-
} else if (module == "amdgpu") {
45-
drm_engine_type = "drm-engine-gfx";
46-
drm_memory_type = "drm-memory-vram";
47-
} else if (module == "msm") {
48-
// msm driver does not report vram usage
49-
drm_engine_type = "drm-engine-gpu";
50-
}
38+
public:
39+
GPU_fdinfo(const std::string module, const std::string pci_dev)
40+
: module(module)
41+
, pci_dev(pci_dev)
42+
{
43+
if (module == "i915") {
44+
drm_engine_type = "drm-engine-render";
45+
drm_memory_type = "drm-total-local0";
46+
find_intel_hwmon();
47+
} else if (module == "amdgpu") {
48+
drm_engine_type = "drm-engine-gfx";
49+
drm_memory_type = "drm-memory-vram";
50+
} else if (module == "msm") {
51+
// msm driver does not report vram usage
52+
drm_engine_type = "drm-engine-gpu";
53+
}
5154

52-
find_fd();
55+
find_fd();
5356

54-
std::thread thread(&GPU_fdinfo::get_load, this);
55-
thread.detach();
56-
}
57+
std::thread thread(&GPU_fdinfo::get_load, this);
58+
thread.detach();
59+
}
5760

58-
gpu_metrics copy_metrics() const {
59-
return metrics;
60-
};
61+
gpu_metrics copy_metrics() const
62+
{
63+
return metrics;
64+
};
6165

62-
void pause() {
63-
paused = true;
64-
cond_var.notify_one();
65-
}
66+
void pause()
67+
{
68+
paused = true;
69+
cond_var.notify_one();
70+
}
6671

67-
void resume() {
68-
paused = false;
69-
cond_var.notify_one();
70-
}
72+
void resume()
73+
{
74+
paused = false;
75+
cond_var.notify_one();
76+
}
7177
};

0 commit comments

Comments
 (0)