summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-12-12 15:20:08 -0500
committerColin Walters <walters@verbum.org>2017-12-12 15:31:45 -0500
commit96b1fd9578b3d6ff2d8e0707068f5ef450eba98c (patch)
tree2d4eb01c58fef1c1eda153a6f28d5a1ef04180f0
parent985ed1c861abf4a0069b582ed6a26f6728e673c2 (diff)
downloadlibglnx-96b1fd9578b3d6ff2d8e0707068f5ef450eba98c.tar.gz
console: Avoid rendering too quickly
For TTYs, it slows things down pointlessly. For non-TTYs like Jenkins jobs, it creates a ton of output that obscures useful information.
-rw-r--r--glnx-console.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/glnx-console.c b/glnx-console.c
index 2ca1349..1cb3a49 100644
--- a/glnx-console.c
+++ b/glnx-console.c
@@ -36,7 +36,15 @@
*/
#define MAX_PROGRESSBAR_COLUMNS 20
+/* Max updates output per second. On a tty there's no point to rendering
+ * extremely fast; and for a non-tty we're probably in a Jenkins job
+ * or whatever and having percentages spam multiple lines there is annoying.
+ */
+#define MAX_TTY_UPDATE_HZ (5)
+#define MAX_NONTTY_UPDATE_HZ (1)
+
static gboolean locked;
+static guint64 last_update_ms; /* monotonic time in millis we last updated */
static gboolean
stdout_is_tty (void)
@@ -184,6 +192,26 @@ static void
text_percent_internal (const char *text,
int percentage)
{
+ /* Check whether we're trying to render too fast; unless percentage is 100, in
+ * which case we assume this is the last call, so we always render it.
+ */
+ const guint64 current_ms = g_get_monotonic_time () / 1000;
+ if (percentage != 100)
+ {
+ const guint64 diff_ms = current_ms - last_update_ms;
+ if (stdout_is_tty ())
+ {
+ if (diff_ms < (1000/MAX_TTY_UPDATE_HZ))
+ return;
+ }
+ else
+ {
+ if (diff_ms < (1000/MAX_NONTTY_UPDATE_HZ))
+ return;
+ }
+ }
+ last_update_ms = current_ms;
+
static const char equals[] = "====================";
const guint n_equals = sizeof (equals) - 1;
static const char spaces[] = " ";