From: CaoRuichuang <create0818@163.com>
To: linux-trace-devel@vger.kernel.org
Cc: Steven Rostedt <rostedt@goodmis.org>,
Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Subject: [PATCH] trace-cmd report: keep a separator before long timestamps
Date: Mon, 6 Apr 2026 15:03:44 +0800 [thread overview]
Message-ID: <20260406070344.64152-1-create0818@163.com> (raw)
trace-cmd report formats normal nanosecond timestamps with "%12d:".
That relies on the field width to provide the separator before the
timestamp.
With --raw-ts and a large --ts-offset, the timestamp can grow beyond
12 digits. Once that happens, the padding disappears and the output
runs into the raw flags field, producing lines such as:
[003] dNh2.749686305812356:
Make the normal timestamp format include an explicit leading space so
the separator remains present regardless of the timestamp width.
Add a unit test that exercises report --raw-ts with a large timestamp
offset and checks both the fixed and the broken output forms.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221303
Signed-off-by: CaoRuichuang <create0818@163.com>
---
tracecmd/trace-read.c | 2 +-
utest/tracecmd-utest.c | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index 355ee0f4..aef9b4c5 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -170,7 +170,7 @@ static const char *time_format(struct tracecmd_input *handle, enum time_fmt tf)
else
return tf == TIME_FMT_NORMAL ? " %6.1000d:" : "%6.1000d";
} else
- return tf == TIME_FMT_NORMAL ? "%12d:" : "%12d";
+ return tf == TIME_FMT_NORMAL ? " %12d:" : "%12d";
}
}
diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c
index c18fb2ea..cc487d13 100644
--- a/utest/tracecmd-utest.c
+++ b/utest/tracecmd-utest.c
@@ -445,6 +445,28 @@ static void test_trace_convert6(void)
CU_TEST(ret == 0);
}
+static void test_trace_report_long_timestamp_separator(void)
+{
+ struct stat st;
+ int ret;
+
+ /* If the trace data is already created, just use it, otherwise make it again */
+ if (stat(TRACECMD_FILE, &st) < 0) {
+ ret = run_trace("record", TRACECMD_OUT, "-e", "sched", "sleep", "1", NULL);
+ CU_TEST(ret == 0);
+ }
+
+ ret = grep_match("\\[[0-9][0-9][0-9]\\] [^ ]*\\. [0-9]\\{12,\\}:",
+ "report", TRACECMD_IN, "--raw-ts",
+ "--ts-offset", "100000000000000", NULL);
+ CU_TEST(ret == 0);
+
+ ret = grep_match("\\[[0-9][0-9][0-9]\\] [^ ]*\\.[0-9]\\{12,\\}:",
+ "report", TRACECMD_IN, "--raw-ts",
+ "--ts-offset", "100000000000000", NULL);
+ CU_TEST(ret == 1);
+}
+
struct callback_data {
long counter;
struct trace_seq seq;
@@ -798,6 +820,8 @@ void test_tracecmd_lib(void)
test_trace_sqlhist_hist);
CU_add_test(suite, "Test convert from v7 to v6",
test_trace_convert6);
+ CU_add_test(suite, "Keep separator before long timestamps",
+ test_trace_report_long_timestamp_separator);
CU_add_test(suite, "Use libraries to read file",
test_trace_library_read);
CU_add_test(suite, "Use libraries to read file incremental",
--
2.39.5 (Apple Git-154)
next reply other threads:[~2026-04-06 7:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 7:03 CaoRuichuang [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-06 7:32 [PATCH] trace-cmd report: keep a separator before long timestamps CaoRuichuang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260406070344.64152-1-create0818@163.com \
--to=create0818@163.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tz.stoyanov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox