Skip to content

Commit adde7a5

Browse files
common: use constexpr buffer size instead of fixed 256 for read_format in cputrace
Signed-off-by: Jaya Prakash <[email protected]>
1 parent 8267213 commit adde7a5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/common/cputrace.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int register_anchor(const char* name) {
4747

4848
struct read_format {
4949
uint64_t nr;
50-
struct {
50+
struct values {
5151
uint64_t value;
5252
uint64_t id;
5353
} values[];
@@ -171,7 +171,11 @@ void HW_read(HW_ctx* ctx, sample_t* measure) {
171171
if (ctx->parent_fd == -1) {
172172
return;
173173
}
174-
char buf[256];
174+
static constexpr uint64_t MAX_COUNTERS = 5;
175+
static constexpr size_t BUFFER_SIZE =
176+
sizeof(read_format) + MAX_COUNTERS * sizeof(struct read_format::values);
177+
char buf[BUFFER_SIZE];
178+
175179
struct read_format* rf = (struct read_format*)buf;
176180
if (read(ctx->parent_fd, buf, sizeof(buf)) > 0) {
177181
for (uint64_t i = 0; i < rf->nr; i++) {

0 commit comments

Comments
 (0)