|
1 | 1 | #pragma once
|
2 |
| -#include <sys/stat.h> |
3 |
| -#include <thread> |
4 | 2 | #include <filesystem.h>
|
5 | 3 | #include <inttypes.h>
|
| 4 | +#include <sys/stat.h> |
| 5 | +#include <thread> |
6 | 6 | #ifdef TEST_ONLY
|
7 | 7 | #include <../src/mesa/util/os_time.h>
|
8 | 8 | #else
|
9 | 9 | #include <mesa/util/os_time.h>
|
10 | 10 | #endif
|
11 |
| -#include <spdlog/spdlog.h> |
12 | 11 | #include "gpu_metrics_util.h"
|
13 | 12 | #include <atomic>
|
| 13 | +#include <spdlog/spdlog.h> |
14 | 14 |
|
15 | 15 | 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; |
30 | 30 |
|
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(); |
37 | 37 |
|
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 | + } |
51 | 54 |
|
52 |
| - find_fd(); |
| 55 | + find_fd(); |
53 | 56 |
|
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 | + } |
57 | 60 |
|
58 |
| - gpu_metrics copy_metrics() const { |
59 |
| - return metrics; |
60 |
| - }; |
| 61 | + gpu_metrics copy_metrics() const |
| 62 | + { |
| 63 | + return metrics; |
| 64 | + }; |
61 | 65 |
|
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 | + } |
66 | 71 |
|
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 | + } |
71 | 77 | };
|
0 commit comments