X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-progress.c;h=5f1b8dfb97a80166598f18b1a1a1cf4390b5a62c;hb=021a1318604e0898cee3800d5b13033e68191f4e;hp=e1feb8961479235b433a1afe27f0a20902f94408;hpb=aa348082d8e89d2ab021caadbcc97c93038fffb2;p=qemu.git diff --git a/qemu-progress.c b/qemu-progress.c index e1feb8961..5f1b8dfb9 100644 --- a/qemu-progress.c +++ b/qemu-progress.c @@ -26,7 +26,6 @@ #include "osdep.h" #include "sysemu.h" #include -#include struct progress_state { float current; @@ -37,6 +36,7 @@ struct progress_state { }; static struct progress_state state; +static volatile sig_atomic_t print_pending; /* * Simple progress print function. @@ -63,12 +63,16 @@ static void progress_simple_init(void) #ifdef CONFIG_POSIX static void sigusr_print(int signal) { - printf(" (%3.2f/100%%)\n", state.current); + print_pending = 1; } #endif static void progress_dummy_print(void) { + if (print_pending) { + fprintf(stderr, " (%3.2f/100%%)\n", state.current); + print_pending = 0; + } } static void progress_dummy_end(void) @@ -91,6 +95,13 @@ static void progress_dummy_init(void) state.end = progress_dummy_end; } +/* + * Initialize progress reporting. + * If @enabled is false, actual reporting is suppressed. The user can + * still trigger a report by sending a SIGUSR1. + * Reports are also suppressed unless we've had at least @min_skip + * percent progress since the last report. + */ void qemu_progress_init(int enabled, float min_skip) { state.min_skip = min_skip; @@ -106,14 +117,25 @@ void qemu_progress_end(void) state.end(); } -void qemu_progress_print(float percent, int max) +/* + * Report progress. + * @delta is how much progress we made. + * If @max is zero, @delta is an absolut value of the total job done. + * Else, @delta is a progress delta since the last call, as a fraction + * of @max. I.e. the delta is @delta * @max / 100. This allows + * relative accounting of functions which may be a different fraction of + * the full job, depending on the context they are called in. I.e. + * a function might be considered 40% of the full job if used from + * bdrv_img_create() but only 20% if called from img_convert(). + */ +void qemu_progress_print(float delta, int max) { float current; if (max == 0) { - current = percent; + current = delta; } else { - current = state.current + percent / 100 * max; + current = state.current + delta / 100 * max; } if (current > 100) { current = 100;