hammer - Add scoreboard file option
[dragonfly.git] / sbin / hammer / cmd_mirror.c
index e115ea2..fd4f913 100644 (file)
 
 #include "hammer.h"
 
+#define LINE1  0,20
+#define LINE2  20,78
+#define LINE3  90,70
+
 #define SERIALBUF_SIZE (512 * 1024)
 
 typedef struct histogram {
@@ -120,6 +124,9 @@ again:
 
        fd = getpfs(&pfs, filesystem);
 
+       if (streaming >= 0)
+               score_printf(LINE1, "Running");
+
        if (streaming >= 0 && VerboseOpt && VerboseOpt < 2) {
                fprintf(stderr, "%cRunning  \b\b", (sameline ? '\r' : '\n'));
                fflush(stderr);
@@ -273,11 +280,15 @@ again:
                mirror.pfs_id = pfs.pfs_id;
                mirror.shared_uuid = pfs.ondisk->shared_uuid;
                if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
+                       score_printf(LINE3, "Mirror-read %s failed: %s",
+                                    filesystem, strerror(errno));
                        fprintf(stderr, "Mirror-read %s failed: %s\n",
                                filesystem, strerror(errno));
                        exit(1);
                }
                if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
+                       score_printf(LINE3, "Mirror-read %s fatal error %d",
+                                    filesystem, mirror.head.error);
                        fprintf(stderr,
                                "Mirror-read %s fatal error %d\n",
                                filesystem, mirror.head.error);
@@ -291,8 +302,13 @@ again:
                                n = write(1, mirror.ubuf, mirror.count);
                        }
                        if (n != mirror.count) {
-                               fprintf(stderr, "Mirror-read %s failed: "
-                                               "short write\n",
+                               score_printf(LINE3,
+                                            "Mirror-read %s failed: "
+                                            "short write",
+                                            filesystem);
+                               fprintf(stderr,
+                                       "Mirror-read %s failed: "
+                                       "short write\n",
                                filesystem);
                                exit(1);
                        }
@@ -307,6 +323,13 @@ again:
                                (intmax_t)total_bytes);
                        fflush(stderr);
                        sameline = 0;
+               } else if (streaming) {
+                       score_printf(LINE2,
+                               "obj=%016jx tids=%016jx:%016jx %11jd",
+                               (uintmax_t)mirror.key_cur.obj_id,
+                               (uintmax_t)mirror.tid_beg,
+                               (uintmax_t)mirror.tid_end,
+                               (intmax_t)total_bytes);
                }
                mirror.key_beg = mirror.key_cur;
 
@@ -315,6 +338,11 @@ again:
                 */
                if (TimeoutOpt &&
                    (unsigned)(time(NULL) - base_t) > (unsigned)TimeoutOpt) {
+                       score_printf(LINE3,
+                               "Mirror-read %s interrupted by timer at"
+                               " %016jx",
+                               filesystem,
+                               (uintmax_t)mirror.key_cur.obj_id);
                        fprintf(stderr,
                                "Mirror-read %s interrupted by timer at"
                                " %016jx\n",
@@ -406,6 +434,8 @@ done:
                if (VerboseOpt && streaming >= 0) {
                        fprintf(stderr, " W");
                        fflush(stderr);
+               } else if (streaming >= 0) {
+                       score_printf(LINE1, "Waiting");
                }
                pfs.ondisk->sync_end_tid = mirror.tid_end;
                if (streaming < 0) {
@@ -415,7 +445,11 @@ done:
                         */
                        streaming = 0;
                } else if (ioctl(fd, HAMMERIOC_WAI_PSEUDOFS, &pfs) < 0) {
-                       fprintf(stderr, "Mirror-read %s: cannot stream: %s\n",
+                       score_printf(LINE3,
+                                    "Mirror-read %s: cannot stream: %s\n",
+                                    filesystem, strerror(errno));
+                       fprintf(stderr,
+                               "Mirror-read %s: cannot stream: %s\n",
                                filesystem, strerror(errno));
                } else {
                        t2 = time(NULL) - t1;
@@ -472,6 +506,7 @@ generate_histogram(int fd, const char *filesystem,
        u_int64_t *tid_bytes;
        u_int64_t total;
        u_int64_t accum;
+       int chunkno;
        int i;
        int res;
        int off;
@@ -509,6 +544,7 @@ generate_histogram(int fd, const char *filesystem,
         */
        total = 0;
        accum = 0;
+       chunkno = 0;
        for (;;) {
                mirror.count = 0;
                if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
@@ -590,12 +626,14 @@ generate_histogram(int fd, const char *filesystem,
                                accum += len;
                        }
                }
-               if (VerboseOpt > 1) {
-                       if (*repeatp == 0 && accum > SplitupOpt) {
+               if (*repeatp == 0 && accum > SplitupOpt) {
+                       if (VerboseOpt > 1) {
                                fprintf(stderr, ".");
                                fflush(stderr);
-                               accum = 0;
                        }
+                       ++chunkno;
+                       score_printf(LINE2, "Prescan chunk %d", chunkno);
+                       accum = 0;
                }
                if (mirror.count == 0)
                        break;
@@ -631,6 +669,8 @@ generate_histogram(int fd, const char *filesystem,
        if (*repeatp == 0) {
                if (VerboseOpt > 1)
                        fprintf(stderr, "\n");  /* newline after ... */
+               score_printf(LINE3, "Prescan %d chunks, total %ju MBytes",
+                       res, (uintmax_t)total / (1024 * 1024));
                fprintf(stderr, "Prescan %d chunks, total %ju MBytes (",
                        res, (uintmax_t)total / (1024 * 1024));
                for (i = 0; i < res && i < 3; ++i) {