public inbox for linux-trace-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] trace-cmd report: keep a separator before long timestamps
@ 2026-04-06  7:03 CaoRuichuang
  0 siblings, 0 replies; 2+ messages in thread
From: CaoRuichuang @ 2026-04-06  7:03 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt, Tzvetomir Stoyanov

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)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] trace-cmd report: keep a separator before long timestamps
@ 2026-04-06  7:32 CaoRuichuang
  0 siblings, 0 replies; 2+ messages in thread
From: CaoRuichuang @ 2026-04-06  7:32 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt, tz.stoyanov

A quick follow-up on validation for this patch.

The one remaining "Simple reset" utest failure I mentioned came from
running in the VM against Ubuntu's libtracefs 1.8.0.

Re-running the same trace-cmd utests with upstream libtracefs 1.8.3
makes that test pass as well, and the full trace-cmd utest run becomes
9/9 passed.

So there is no patch change here. This is only a validation note that
the unrelated remaining failure was due to the older libtracefs in the
VM environment.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-06  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-06  7:03 [PATCH] trace-cmd report: keep a separator before long timestamps CaoRuichuang
  -- strict thread matches above, loose matches on Subject: below --
2026-04-06  7:32 CaoRuichuang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox