From d3fcd3415c60995784dbedda8e92d0f880a871b8 Mon Sep 17 00:00:00 2001
From: Steven Rostedt <rostedt@goodmis.org>
Date: Wed, 27 Dec 2023 11:37:43 +0800
Subject: [PATCH] trace-cmd record: Fix -m option

The -m option limits the size of each per-cpu buffer to the value
specified in kbs (or actually pages). That is, if -m 1000 is specified,
then the size per cpu buffer should not be more that 1000 kbs. Since it is
implemented in halfs, it is usually between half and the full amount.

But since the buffer reads can use pipes, the increment of the page count
needs to take that into consideration. Currently, it just increments the
page count every time the count goes over the page size. But due to pipes,
the size increment can be multiple pages (65k in fact), and this distorts
the size.

Have the page count increment via the actually size read and not just by
one even if several pages were read at one go.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

---
 trace-recorder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/trace-recorder.c b/trace-recorder.c
index c811028..d133d9a 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -323,8 +323,8 @@ static inline void update_fd(struct tracecmd_recorder *recorder, int size)
 	recorder->count += size;
 
 	if (recorder->count >= recorder->page_size) {
+		recorder->pages += recorder->count / recorder->page_size;
 		recorder->count = 0;
-		recorder->pages++;
 	}
 
 	if (recorder->pages < recorder->max)
-- 
2.37.0.windows.1

