]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck: use gettimeofday() for real elapsed time statistic
authorKarel Zak <kzak@redhat.com>
Tue, 6 Mar 2012 12:36:28 +0000 (13:36 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2012 10:22:09 +0000 (11:22 +0100)
 and use shorter "rss" rather than "maxrss" keyword in stats output

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fsck.8
disk-utils/fsck.c

index 69fe2edd14935822273a79181735e7e14db69ecd..5eca31897e92ff001cd18df1f4747cea9f6f9223 100644 (file)
@@ -109,7 +109,7 @@ include the exit status, the maximum run set size (in kilobytes), the elapsed
 all-clock time and the user and system CPU time used by the fsck run. For
 example:
 
-/dev/sda1: status 0, maxrss 92828, real 4, user 2.677592, sys 0.861868
+/dev/sda1: status 0, rss 92828, real 4.002804, user 2.677592, sys 0.86186
 .TP
 .B \-s
 Serialize
index 040f6f8e0a144b5415f1e9d93068bb40ac54b59b..ff16ebcf146b3607d57643b81fbabe781a8da52f 100644 (file)
@@ -44,6 +44,7 @@
 #include <signal.h>
 #include <dirent.h>
 #include <sys/resource.h>
+#include <sys/time.h>
 #include <blkid.h>
 #include <libmount.h>
 
@@ -102,8 +103,8 @@ struct fsck_instance {
        int     flags;          /* FLAG_{DONE|PROGRESS} */
        int     lock;           /* flock()ed whole disk file descriptor or -1 */
        int     exit_status;
-       time_t  start_time;
-       time_t  end_time;
+       struct timeval start_time;
+       struct timeval end_time;
        char *  prog;
        char *  type;
 
@@ -500,18 +501,20 @@ static int progress_active(void)
  */
 static void print_stats(struct fsck_instance *inst)
 {
-       time_t time_diff;
+       double time_diff;
 
        if (!inst || !report_stats || noexecute)
                return;
 
-       time_diff = inst->end_time - inst->start_time;
-       fprintf(stdout, "%s: status %d, maxrss %ld, "
-                       "real %d, user %d.%06d, sys %d.%06d\n",
+       time_diff = (inst->end_time.tv_sec  - inst->start_time.tv_sec)
+                 + (inst->end_time.tv_usec - inst->start_time.tv_usec) / 1E6;
+
+       fprintf(stdout, "%s: status %d, rss %ld, "
+                       "real %f, user %d.%06d, sys %d.%06d\n",
                fs_get_device(inst->fs),
                inst->exit_status,
                inst->rusage.ru_maxrss,
-               (int)time_diff,
+               time_diff,
                (int)inst->rusage.ru_utime.tv_sec,
                (int)inst->rusage.ru_utime.tv_usec,
                (int)inst->rusage.ru_stime.tv_sec,
@@ -603,7 +606,7 @@ static int execute(const char *type, struct libmnt_fs *fs, int interactive)
        inst->pid = pid;
        inst->prog = xstrdup(prog);
        inst->type = xstrdup(type);
-       inst->start_time = time(0);
+       gettimeofday(&inst->start_time, NULL);
        inst->next = NULL;
 
        /*
@@ -716,7 +719,7 @@ static struct fsck_instance *wait_one(int flags)
 
        inst->exit_status = status;
        inst->flags |= FLAG_DONE;
-       inst->end_time = time(0);
+       gettimeofday(&inst->end_time, NULL);
        memcpy(&inst->rusage, &rusage, sizeof(struct rusage));
 
        if (progress && (inst->flags & FLAG_PROGRESS) &&
@@ -734,7 +737,7 @@ static struct fsck_instance *wait_one(int flags)
                         * bit before sending the kill, to give it
                         * time to set up the signal handler
                         */
-                       if (inst2->start_time < time(0)+2) {
+                       if (inst2->start_time.tv_sec < time(0) + 2) {
                                if (fork() == 0) {
                                        sleep(1);
                                        kill(inst2->pid, SIGUSR1);