[PATCH] blkparse: add the -n option to output original IO event information.

[email protected] Thu, 12 Jun 2025 15:24:03 +0800
Newsgroups org.kernel.vger.linux-btrace
Message-ID <[email protected]>
From: Kou Wenqi <[email protected]>

commit e81829a56516 fixes the sector and length of split completions
to match the original request.
However, the original IO event information is also required.
Add the -n option to blkparse to output original IO event information.

Signed-off-by: Kou Wenqi <[email protected]>
---
 blkparse.c       | 17 ++++++++++++++++-
 doc/blkparse.1   |  7 +++++++
 doc/blktrace.tex |  2 ++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/blkparse.c b/blkparse.c
index d6aaa8b..4af6d1d 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -180,6 +180,12 @@ static struct option l_opts[] = {
 		.flag = NULL,
 		.val = 'M'
 	},
+	{
+		.name = "do-not-fix-up-for-split-completions",
+		.has_arg = no_argument,
+		.flag = NULL,
+		.val = 'n'
+	},
 	{
 		.name = "output",
 		.has_arg = required_argument,
@@ -326,6 +332,8 @@ static unsigned long long start_timestamp;
 
 static int have_drv_data = 0;
 
+static int do_not_fix_up_for_split_completions = 0;
+
 #define JHASH_RANDOM	(0x3af5f2ee)
 
 #define CPUS_PER_LONG	(8 * sizeof(unsigned long))
@@ -1099,6 +1107,8 @@ static void log_track_queue(struct per_dev_info *pdi, struct blk_io_trace *t)
 static void log_track_split(struct per_dev_info *pdi, struct blk_io_trace *t)
 {
 	struct io_track *iot, *split;
+	if (do_not_fix_up_for_split_completions)
+		return;
 
 	/*
 	 * With a split request, the completion event will refer to the last
@@ -2991,7 +3001,7 @@ static int get_program_sort_event(const char *str)
 	return 0;
 }
 
-#define S_OPTS  "a:A:b:D:d:f:F:hi:o:OqsS:tw:vVM"
+#define S_OPTS  "a:A:b:D:d:f:F:hi:no:OqsS:tw:vVM"
 static char usage_str[] =    "\n\n" \
 	"-i <file>           | --input=<file>\n" \
 	"[ -a <action field> | --act-mask=<action field> ]\n" \
@@ -3002,6 +3012,7 @@ static char usage_str[] =    "\n\n" \
 	"[ -f <format>       | --format=<format> ]\n" \
 	"[ -F <spec>         | --format-spec=<spec> ]\n" \
 	"[ -h                | --hash-by-name ]\n" \
+	"[ -n                | --do-not-fix-up-for-split-completions ]\n" \
 	"[ -o <file>         | --output=<file> ]\n" \
 	"[ -O                | --no-text-output ]\n" \
 	"[ -q                | --quiet ]\n" \
@@ -3022,6 +3033,7 @@ static char usage_str[] =    "\n\n" \
 	"\t-F Format specification. Can be found in the documentation\n" \
 	"\t-h Hash processes by name, not pid\n" \
 	"\t-i Input file containing trace data, or '-' for stdin\n" \
+	"\t-n Do not fix up the sector and length for split completions\n" \
 	"\t-o Output file. If not given, output is stdout\n" \
 	"\t-O Do NOT output text data\n" \
 	"\t-q Quiet. Don't display any stats at the end of the trace\n" \
@@ -3083,6 +3095,9 @@ int main(int argc, char *argv[])
 		case 'D':
 			input_dir = optarg;
 			break;
+		case 'n':
+			do_not_fix_up_for_split_completions = 1;
+			break;
 		case 'o':
 			output_name = optarg;
 			break;
diff --git a/doc/blkparse.1 b/doc/blkparse.1
index 93aa449..fc88c51 100644
--- a/doc/blkparse.1
+++ b/doc/blkparse.1
@@ -130,6 +130,13 @@ the CFQ I/O scheduler.)
 Hash processes by name, not by PID
 .RE
 
+\-n
+.br
+\-\-do\-not\-fix\-up\-for\-split\-completions
+.RS
+Do not fix up the sector and length for split completions
+.RE
+
 \-o \fIfile\fR
 .br
 \-\-output=\fIfile\fR
diff --git a/doc/blktrace.tex b/doc/blktrace.tex
index d747de7..504355c 100644
--- a/doc/blktrace.tex
+++ b/doc/blktrace.tex
@@ -493,6 +493,8 @@ Short              & Long                       & Description \\ \hline\hline
 
 -h                 & --hash-by-name             & Hash processes by name, not by PID\\ \hline
 
+-n                 & --do-not-fix-up-for-split-completions  & Do not fix up the sector and length for split completions\\ \hline
+
 -o \emph{file}     & --output=\emph{file}       & Output file \\ \hline
 -O                 & --no-text-output           & Do \emph{not} produce text output, used for binary (-d) only \\ \hline
 
-- 
2.43.0