[Cluster-devel] [PATCH 1/2] fsck.gfs2: Improve reporting of pass timings

Andrew Price anprice at redhat.com
Thu Nov 13 14:19:33 UTC 2014


The days value is not currently reported in the pass timings but the
hours value is still reported modulo 24.  Drop the use of gmtime(3) as
it's more appropriate for calendar time operations than elapsed time,
and add a simple duration reporting function which matches the existing
output format.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/fsck/main.c | 48 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index b25d802..a4af25d 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -246,18 +246,46 @@ static const struct fsck_pass passes[] = {
 	{ .name = NULL, }
 };
 
+static void print_pass_duration(const char *name, struct timeval *start)
+{
+	char duration[17] = ""; /* strlen("XXdXXhXXmXX.XXXs") + 1 */
+	struct timeval end, diff;
+	unsigned d, h, m, s;
+	char *p = duration;
+
+	gettimeofday(&end, NULL);
+	timersub(&end, start, &diff);
+
+	s = diff.tv_sec % 60;
+	diff.tv_sec /= 60;
+	m = diff.tv_sec % 60;
+	diff.tv_sec /= 60;
+	h = diff.tv_sec % 24;
+	d = diff.tv_sec / 24;
+
+	if (d)
+		p += snprintf(p, 4, "%ud", d > 99 ? 99U : d);
+	if (h)
+		p += snprintf(p, 4, "%uh", h);
+	if (m)
+		p += snprintf(p, 4, "%um", m);
+
+	snprintf(p, 8, "%u.%03lus", s, diff.tv_usec / 1000);
+	log_notice(_("%s completed in %s\n"), name, duration);
+}
+
 static int fsck_pass(const struct fsck_pass *p, struct gfs2_sbd *sdp)
 {
 	int ret;
-	struct	timeval	before, after, diff;
-	time_t runtime;
-	struct tm *run_tm;
+	struct timeval timer;
 
 	if (fsck_abort)
 		return FSCK_CANCELED;
 	pass = p->name;
+
 	log_notice( _("Starting %s\n"), p->name);
-	gettimeofday(&before, 0);
+	gettimeofday(&timer, NULL);
+
 	ret = p->f(sdp);
 	if (ret)
 		exit(ret);
@@ -266,16 +294,8 @@ static int fsck_pass(const struct fsck_pass *p, struct gfs2_sbd *sdp)
 		log_notice( _("%s interrupted   \n"), p->name);
 		return FSCK_CANCELED;
 	}
-	gettimeofday(&after, 0);
-	timersub(&after, &before, &diff);
-	runtime = (time_t)diff.tv_sec;
-	run_tm = gmtime(&runtime);
-	log_notice( _("%s completed in "), p->name);
-	if (run_tm->tm_hour)
-		log_notice("%dh", run_tm->tm_hour);
-	if (run_tm->tm_min)
-		log_notice("%dm", run_tm->tm_min);
-	log_notice("%d.%03lds      \n", run_tm->tm_sec, diff.tv_usec / 1000);
+
+	print_pass_duration(p->name, &timer);
 	return 0;
 }
 
-- 
1.9.3




More information about the Cluster-devel mailing list