cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/2] fsck.gfs2: Improve reporting of pass timings
Date: Thu, 13 Nov 2014 14:19:33 +0000	[thread overview]
Message-ID: <1415888374-23564-1-git-send-email-anprice@redhat.com> (raw)

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@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



             reply	other threads:[~2014-11-13 14:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 14:19 Andrew Price [this message]
2014-11-13 14:19 ` [Cluster-devel] [PATCH 2/2] mkfs.gfs2: Revert default resource group size Andrew Price
2014-11-14 16:45   ` Bob Peterson
2014-11-14 16:44 ` [Cluster-devel] [PATCH 1/2] fsck.gfs2: Improve reporting of pass timings Bob Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415888374-23564-1-git-send-email-anprice@redhat.com \
    --to=anprice@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).