[PATCH] btt: eliminate redundant separators in btt -p display

[email protected] Wed, 9 Apr 2025 17:39:30 +0800
Newsgroups org.kernel.vger.linux-btrace
Message-ID <[email protected]>
From: Kou Wenqi <[email protected]>

8,0    1        1     0.000000000  5315  Q  WS 0 + 375 [dd]
8,0    1        2     0.000005314  5315  X  WS 0 / 128 [dd]
8,0    1        3     0.000012623  5315  G  WS 0 + 128 [dd]
8,0    1        4     0.000030582  5315  I  WS 0 + 128 [dd]
8,0    1        5     0.000046089  5315  X  WS 128 / 256 [dd]
8,0    1        6     0.000047072  5315  G  WS 128 + 128 [dd]
8,0    1        7     0.000047513  5315  I  WS 128 + 128 [dd]
8,0    1        8     0.000051336  5315  G  WS 256 + 119 [dd]
8,0    1        9     0.000051562  5315  I  WS 256 + 119 [dd]
8,0    1       10     0.000079209   109  D  WS 0 + 128 [kworker/1:1H]
8,0    1       11     0.000308966   109  D  WS 128 + 128 [kworker/1:1H]
8,0    1       12     0.000467117   109  D  WS 256 + 119 [kworker/1:1H]
8,0    2        1     0.000596478     0  C  WS 0 + 128 [0]
8,0    2        2     0.000616049     0  C  WS 0 + 256 [0]
8,0    2        3     0.000618701     0  C  WS 0 + 375 [0]
8,0    1       13     0.000909790  5315  Q  WS 375 + 375 [dd]
8,0    1       14     0.000913783  5315  X  WS 375 / 503 [dd]
8,0    1       15     0.000918960  5315  G  WS 375 + 128 [dd]
8,0    1       16     0.000933605  5315  I  WS 375 + 128 [dd]
8,0    1       17     0.000945282  5315  X  WS 503 / 631 [dd]
8,0    1       18     0.000946635  5315  G  WS 503 + 128 [dd]
8,0    1       19     0.000947169  5315  I  WS 503 + 128 [dd]
8,0    1       20     0.000950159  5315  G  WS 631 + 119 [dd]
8,0    1       21     0.000950570  5315  I  WS 631 + 119 [dd]
8,0    1       22     0.000973481   109  D  WS 375 + 128 [kworker/1:1H]
8,0    1       23     0.001133980   109  D  WS 503 + 128 [kworker/1:1H]
8,0    1       24     0.001228540   109  D  WS 631 + 119 [kworker/1:1H]
8,0    2        4     0.001377897     0  C  WS 375 + 128 [0]
8,0    2        5     0.001385818     0  C  WS 375 + 256 [0]
8,0    2        6     0.001389308     0  C  WS 375 + 375 [0]

Before this patch, the output of btt -p is as follows:
-----------------------------------------
-----------------------------------------
  8,0  :     0.000000000 Q          0+375
             0.000012623 G          0+375
             0.000030582 I          0+375
             0.000618701 C          0+375

-----------------------------------------
-----------------------------------------
-----------------------------------------
  8,0  :     0.000909790 Q        375+375
             0.000918960 G        375+375
             0.000933605 I        375+375
             0.001389308 C        375+375

-----------------------------------------

After this patch, the output of btt -p is as follows:
  8,0  :     0.000000000 Q          0+375
             0.000012623 G          0+375
             0.000030582 I          0+375
             0.000618701 C          0+375

-----------------------------------------
  8,0  :     0.000909790 Q        375+375
             0.000918960 G        375+375
             0.000933605 I        375+375
             0.001389308 C        375+375

-----------------------------------------

Signed-off-by: Kou Wenqi <[email protected]>
---
 btt/trace_complete.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/btt/trace_complete.c b/btt/trace_complete.c
index 44732c5..6fb2347 100644
--- a/btt/trace_complete.c
+++ b/btt/trace_complete.c
@@ -56,6 +56,7 @@ static void handle_complete(struct io *c_iop)
 	__u64 d_time = (__u64)-1;
 	FILE *pit_fp = c_iop->dip->pit_fp;
 	double cur = BIT_TIME(c_iop->t.time);
+	int q_iop_matched = 0;
 
 	update_blks(c_iop);
 	update_cregion(&all_regions, c_iop->t.time);
@@ -67,6 +68,7 @@ static void handle_complete(struct io *c_iop)
 
 	dip_foreach_list(c_iop, IOP_Q, &head);
 	list_for_each_safe(p, q, &head) {
+		q_iop_matched = 1;
 		struct io *q_iop = list_entry(p, struct io, f_head);
 		__u64 q2c = tdelta(q_iop->t.time, c_iop->t.time);
 
@@ -103,7 +105,7 @@ static void handle_complete(struct io *c_iop)
 		io_release(q_iop);
 	}
 
-	if (per_io_ofp)
+	if (per_io_ofp && q_iop_matched)
 		fprintf(per_io_ofp,
 			"-----------------------------------------\n");
 
-- 
2.43.0