[PATCH v2] btt: add a switch to change it to msec

Fanhui Meng <[email protected]> Thu, 24 Apr 2025 13:52:34 +0800
Newsgroups org.kernel.vger.linux-btrace
Message-ID <[email protected]>
Output latency time in msec to increase readability.
as the normal time for IO requests is usually a few
msec. Therefore, add a switch to change it to msec.

default command and test result:
btt -i   blkparse.out -q q2c.lat
1.725317 0.000292
1.725275 0.000337
1.725326 0.000288
1.725334 0.000282
1.725342 0.000277
2.039203 0.000217
2.039463 0.000123
2.039715 0.000174
2.040144 0.000184

switch to msec command:
btt -i   blkparse.out -q q2c.lat  -w
q2c.dat test output result:
1.725317 0.292148
1.725275 0.337183
1.725326 0.288462
1.725334 0.282350
1.725342 0.276609
2.039203 0.217158
2.039463 0.123061
2.039715 0.173856
2.040144 0.184456

Signed-off-by: Fanhui Meng <[email protected]>
---
 btt/args.c    | 12 +++++++++++-
 btt/globals.h |  2 +-
 btt/latency.c |  4 +++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/btt/args.c b/btt/args.c
index 5c5078a..ec65399 100644
--- a/btt/args.c
+++ b/btt/args.c
@@ -29,7 +29,7 @@
 
 #define SETBUFFER_SIZE	(64 * 1024)
 
-#define S_OPTS	"aAB:d:D:e:hi:I:l:L:m:M:o:p:P:q:Q:rs:S:t:T:u:VvXz:Z"
+#define S_OPTS	"aAB:d:D:e:hi:I:l:L:m:M:o:p:P:wq:Q:rs:S:t:T:u:VvXz:Z"
 static struct option l_opts[] = {
 	{
 		.name = "seek-absolute",
@@ -199,6 +199,12 @@ static struct option l_opts[] = {
 		.flag = NULL,
 		.val = 'X'
 	},
+	{
+		.name = "sec-to-msec",
+		.has_arg = no_argument,
+		.flag = NULL,
+		.val = 'w'
+	},
 	{
 		.name = "q2d-latencies",
 		.has_arg = required_argument,
@@ -239,6 +245,7 @@ static char usage_str[] = \
 	"[ -v               | --verbose ]\n" \
 	"[ -X               | --easy-parse-avgs ]\n" \
 	"[ -z <output name> | --q2d-latencies=<output name> ]\n" \
+	"[ -w               | --sec-to-msec ]\n" \
 	"[ -Z               | --do-active\n" \
 	"\n";
 
@@ -384,6 +391,9 @@ void handle_args(int argc, char *argv[])
 		case 'z':
 			q2d_name = optarg;
 			break;
+		case 'w':
+			sec_to_msec = 1;
+			break;
 		case 'Z':
 			do_p_live = 1;
 			break;
diff --git a/btt/globals.h b/btt/globals.h
index 22a1cb0..0331ecf 100644
--- a/btt/globals.h
+++ b/btt/globals.h
@@ -179,7 +179,7 @@ extern double range_delta, plat_freq, last_t_seen;
 extern FILE *rngs_ofp, *avgs_ofp, *xavgs_ofp, *iostat_ofp, *per_io_ofp;
 extern FILE *msgs_ofp;
 extern int verbose, done, time_bounded, output_all_data, seek_absolute;
-extern int easy_parse_avgs, ignore_remaps, do_p_live;
+extern int easy_parse_avgs, ignore_remaps, do_p_live, sec_to_msec;
 extern unsigned int n_devs;
 extern unsigned long n_traces;
 extern struct list_head all_devs, all_procs;
diff --git a/btt/latency.c b/btt/latency.c
index 51e6881..332d05a 100644
--- a/btt/latency.c
+++ b/btt/latency.c
@@ -20,10 +20,12 @@
  */
 #include "globals.h"
 
+int sec_to_msec;
+
 static inline void latency_out(FILE *ofp, __u64 tstamp, __u64 latency)
 {
 	if (ofp)
-		fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), TO_SEC(latency));
+		fprintf(ofp, "%lf %lf\n", TO_SEC(tstamp), sec_to_msec ? TO_MSEC(latency) : TO_SEC(latency));
 }
 
 FILE *latency_open(struct d_info *dip, char *name, char *post)
-- 
2.25.1