diff --git a/.vscode/settings.json b/.vscode/settings.json index ecd20c5b..342714d2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -76,6 +76,7 @@ "unordered_map": "cpp", "utility": "cpp", "vector": "cpp", - "*.ipp": "cpp" + "*.ipp": "cpp", + "*.tcc": "cpp" } } \ No newline at end of file diff --git a/benchmark/linux/linux-perf-events.h b/benchmark/linux/linux-perf-events.h index e0f3bb3f..47355adb 100644 --- a/benchmark/linux/linux-perf-events.h +++ b/benchmark/linux/linux-perf-events.h @@ -29,6 +29,7 @@ template class LinuxEvents { size_t num_events{}; std::vector temp_result_vec{}; std::vector result{}; + std::vector fds{}; bool quiet; public: @@ -52,10 +53,12 @@ public: uint32_t i = 0; for (auto config : config_vec) { attribs.config = config; - fd = static_cast(syscall(__NR_perf_event_open, &attribs, pid, cpu, group, flags)); - if (fd == -1) { + int _fd = static_cast(syscall(__NR_perf_event_open, &attribs, pid, cpu, group, flags)); + if (_fd == -1) { report_error("perf_event_open"); } + fd = _fd; // fd tracks the last _fd value. + fds.push_back(fd); ioctl(fd, PERF_EVENT_IOC_ID, &result[i++]); if (group == -1) { group = fd; @@ -65,7 +68,11 @@ public: temp_result_vec.resize(num_events * 2 + 1); } - ~LinuxEvents() { if (fd != -1) { close(fd); } } + ~LinuxEvents() { + for (auto tfd : fds) { + if (tfd != -1) { close(tfd); } + } + } inline void start() { if (fd != -1) {