Skip to contentSkip to conversation

xfs_io: fix operation time reporting

PATCH In review Dave Chinner 2 participants 2 messages Mar 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_io: fix operation time reporting

From: Dave Chinner <[email protected]>

Currently the 100th/sec units always report zero, such as:

32 MiB, 8192 ops; 0:00:21.00 (1.476 MiB/sec and 377.9260 ops/sec)

                          ^^

This is incorrect.

Fix it by reporting milliseconds to be consistent with other time recording utilities. This means we can just use simple integer divsion to implement this and remove all the confusion around calculating non-standard units of time.

Also fix the non-verbose, sub-second time output printed 4 significant digits but only calculated the time to hundreths of a second. Again, just use milliseconds for it.

---
 libxcmd/input.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
libxcmd/input.c +10 -10
index 441bb2fbbf34..4830494eb173 100644
@@ -154,9 +154,10 @@ tdiv(double value, struct timeval tv)
 	return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
 }
 
-#define HOURS(sec)	((sec) / (60 * 60))
-#define MINUTES(sec)	(((sec) % (60 * 60)) / 60)
-#define SECONDS(sec)	((sec) % 60)
+#define HOURS(sec)		((sec) / (60 * 60))
+#define MINUTES(sec)		(((sec) % (60 * 60)) / 60)
+#define SECONDS(sec)		((sec) % 60)
+#define MILLISECONDS(usec)	((usec) / 1000)
 
 void
 timestr(
@@ -165,27 +166,26 @@ timestr(
 	size_t		size,
 	int		format)
 {
-	double		usec = (double)tv->tv_usec / 1000000.0;
-
 	if (format & TERSE_FIXED_TIME) {
 		if (!HOURS(tv->tv_sec)) {
-			snprintf(ts, size, "%u:%02u.%02u",
+			snprintf(ts, size, "%u:%02u.%03u",
 				(unsigned int) MINUTES(tv->tv_sec),
 				(unsigned int) SECONDS(tv->tv_sec),
-				(unsigned int) usec * 100);
+				(unsigned int) MILLISECONDS(tv->tv_usec));
 			return;
 		}
 		format |= VERBOSE_FIXED_TIME;	/* fallback if hours needed */
 	}
 
 	if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
-		snprintf(ts, size, "%u:%02u:%02u.%02u",
+		snprintf(ts, size, "%u:%02u:%02u.%03u",
 			(unsigned int) HOURS(tv->tv_sec),
 			(unsigned int) MINUTES(tv->tv_sec),
 			(unsigned int) SECONDS(tv->tv_sec),
-			(unsigned int) usec * 100);
+			(unsigned int) MILLISECONDS(tv->tv_usec));
 	} else {
-		snprintf(ts, size, "0.%04u sec", (unsigned int) usec * 10000);
+		snprintf(ts, size, "0.%03u sec",
+			(unsigned int) MILLISECONDS(tv->tv_usec));
 	}
 }
 
Signature · 1 line
2.16.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dave Chinner

From: Dave Chinner <[email protected]>

Currently the 100th/sec units always report zero, such as:

32 MiB, 8192 ops; 0:00:21.00 (1.476 MiB/sec and 377.9260 ops/sec)

                          ^^

This is incorrect.

Fix it by reporting milliseconds to be consistent with other time recording utilities. This means we can just use simple integer divsion to implement this and remove all the confusion around calculating non-standard units of time.

Quoted 5 lines

Also fix the non-verbose, sub-second time output printed 4 significant digits but only calculated the time to hundreths of a second. Again, just use milliseconds for it.

Thanks for the update.

Quoted 57 lines
---
 libxcmd/input.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
libxcmd/input.c +10 -10
index 441bb2fbbf34..4830494eb173 100644
@@ -154,9 +154,10 @@ tdiv(double value, struct timeval tv)
 	return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
 }
 
-#define HOURS(sec)	((sec) / (60 * 60))
-#define MINUTES(sec)	(((sec) % (60 * 60)) / 60)
-#define SECONDS(sec)	((sec) % 60)
+#define HOURS(sec)		((sec) / (60 * 60))
+#define MINUTES(sec)		(((sec) % (60 * 60)) / 60)
+#define SECONDS(sec)		((sec) % 60)
+#define MILLISECONDS(usec)	((usec) / 1000)
 
 void
 timestr(
@@ -165,27 +166,26 @@ timestr(
 	size_t		size,
 	int		format)
 {
-	double		usec = (double)tv->tv_usec / 1000000.0;
-
 	if (format & TERSE_FIXED_TIME) {
 		if (!HOURS(tv->tv_sec)) {
-			snprintf(ts, size, "%u:%02u.%02u",
+			snprintf(ts, size, "%u:%02u.%03u",
 				(unsigned int) MINUTES(tv->tv_sec),
 				(unsigned int) SECONDS(tv->tv_sec),
-				(unsigned int) usec * 100);
+				(unsigned int) MILLISECONDS(tv->tv_usec));
 			return;
 		}
 		format |= VERBOSE_FIXED_TIME;	/* fallback if hours needed */
 	}
 
 	if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
-		snprintf(ts, size, "%u:%02u:%02u.%02u",
+		snprintf(ts, size, "%u:%02u:%02u.%03u",
 			(unsigned int) HOURS(tv->tv_sec),
 			(unsigned int) MINUTES(tv->tv_sec),
 			(unsigned int) SECONDS(tv->tv_sec),
-			(unsigned int) usec * 100);
+			(unsigned int) MILLISECONDS(tv->tv_usec));
 	} else {
-		snprintf(ts, size, "0.%04u sec", (unsigned int) usec * 10000);
+		snprintf(ts, size, "0.%03u sec",
+			(unsigned int) MILLISECONDS(tv->tv_usec));
 	}
 }