From 6b043c0231286ec75d4b113face0dd8ddcd0feaa Mon Sep 17 00:00:00 2001 From: Pierre Pebay Date: Mon, 25 Nov 2024 17:41:11 +0100 Subject: [PATCH] #2302: Fix warnings --- cmake/load_papi.cmake | 2 +- cmake/load_perf.cmake | 2 +- src/vt/metrics/perf_data.cc | 25 ++++++++++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cmake/load_papi.cmake b/cmake/load_papi.cmake index d1719200a0..dee7f778d2 100644 --- a/cmake/load_papi.cmake +++ b/cmake/load_papi.cmake @@ -9,4 +9,4 @@ if (vt_papi_enabled) find_package(PAPI REQUIRED) message(STATUS: "FOUND PAPI: PAPI LIBRARY: ${PAPI_LIBRARY}\n PAPI INCLUDE DIR: ${PAPI_INCLUDE_DIR}") set(vt_papi_found "1") -endif () \ No newline at end of file +endif () diff --git a/cmake/load_perf.cmake b/cmake/load_perf.cmake index 5dc194b69a..b1f850ba09 100644 --- a/cmake/load_perf.cmake +++ b/cmake/load_perf.cmake @@ -45,4 +45,4 @@ if (vt_perf_enabled) set(vt_perf_enabled "0") set(vt_perf_found "0") endif () -endif () \ No newline at end of file +endif () diff --git a/src/vt/metrics/perf_data.cc b/src/vt/metrics/perf_data.cc index 53ba16c5cb..c0825d3f4d 100644 --- a/src/vt/metrics/perf_data.cc +++ b/src/vt/metrics/perf_data.cc @@ -135,27 +135,34 @@ void PerfData::stopTaskMeasurement() } } -std::unordered_map PerfData::getTaskMeasurements() -{ +std::unordered_map PerfData::getTaskMeasurements() { std::unordered_map measurements; - for (size_t i = 0; i < event_fds_.size(); ++i) - { + + if (event_fds_.size() != event_names_.size()) { + vtAbort("Mismatch between event_fds_ and event_names_ sizes."); + } + + for (size_t i = 0; i < event_fds_.size(); ++i) { uint64_t count = 0; + if (event_fds_[i] != -1) { ssize_t bytesRead = read(event_fds_[i], &count, sizeof(uint64_t)); + if (bytesRead == sizeof(uint64_t)) { measurements[event_names_[i]] = count; } else if (bytesRead == -1) { - vtAbort("Failed to read perf event data for: " + event_names_[i] + ". Error: " + std::strerror(errno)); + vtAbort("Failed to read perf event data for: " + event_names_[i] + + ". Error: " + std::strerror(errno)); } else { - vtAbort("Incomplete read for: " + event_names_[i] + ". Expected " + std::to_string(sizeof(uint64_t)) + - " bytes, but got " + std::to_string(bytesRead)); + vtAbort("Incomplete read for: " + event_names_[i] + + ". Expected " + std::to_string(sizeof(uint64_t)) + + " bytes, but got " + std::to_string(bytesRead)); } - } - else { + } else { vtAbort("Invalid file descriptor for: " + event_names_[i]); } } + return measurements; }