From adde7a57e9c3ead0c4dbe7f97999751943fcccbc Mon Sep 17 00:00:00 2001 From: Jaya Prakash Date: Fri, 17 Oct 2025 12:22:45 +0000 Subject: [PATCH] common: use constexpr buffer size instead of fixed 256 for read_format in cputrace Signed-off-by: Jaya Prakash --- src/common/cputrace.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/cputrace.cc b/src/common/cputrace.cc index ed4d11a96e39..fcbbeb8feb07 100644 --- a/src/common/cputrace.cc +++ b/src/common/cputrace.cc @@ -47,7 +47,7 @@ int register_anchor(const char* name) { struct read_format { uint64_t nr; - struct { + struct values { uint64_t value; uint64_t id; } values[]; @@ -171,7 +171,11 @@ void HW_read(HW_ctx* ctx, sample_t* measure) { if (ctx->parent_fd == -1) { return; } - char buf[256]; + static constexpr uint64_t MAX_COUNTERS = 5; + static constexpr size_t BUFFER_SIZE = + sizeof(read_format) + MAX_COUNTERS * sizeof(struct read_format::values); + char buf[BUFFER_SIZE]; + struct read_format* rf = (struct read_format*)buf; if (read(ctx->parent_fd, buf, sizeof(buf)) > 0) { for (uint64_t i = 0; i < rf->nr; i++) { -- 2.47.3