This solves a minor issue with our legacy benchmark tools. (#1653)

* This solves a minor issue with our legacy benchmark tools.

* Slightly better code.

* Removing bad typo.
This commit is contained in:
Daniel Lemire 2021-07-13 09:18:58 -04:00 committed by GitHub
parent ea3d4e7ce5
commit b085b56e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -76,6 +76,7 @@
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp",
"*.ipp": "cpp"
"*.ipp": "cpp",
"*.tcc": "cpp"
}
}

View File

@ -29,6 +29,7 @@ template <int TYPE = PERF_TYPE_HARDWARE> class LinuxEvents {
size_t num_events{};
std::vector<uint64_t> temp_result_vec{};
std::vector<uint64_t> result{};
std::vector<int> fds{};
bool quiet;
public:
@ -52,10 +53,12 @@ public:
uint32_t i = 0;
for (auto config : config_vec) {
attribs.config = config;
fd = static_cast<int>(syscall(__NR_perf_event_open, &attribs, pid, cpu, group, flags));
if (fd == -1) {
int _fd = static_cast<int>(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) {