diff options
-rw-r--r-- | perf.hpp | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -22,8 +22,8 @@ * SOFTWARE. **/ -#ifndef LIBPERF_H -#define LIBPERF_H +#ifndef LIBPERF_HPP +#define LIBPERF_HPP #include <asm/unistd.h> #include <asm/unistd_64.h> @@ -59,6 +59,7 @@ static inline void ioctl(int fd, unsigned long rqst, unsigned long arg) { assert(ret == 0); } +// Checked read(2) syscall. template <typename T> static inline void read(int fd, T& buf) { ssize_t ret = ::read(fd, &buf, sizeof(buf)); @@ -103,7 +104,7 @@ private: }; struct pmc { - pmc_desc def; + pmc_desc desc; int fd; read_fmt last_value; }; @@ -194,8 +195,9 @@ inline void perf_group::stop() { inline void perf_group::dump() const { auto correct = [](const read_fmt& data) -> uint64_t { - if (data.value == 0) + if (data.value == 0) { return 0ul; + } // Correction of error due pmc multiplexing (simple approximation, assuming // linear increment). @@ -207,7 +209,7 @@ inline void perf_group::dump() const { for (auto& pmc : pmcs_) { auto value = mode_ == RUN_GROUP ? correct(pmc.last_value) : pmc.last_value.value; - std::printf("%-10s: %12ld | E=%ld R=%ld\n", pmc.def.name, value, + std::printf("%-10s: %12ld | E=%ld R=%ld\n", pmc.desc.name, value, pmc.last_value.time_enabled, pmc.last_value.time_running); } @@ -222,7 +224,7 @@ inline void perf_group::dump() const { inline const perf_group::read_fmt* perf_group::find(uint64_t type, uint64_t config) const { for (auto& pmc : pmcs_) { - if (pmc.def.type == type && pmc.def.config == config) { + if (pmc.desc.type == type && pmc.desc.config == config) { return &pmc.last_value; } } |