lib/aux: Print progress output at INFO level

With the structured logging it makes more sense to tune this down a
bit. Also, this way it is consistent with Thomas Wood's new activity
indicator helper.

Spotted while discussing Thomas' patch with him.

v2: Thomas noticed that I've forgotten the fflush. Extract
igt_interactive_info for both igt_progress and igt_print_activity.

v3: Interactive output should go to stderr. Also extract the "is this
a terminal" check.

Cc: Thomas Wood <thomas.wood@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
This commit is contained in:
Daniel Vetter 2014-09-30 18:44:15 +02:00
parent 6a8d33c2bb
commit 711199b8ec

View File

@ -214,6 +214,23 @@ void igt_permute_array(void *array, unsigned size,
} }
} }
__attribute__((format(printf, 1, 2)))
static void igt_interactive_info(const char *format, ...)
{
va_list args;
if (!isatty(STDERR_FILENO))
return;
if (igt_log_level > IGT_LOG_INFO)
return;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
/** /**
* igt_progress: * igt_progress:
* @header: header string to prepend to the progress indicator * @header: header string to prepend to the progress indicator
@ -229,11 +246,8 @@ void igt_progress(const char *header, uint64_t i, uint64_t total)
{ {
int divider = 200; int divider = 200;
if (!isatty(fileno(stderr)))
return;
if (i+1 >= total) { if (i+1 >= total) {
igt_warn("\r%s100%%\n", header); igt_interactive_info("\r%s100%%\n", header);
return; return;
} }
@ -242,8 +256,8 @@ void igt_progress(const char *header, uint64_t i, uint64_t total)
/* only bother updating about every 0.5% */ /* only bother updating about every 0.5% */
if (i % (total / divider) == 0) if (i % (total / divider) == 0)
igt_warn("\r%s%3llu%%", header, igt_interactive_info("\r%s%3llu%%", header,
(long long unsigned)i * 100 / total); (long long unsigned)i * 100 / total);
} }
/** /**
@ -254,11 +268,7 @@ void igt_progress(const char *header, uint64_t i, uint64_t total)
*/ */
void igt_print_activity(void) void igt_print_activity(void)
{ {
if (!isatty(STDOUT_FILENO)) igt_interactive_info(".");
return;
igt_info(".");
fflush(stdout);
} }
/* mappable aperture trasher helper */ /* mappable aperture trasher helper */