From: Jens Axboe Date: Tue, 23 Sep 2014 20:40:48 +0000 (-0600) Subject: dedupe: print progress indicator X-Git-Tag: fio-2.1.13~50 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=4d53d6c06e181d8e4eb62dd8c1ba471dee9f35e2;p=fio.git dedupe: print progress indicator Signed-off-by: Jens Axboe --- diff --git a/t/dedupe.c b/t/dedupe.c index 03c5032b..d816a093 100644 --- a/t/dedupe.c +++ b/t/dedupe.c @@ -36,6 +36,8 @@ void __dprint(int type, const char *str, ...) struct worker_thread { pthread_t thread; + volatile int done; + int fd; uint64_t cur_offset; uint64_t size; @@ -70,6 +72,7 @@ static unsigned int chunk_size = 1048576; static unsigned int dump_output; static unsigned int odirect; static unsigned int collision_check; +static unsigned int print_progress = 1; static uint64_t total_size; static uint64_t cur_offset; @@ -272,6 +275,7 @@ static void *thread_fn(void *data) } } while (1); + thread->done = 1; fio_memfree(buf, blocksize); return NULL; } @@ -279,10 +283,11 @@ static void *thread_fn(void *data) static int __dedupe_check(int fd, uint64_t dev_size) { struct worker_thread *threads; - unsigned long nitems; + unsigned long nitems, total_items; int i, err = 0; total_size = dev_size; + total_items = dev_size / blocksize; cur_offset = 0; size_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); @@ -291,6 +296,7 @@ static int __dedupe_check(int fd, uint64_t dev_size) threads[i].fd = fd; threads[i].items = 0; threads[i].err = 0; + threads[i].done = 0; err = pthread_create(&threads[i].thread, NULL, thread_fn, &threads[i]); if (err) { @@ -299,6 +305,28 @@ static int __dedupe_check(int fd, uint64_t dev_size) } } + while (print_progress) { + float perc; + int some_done; + + nitems = 0; + for (i = 0; i < num_threads; i++) { + nitems += threads[i].items; + some_done = threads[i].done; + if (some_done) + break; + } + + if (some_done) + break; + + perc = (float) nitems / (float) total_items; + perc *= 100.0; + printf("%3.2f%% done\r", perc); + fflush(stdout); + usleep(200000); + }; + nitems = 0; for (i = 0; i < num_threads; i++) { void *ret; @@ -399,6 +427,7 @@ static int usage(char *argv[]) log_err("\t-d\tFull extent/chunk debug output\n"); log_err("\t-o\tUse O_DIRECT\n"); log_err("\t-c\tFull collision check\n"); + log_err("\t-p\tPrint progress indicator\n"); return 1; } @@ -406,7 +435,7 @@ int main(int argc, char *argv[]) { int c, ret; - while ((c = getopt(argc, argv, "b:t:d:o:c:")) != -1) { + while ((c = getopt(argc, argv, "b:t:d:o:c:p:")) != -1) { switch (c) { case 'b': blocksize = atoi(optarg); @@ -423,6 +452,9 @@ int main(int argc, char *argv[]) case 'c': collision_check = atoi(optarg); break; + case 'p': + print_progress = atoi(optarg); + break; case '?': default: return usage(argv);