From 5ac7cd47a70c646ee8db3f6a3cc59ae5d9ef114e Mon Sep 17 00:00:00 2001 From: Filip Date: Sat, 24 Jan 2026 20:15:07 +0100 Subject: [PATCH 1/9] chore: setup helix editor configs && update .gitignore --- .gitignore | 1 + .helix/languages.toml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .helix/languages.toml diff --git a/.gitignore b/.gitignore index 7e53678..fc39ba5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ bin/ +.cache/ diff --git a/.helix/languages.toml b/.helix/languages.toml new file mode 100644 index 0000000..6666436 --- /dev/null +++ b/.helix/languages.toml @@ -0,0 +1,18 @@ +[[language]] +name = "c" +scope = "source.c" +file-types = [] + +[[language]] +name = "cpp" +scope = "source.cpp" +file-types = ["cc", "hh", "c++", "cpp", "hpp", "h", "ipp", "tpp", "cxx", "hxx", "ixx", "txx", "ino", "C", "H", "cu", "cuh"] +language-servers = ["clangd"] + +[language-server.clangd] +command = "clangd" +args = [ + "--header-insertion=never", + "--query-driver=/usr/bin/g++,/usr/bin/c++", + "--compile-commands-dir=build" +] From 2123226844e5d116893de2f2931ce9335340e58a Mon Sep 17 00:00:00 2001 From: Filip Date: Sat, 24 Jan 2026 23:37:19 +0100 Subject: [PATCH 2/9] feat(agent): add minimal intel RAPL collector --- source/agent/src/collectors/rapl_collector.cc | 60 ++++++++++++++++ source/agent/src/collectors/rapl_collector.h | 68 +++++++++++++++++++ source/agent/src/config/config_loader.cc | 7 +- source/agent/src/main.cc | 8 +-- 4 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 source/agent/src/collectors/rapl_collector.cc create mode 100644 source/agent/src/collectors/rapl_collector.h diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc new file mode 100644 index 0000000..e5ba9b7 --- /dev/null +++ b/source/agent/src/collectors/rapl_collector.cc @@ -0,0 +1,60 @@ +#include "rapl_collector.h" + +#include +#include + +#include +#include + +namespace volta { +namespace agent { +namespace collectors { + +RaplCollector::RaplCollector() { + uint64_t readout = ReadMSR(MSR_RAPL::POWER_UNIT); + + power_units_ = pow(0.5, (double)(readout & 0xf)); + energy_units_ = pow(0.5, (double)((readout >> 8) & 0x1f)); + time_units_ = pow(0.5, (double)((readout >> 16) & 0xf)); + readout = ReadMSR(MSR_RAPL::PKG::ENERGY_STATUS); + last_value = energy_units_ * readout; +} + +std::vector RaplCollector::Collect() { + uint64_t readout = ReadMSR(MSR_RAPL::PKG::ENERGY_STATUS); + double value = energy_units_ * readout; + + // TODO add more metrics + Metric m; + m.name = "cpu_energy_usage_total"; + m.value = value - last_value; + m.timestamp = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + last_value = value; + return {m}; +} + +uint64_t RaplCollector::ReadMSR(uint32_t offset) { + // TODO support other cores + int fd = OpenMSR(0); + + uint64_t data; + // c-like read for thread safety + if (pread(fd, &data, sizeof data, offset) != sizeof data) { + return {}; + } + + CloseMSR(fd); + return data; +} + +int RaplCollector::OpenMSR(uint8_t core) { + std::string path = "/dev/cpu/" + std::to_string(core) + "/msr"; + return open(path.c_str(), O_RDONLY); +} +void RaplCollector::CloseMSR(int fd) { close(fd); } + +} // namespace collectors +} // namespace agent +} // namespace volta diff --git a/source/agent/src/collectors/rapl_collector.h b/source/agent/src/collectors/rapl_collector.h new file mode 100644 index 0000000..58123e4 --- /dev/null +++ b/source/agent/src/collectors/rapl_collector.h @@ -0,0 +1,68 @@ +#ifndef VOLTA_AGENT_SRC_COLLECTORS_RAPL_COLLECTOR_H_ +#define VOLTA_AGENT_SRC_COLLECTORS_RAPL_COLLECTOR_H_ + +#include "collectors/collector.h" + +namespace volta { +namespace agent { +namespace collectors { + +class RaplCollector : public Collector { + public: + RaplCollector(); + // ~RaplCollector() override; + + std::vector Collect() override; + + private: + uint64_t ReadMSR(uint32_t offset); + int OpenMSR(uint8_t core); + void CloseMSR(int fd); + bool initialized_ = false; + double power_units_, energy_units_, time_units_; + + double last_value; + struct MSR_RAPL { + static constexpr uint32_t POWER_UNIT = 0x606; + struct Units { + static constexpr uint32_t POWER_UNIT_OFFSET = 0; + static constexpr uint32_t POWER_UNIT_MASK = 0x0F; + static constexpr uint32_t ENERGY_UNIT_OFFSET = 0x08; + static constexpr uint32_t ENERGY_UNIT_MASK = 0x1F00; + static constexpr uint32_t TIME_UNIT_OFFSET = 0x10; + static constexpr uint32_t TIME_UNIT_MASK = 0xF000; + }; + + struct PKG { + static constexpr uint32_t POWER_LIMIT = 0x610; + static constexpr uint32_t ENERGY_STATUS = 0x611; + static constexpr uint32_t PERF_STATUS = 0x613; + static constexpr uint32_t POWER_INFO = 0x614; + }; + + struct PP0 { + static constexpr uint32_t POWER_LIMIT = 0x638; + static constexpr uint32_t ENERGY_STATUS = 0x639; + static constexpr uint32_t POLICY = 0x63A; + static constexpr uint32_t PERF_STATUS = 0x63B; + }; + + struct PP1 { + static constexpr uint32_t POWER_LIMIT = 0x640; + static constexpr uint32_t ENERGY_STATUS = 0x641; + static constexpr uint32_t POLICY = 0x642; + }; + + struct DRAM { + static constexpr uint32_t POWER_LIMIT = 0x618; + static constexpr uint32_t ENERGY_STATUS = 0x619; + static constexpr uint32_t PERF_STATUS = 0x61B; + static constexpr uint32_t POWER_INFO = 0x61C; + }; + }; +}; + +} // namespace collectors +} // namespace agent +} // namespace volta +#endif diff --git a/source/agent/src/config/config_loader.cc b/source/agent/src/config/config_loader.cc index d409213..2a0e393 100644 --- a/source/agent/src/config/config_loader.cc +++ b/source/agent/src/config/config_loader.cc @@ -21,10 +21,15 @@ Config ConfigLoader::LoadConfig() { proc_stat_config.metrics["cpu_usage_percent"] = true; config.collectors[CollectorNames::kProcStat] = proc_stat_config; + CollectorConfig rapl_collector; + rapl_collector.enabled = true; + rapl_collector.metrics = {{"cpu_energy_usage_total", true}}; + config.collectors[CollectorNames::kRapl] = rapl_collector; + return config; } -Config ConfigLoader::LoadConfig(const std::filesystem::path& filepath) { +Config ConfigLoader::LoadConfig(const std::filesystem::path &filepath) { // ignore for POC return LoadConfig(); } diff --git a/source/agent/src/main.cc b/source/agent/src/main.cc index e44c31e..caece51 100644 --- a/source/agent/src/main.cc +++ b/source/agent/src/main.cc @@ -9,6 +9,7 @@ #include "collectors/nvml_collector.h" #include "collectors/proc_stat_collector.h" #include "collectors/ram_collector.h" +#include "collectors/rapl_collector.h" #include "config/config.h" #include "config/config_loader.h" #include "platform/platform_detector.h" @@ -28,10 +29,9 @@ int main() { active_collectors.push_back( std::make_unique()); - active_collectors.push_back(std::make_unique()); - - for (const auto& gpu : hw.gpus) { + active_collectors.push_back(std::make_unique()); + for (const auto &gpu : hw.gpus) { if (gpu.vendor == platform::GpuVendor::NVIDIA) { auto nvml = std::make_unique(); if (nvml->Init()) { @@ -43,7 +43,7 @@ int main() { Scheduler scheduler(config, std::move(active_collectors)); scheduler.Run(); - } catch (const std::exception& e) { + } catch (const std::exception &e) { std::cerr << "CRITICAL ERROR: " << e.what() << std::endl; return 1; } From 9dae3148212a9f14cbe0d2041e408f42c57fb536 Mon Sep 17 00:00:00 2001 From: Filip Date: Sun, 29 Mar 2026 23:02:46 +0200 Subject: [PATCH 3/9] feat: implement core detection and improve error handling --- CMakeLists.txt | 2 +- source/agent/CMakeLists.txt | 2 +- source/agent/src/collectors/rapl_collector.cc | 60 +++++++++++++++---- source/agent/src/collectors/rapl_collector.h | 12 ++-- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff22de7..03e9cc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(Protobuf REQUIRED) +find_package(Protobuf CONFIG REQUIRED) find_package(gRPC CONFIG REQUIRED) set(PROTO_DIR ${CMAKE_SOURCE_DIR}/libs/proto) diff --git a/source/agent/CMakeLists.txt b/source/agent/CMakeLists.txt index 46a770a..dc01e4b 100644 --- a/source/agent/CMakeLists.txt +++ b/source/agent/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(${AGENT_NAME} PRIVATE src) target_link_libraries(${AGENT_NAME} PRIVATE volta_proto) find_package(Threads REQUIRED) -find_package(Protobuf REQUIRED) +find_package(Protobuf CONFIG REQUIRED) find_package(gRPC REQUIRED) target_link_libraries(${AGENT_NAME} PRIVATE Threads::Threads) diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc index e5ba9b7..0fecffd 100644 --- a/source/agent/src/collectors/rapl_collector.cc +++ b/source/agent/src/collectors/rapl_collector.cc @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include @@ -11,17 +13,29 @@ namespace agent { namespace collectors { RaplCollector::RaplCollector() { - uint64_t readout = ReadMSR(MSR_RAPL::POWER_UNIT); - + try { + OpenMSR(); + }catch(std::exception e){ + throw e; + } + uint64_t readout = ReadMSR(0, MSR_RAPL::POWER_UNIT); power_units_ = pow(0.5, (double)(readout & 0xf)); energy_units_ = pow(0.5, (double)((readout >> 8) & 0x1f)); time_units_ = pow(0.5, (double)((readout >> 16) & 0xf)); - readout = ReadMSR(MSR_RAPL::PKG::ENERGY_STATUS); + readout = ReadMSR(0, MSR_RAPL::PKG::ENERGY_STATUS); last_value = energy_units_ * readout; } std::vector RaplCollector::Collect() { - uint64_t readout = ReadMSR(MSR_RAPL::PKG::ENERGY_STATUS); + uint64_t readout; + + try { + readout = ReadMSR(0, MSR_RAPL::PKG::ENERGY_STATUS); + } + catch(MSR_Read_Exception){ + return {}; + } + double value = energy_units_ * readout; // TODO add more metrics @@ -35,26 +49,46 @@ std::vector RaplCollector::Collect() { return {m}; } -uint64_t RaplCollector::ReadMSR(uint32_t offset) { - // TODO support other cores - int fd = OpenMSR(0); - +uint64_t RaplCollector::ReadMSR(uint8_t core, uint32_t offset) { uint64_t data; + if(core > MSR_files_.size()){ + throw MSR_Read_Exception(); + } // c-like read for thread safety - if (pread(fd, &data, sizeof data, offset) != sizeof data) { + if (pread(MSR_files_[core], &data, sizeof data, offset) != sizeof data) { return {}; } - CloseMSR(fd); return data; } -int RaplCollector::OpenMSR(uint8_t core) { - std::string path = "/dev/cpu/" + std::to_string(core) + "/msr"; - return open(path.c_str(), O_RDONLY); +void RaplCollector::OpenMSR() { + const std::filesystem::path cpu_base = "/dev/cpu"; + MSR_files_ = std::vector(); + std::error_code ec; + if (!std::filesystem::exists(cpu_base, ec)) { + throw MSR_Open_Exception(); + } + for (const auto& entry : std::filesystem::directory_iterator(cpu_base)) { + if (!entry.is_directory()) continue; + + const auto& dirname = entry.path().filename().string(); + if (!std::ranges::all_of(dirname, ::isdigit)) continue; + + int fd = open((entry.path() / "msr").c_str(), O_RDONLY); + if (fd >= 0) { + MSR_files_.push_back(fd); + } + } } + void RaplCollector::CloseMSR(int fd) { close(fd); } +RaplCollector::~RaplCollector(){ + for(auto file : MSR_files_){ + CloseMSR(file); + } +}; } // namespace collectors } // namespace agent } // namespace volta diff --git a/source/agent/src/collectors/rapl_collector.h b/source/agent/src/collectors/rapl_collector.h index 58123e4..395bfa2 100644 --- a/source/agent/src/collectors/rapl_collector.h +++ b/source/agent/src/collectors/rapl_collector.h @@ -13,15 +13,19 @@ class RaplCollector : public Collector { // ~RaplCollector() override; std::vector Collect() override; - + ~RaplCollector(); private: - uint64_t ReadMSR(uint32_t offset); - int OpenMSR(uint8_t core); + uint64_t ReadMSR(uint8_t core, uint32_t offset); + void OpenMSR(); void CloseMSR(int fd); bool initialized_ = false; double power_units_, energy_units_, time_units_; - + std::vector MSR_files_; double last_value; + + class MSR_Read_Exception : std::exception {}; + class MSR_Open_Exception : std::exception {}; + struct MSR_RAPL { static constexpr uint32_t POWER_UNIT = 0x606; struct Units { From 0094bcec07eb32e6e437167f6d0f53ab14fe5429 Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 8 Apr 2026 16:01:21 +0200 Subject: [PATCH 4/9] fix: MSR read exception condition --- .gitignore | 5 ++ source/agent/src/collectors/rapl_collector.cc | 58 +++++++++---------- vcpkg.json | 11 ++++ 3 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 vcpkg.json diff --git a/.gitignore b/.gitignore index fc39ba5..97ce92c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ build/ bin/ .cache/ + +CMakeFiles/ +CMakeCache.txt + +vcpkg_installed/ diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc index 0fecffd..7e1829b 100644 --- a/source/agent/src/collectors/rapl_collector.cc +++ b/source/agent/src/collectors/rapl_collector.cc @@ -1,9 +1,9 @@ #include "rapl_collector.h" +#include #include -#include #include -#include +#include #include #include @@ -13,11 +13,7 @@ namespace agent { namespace collectors { RaplCollector::RaplCollector() { - try { - OpenMSR(); - }catch(std::exception e){ - throw e; - } + OpenMSR(); uint64_t readout = ReadMSR(0, MSR_RAPL::POWER_UNIT); power_units_ = pow(0.5, (double)(readout & 0xf)); energy_units_ = pow(0.5, (double)((readout >> 8) & 0x1f)); @@ -31,14 +27,12 @@ std::vector RaplCollector::Collect() { try { readout = ReadMSR(0, MSR_RAPL::PKG::ENERGY_STATUS); - } - catch(MSR_Read_Exception){ + } catch (MSR_Read_Exception) { return {}; } double value = energy_units_ * readout; - // TODO add more metrics Metric m; m.name = "cpu_energy_usage_total"; m.value = value - last_value; @@ -51,7 +45,7 @@ std::vector RaplCollector::Collect() { uint64_t RaplCollector::ReadMSR(uint8_t core, uint32_t offset) { uint64_t data; - if(core > MSR_files_.size()){ + if (core + 1 > MSR_files_.size()) { throw MSR_Read_Exception(); } // c-like read for thread safety @@ -63,32 +57,36 @@ uint64_t RaplCollector::ReadMSR(uint8_t core, uint32_t offset) { } void RaplCollector::OpenMSR() { - const std::filesystem::path cpu_base = "/dev/cpu"; - MSR_files_ = std::vector(); - std::error_code ec; - if (!std::filesystem::exists(cpu_base, ec)) { - throw MSR_Open_Exception(); - } - for (const auto& entry : std::filesystem::directory_iterator(cpu_base)) { - if (!entry.is_directory()) continue; + const std::filesystem::path cpu_base = "/dev/cpu"; + MSR_files_ = std::vector(); + std::error_code ec; + + if (!std::filesystem::exists(cpu_base, ec)) { + throw MSR_Open_Exception(); + } + + for (const auto &entry : std::filesystem::directory_iterator(cpu_base)) { + if (!entry.is_directory()) + continue; - const auto& dirname = entry.path().filename().string(); - if (!std::ranges::all_of(dirname, ::isdigit)) continue; + const auto &dirname = entry.path().filename().string(); + if (!std::ranges::all_of(dirname, ::isdigit)) + continue; - int fd = open((entry.path() / "msr").c_str(), O_RDONLY); - if (fd >= 0) { - MSR_files_.push_back(fd); - } + int fd = open((entry.path() / "msr").c_str(), O_RDONLY); + if (fd >= 0) { + MSR_files_.push_back(fd); } + } } void RaplCollector::CloseMSR(int fd) { close(fd); } -RaplCollector::~RaplCollector(){ - for(auto file : MSR_files_){ +RaplCollector::~RaplCollector() { + for (auto file : MSR_files_) { CloseMSR(file); } }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..f7b4c46 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,11 @@ +{ + "name": "volta-agent", + "version-string": "0.1.0", + "builtin-baseline": "6d7bf7ef2193e2d1c5798a5ff8811d533104c861", + "dependencies": [ + "fmt", + "grpc", + "protobuf", + "tomlplusplus" + ] +} From 6c6bd220da3481a515c86e33084115b0597906e8 Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 8 Apr 2026 16:15:40 +0200 Subject: [PATCH 5/9] fix: formatting --- source/agent/src/collectors/rapl_collector.cc | 16 +++++++--------- source/agent/src/collectors/rapl_collector.h | 1 + source/agent/src/scheduler.cc | 6 ++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc index 7e1829b..2528f0a 100644 --- a/source/agent/src/collectors/rapl_collector.cc +++ b/source/agent/src/collectors/rapl_collector.cc @@ -1,12 +1,12 @@ #include "rapl_collector.h" -#include #include -#include #include +#include #include #include +#include namespace volta { namespace agent { @@ -66,12 +66,10 @@ void RaplCollector::OpenMSR() { } for (const auto &entry : std::filesystem::directory_iterator(cpu_base)) { - if (!entry.is_directory()) - continue; + if (!entry.is_directory()) continue; const auto &dirname = entry.path().filename().string(); - if (!std::ranges::all_of(dirname, ::isdigit)) - continue; + if (!std::ranges::all_of(dirname, ::isdigit)) continue; int fd = open((entry.path() / "msr").c_str(), O_RDONLY); if (fd >= 0) { @@ -87,6 +85,6 @@ RaplCollector::~RaplCollector() { CloseMSR(file); } }; -} // namespace collectors -} // namespace agent -} // namespace volta +} // namespace collectors +} // namespace agent +} // namespace volta diff --git a/source/agent/src/collectors/rapl_collector.h b/source/agent/src/collectors/rapl_collector.h index 395bfa2..9b9c09c 100644 --- a/source/agent/src/collectors/rapl_collector.h +++ b/source/agent/src/collectors/rapl_collector.h @@ -14,6 +14,7 @@ class RaplCollector : public Collector { std::vector Collect() override; ~RaplCollector(); + private: uint64_t ReadMSR(uint8_t core, uint32_t offset); void OpenMSR(); diff --git a/source/agent/src/scheduler.cc b/source/agent/src/scheduler.cc index d6c806a..ecb7c07 100644 --- a/source/agent/src/scheduler.cc +++ b/source/agent/src/scheduler.cc @@ -39,7 +39,8 @@ void Scheduler::PrintDashboard(const std::vector& metrics) { std::cout << " VOLTA AGENT v0.1 (POC) - ACTIVE MONITOR \n"; std::cout << "===============================================\n"; - std::cout << std::left << std::setw(30) << "METRIC NAME" << "VALUE\n"; + std::cout << std::left << std::setw(30) << "METRIC NAME" + << "VALUE\n"; std::cout << "-----------------------------------------------\n"; for (const auto& m : metrics) { @@ -49,7 +50,8 @@ void Scheduler::PrintDashboard(const std::vector& metrics) { std::cout << "-----------------------------------------------\n"; std::cout << "Data points collected: " << metrics.size() << "\n"; - std::cout << "Press Ctrl+C to exit." << "\n"; + std::cout << "Press Ctrl+C to exit." + << "\n"; std::cout.flush(); } From 5f7dd0827a5136fcf1f90fcb2c24729ffde9117e Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 8 Apr 2026 16:21:52 +0200 Subject: [PATCH 6/9] fix: formating 2 --- source/agent/src/scheduler.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/agent/src/scheduler.cc b/source/agent/src/scheduler.cc index ecb7c07..9b18c56 100644 --- a/source/agent/src/scheduler.cc +++ b/source/agent/src/scheduler.cc @@ -50,8 +50,7 @@ void Scheduler::PrintDashboard(const std::vector& metrics) { std::cout << "-----------------------------------------------\n"; std::cout << "Data points collected: " << metrics.size() << "\n"; - std::cout << "Press Ctrl+C to exit." - << "\n"; + std::cout << "Press Ctrl+C to exit." << "\n"; std::cout.flush(); } From cc1514d4d2d855b719abb3d8aa2f192322b51392 Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 8 Apr 2026 16:23:15 +0200 Subject: [PATCH 7/9] fix: formatting pls work --- source/agent/src/scheduler.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/agent/src/scheduler.cc b/source/agent/src/scheduler.cc index 9b18c56..d6c806a 100644 --- a/source/agent/src/scheduler.cc +++ b/source/agent/src/scheduler.cc @@ -39,8 +39,7 @@ void Scheduler::PrintDashboard(const std::vector& metrics) { std::cout << " VOLTA AGENT v0.1 (POC) - ACTIVE MONITOR \n"; std::cout << "===============================================\n"; - std::cout << std::left << std::setw(30) << "METRIC NAME" - << "VALUE\n"; + std::cout << std::left << std::setw(30) << "METRIC NAME" << "VALUE\n"; std::cout << "-----------------------------------------------\n"; for (const auto& m : metrics) { From 9c51bc0e16571265291a17a08ae98481cb64bfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Woli=C5=84ski-Nag=C3=B3rko?= <77678355+szlachta99@users.noreply.github.com> Date: Fri, 10 Apr 2026 23:35:53 +0200 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Kacper Doga --- source/agent/src/collectors/rapl_collector.cc | 2 +- source/agent/src/collectors/rapl_collector.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc index 2528f0a..144a07f 100644 --- a/source/agent/src/collectors/rapl_collector.cc +++ b/source/agent/src/collectors/rapl_collector.cc @@ -27,7 +27,7 @@ std::vector RaplCollector::Collect() { try { readout = ReadMSR(0, MSR_RAPL::PKG::ENERGY_STATUS); - } catch (MSR_Read_Exception) { + } catch (const MSR_Read_Exception& e) { return {}; } diff --git a/source/agent/src/collectors/rapl_collector.h b/source/agent/src/collectors/rapl_collector.h index 9b9c09c..8da12ff 100644 --- a/source/agent/src/collectors/rapl_collector.h +++ b/source/agent/src/collectors/rapl_collector.h @@ -11,7 +11,8 @@ class RaplCollector : public Collector { public: RaplCollector(); // ~RaplCollector() override; - +RaplCollector(const RaplCollector&) = delete; +RaplCollector& operator=(const RaplCollector&) = delete; std::vector Collect() override; ~RaplCollector(); From 9670153f1b71a6d02e975de2c5456f621a9bfc4b Mon Sep 17 00:00:00 2001 From: Filip Date: Fri, 10 Apr 2026 23:59:26 +0200 Subject: [PATCH 9/9] fix: core ordering --- source/agent/src/collectors/rapl_collector.cc | 12 ++++++++---- source/agent/src/collectors/rapl_collector.h | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/agent/src/collectors/rapl_collector.cc b/source/agent/src/collectors/rapl_collector.cc index 144a07f..6616659 100644 --- a/source/agent/src/collectors/rapl_collector.cc +++ b/source/agent/src/collectors/rapl_collector.cc @@ -27,7 +27,7 @@ std::vector RaplCollector::Collect() { try { readout = ReadMSR(0, MSR_RAPL::PKG::ENERGY_STATUS); - } catch (const MSR_Read_Exception& e) { + } catch (const MSR_Read_Exception &e) { return {}; } @@ -64,14 +64,18 @@ void RaplCollector::OpenMSR() { if (!std::filesystem::exists(cpu_base, ec)) { throw MSR_Open_Exception(); } - + std::vector> cpu_entries; for (const auto &entry : std::filesystem::directory_iterator(cpu_base)) { if (!entry.is_directory()) continue; - const auto &dirname = entry.path().filename().string(); if (!std::ranges::all_of(dirname, ::isdigit)) continue; + cpu_entries.emplace_back(std::stoi(dirname), entry.path()); + } + + std::ranges::sort(cpu_entries); - int fd = open((entry.path() / "msr").c_str(), O_RDONLY); + for (const auto &[id, path] : cpu_entries) { + int fd = open((path / "msr").c_str(), O_RDONLY); if (fd >= 0) { MSR_files_.push_back(fd); } diff --git a/source/agent/src/collectors/rapl_collector.h b/source/agent/src/collectors/rapl_collector.h index 8da12ff..4696516 100644 --- a/source/agent/src/collectors/rapl_collector.h +++ b/source/agent/src/collectors/rapl_collector.h @@ -11,8 +11,8 @@ class RaplCollector : public Collector { public: RaplCollector(); // ~RaplCollector() override; -RaplCollector(const RaplCollector&) = delete; -RaplCollector& operator=(const RaplCollector&) = delete; + RaplCollector(const RaplCollector&) = delete; + RaplCollector& operator=(const RaplCollector&) = delete; std::vector Collect() override; ~RaplCollector();