Print UTF-8 SI suffix only when allowed by the locale
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 14 Dec 2018 02:24:35 +0000 (21:24 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 14 Jan 2019 22:56:28 +0000 (17:56 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/timer.c
src/bin/lttng/commands/create.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_rotation.c
src/bin/lttng/commands/list.c
src/common/time.c
src/common/time.h

index 9915767657fdbdc790d4b8568cd6ecb710b8a40d..c65df5c2dc132706b1a6335e0d73ecff10eabf00 100644 (file)
@@ -279,8 +279,8 @@ int timer_session_rotation_schedule_timer_start(struct ltt_session *session,
                ret = -1;
                goto end;
        }
-       DBG("Enabling scheduled rotation timer on session \"%s\" (%ui µs)", session->name,
-                       interval_us);
+       DBG("Enabling scheduled rotation timer on session \"%s\" (%ui %s)", session->name,
+                       interval_us, USEC_UNIT);
        ret = timer_start(&session->rotation_schedule_timer, session,
                        interval_us, LTTNG_SESSIOND_SIG_SCHEDULED_ROTATION,
                        /* one-shot */ false);
index 60ca1f5d45fc7e0b6271f022b382d9ff8ce9a162..d2741c37309239697ab9d7b30fed98ee5011f2c9 100644 (file)
@@ -442,7 +442,7 @@ static int create_session(void)
                MSG("Traces will be written in %s", print_str_url);
 
                if (opt_live_timer) {
-                       MSG("Live timer set to %u usec", opt_live_timer);
+                       MSG("Live timer set to %u %s", opt_live_timer, USEC_UNIT);
                }
        } else if (opt_snapshot) {
                if (print_str_url) {
index 3314bde0d6da4f7ff37d8747d2b1129e746bda92..b4e2942c3bb5cab0477adb3bc08cc30c33f4475d 100644 (file)
@@ -510,7 +510,9 @@ int cmd_enable_channels(int argc, const char **argv)
                                goto end;
                        }
                        chan_opts.attr.switch_timer_interval = (uint32_t) v;
-                       DBG("Channel switch timer interval set to %d", chan_opts.attr.switch_timer_interval);
+                       DBG("Channel switch timer interval set to %d %s",
+                                       chan_opts.attr.switch_timer_interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_READ_TIMER:
@@ -532,7 +534,9 @@ int cmd_enable_channels(int argc, const char **argv)
                                goto end;
                        }
                        chan_opts.attr.read_timer_interval = (uint32_t) v;
-                       DBG("Channel read timer interval set to %d", chan_opts.attr.read_timer_interval);
+                       DBG("Channel read timer interval set to %d %s",
+                                       chan_opts.attr.read_timer_interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_MONITOR_TIMER:
@@ -549,7 +553,9 @@ int cmd_enable_channels(int argc, const char **argv)
                        }
                        opt_monitor_timer.interval = (uint64_t) v;
                        opt_monitor_timer.set = true;
-                       DBG("Channel monitor timer interval set to %" PRIu64" (µs)", opt_monitor_timer.interval);
+                       DBG("Channel monitor timer interval set to %" PRIu64 " %s",
+                                       opt_monitor_timer.interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_BLOCKING_TIMEOUT:
@@ -597,8 +603,9 @@ int cmd_enable_channels(int argc, const char **argv)
 
                        opt_blocking_timeout.value = (int64_t) v;
                        opt_blocking_timeout.set = true;
-                       DBG("Channel blocking timeout set to %" PRId64 " µs%s",
+                       DBG("Channel blocking timeout set to %" PRId64 " %s%s",
                                        opt_blocking_timeout.value,
+                                       USEC_UNIT,
                                        opt_blocking_timeout.value == 0 ?
                                                " (non-blocking)" : "");
                        break;
index 85dae5681f251b398752cd204928116d32560983..0023de5b7f097c0673a1eb1b8536d5fd2d908242 100644 (file)
@@ -118,8 +118,8 @@ static enum cmd_error_code add_schedule(const char *session_name,
                ret = CMD_SUCCESS;
                switch (schedule_type) {
                case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC:
-                       MSG("Enabled %s rotations every %" PRIu64 " µs on session %s",
-                                       schedule_type_name, value, session_name);
+                       MSG("Enabled %s rotations every %" PRIu64 " %s on session %s",
+                                       schedule_type_name, value, USEC_UNIT, session_name);
                        break;
                case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD:
                        MSG("Enabled %s rotations every %" PRIu64 " bytes written on session %s",
index eabeb8132ecd36c6e15fb996cb8bdba96b61249d..d43127d1d444b24c1675a07ec4cda908c058bcc6 100644 (file)
@@ -1261,7 +1261,7 @@ void print_timer(const char *timer_name, uint32_t space_count, int64_t value)
        }
 
        if (value) {
-               MSG("%" PRId64 " µs", value);
+               MSG("%" PRId64 " %s", value, USEC_UNIT);
        } else {
                MSG("inactive");
        }
@@ -1318,7 +1318,8 @@ static void print_channel(struct lttng_channel *channel)
                if (blocking_timeout == -1) {
                        MSG("%sBlocking timeout: infinite", indent6);
                } else {
-                       MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
+                       MSG("%sBlocking timeout: %" PRId64 " %s", indent6,
+                                       blocking_timeout, USEC_UNIT);
                }
        }
 
@@ -1616,7 +1617,7 @@ static enum cmd_error_code print_periodic_rotation_schedule(
                goto end;
        }
 
-       MSG("    timer period: %" PRIu64" µs", value);
+       MSG("    timer period: %" PRIu64" %s", value, USEC_UNIT);
        ret = CMD_SUCCESS;
 end:
        return ret;
index 5c5594584dc6ae37c59ab44625ca7ad9b8c9534d..5519e3ab4715240cfd1b27ef7701d36c1b737039 100644 (file)
 #include <limits.h>
 #include <errno.h>
 #include <pthread.h>
+#include <locale.h>
+#include <string.h>
+
+static bool utf8_output_supported;
+
+LTTNG_HIDDEN
+bool locale_supports_utf8(void)
+{
+       return utf8_output_supported;
+}
 
 LTTNG_HIDDEN
 int timespec_to_ms(struct timespec ts, unsigned long *ms)
@@ -57,3 +67,16 @@ struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2)
        res.tv_nsec = diff % (uint64_t) NSEC_PER_SEC;
        return res;
 }
+
+static
+void __attribute__((constructor)) init_locale_utf8_support(void)
+{
+       const char *program_locale = setlocale(LC_ALL, NULL);
+       const char *lang = getenv("LANG");
+
+       if (program_locale && strstr(program_locale, "utf8")) {
+               utf8_output_supported = true;
+       } else if (strstr(lang, "utf8")) {
+               utf8_output_supported = true;
+       }
+}
index 8a7dd958ffeeb6b86ef4a1ce1b11cf1c10a6a42b..894ab9259a135a3f7816d74e3475d268ec328b13 100644 (file)
 #define LTTNG_TIME_H
 
 #include <time.h>
+#include <stdbool.h>
 
 #define MSEC_PER_SEC   1000ULL
 #define NSEC_PER_SEC   1000000000ULL
 #define NSEC_PER_MSEC  1000000ULL
 #define NSEC_PER_USEC  1000ULL
 
+bool locale_supports_utf8(void);
+
+#define NSEC_UNIT       "ns"
+#define USEC_UNIT       (locale_supports_utf8() ? "µs" : "us")
+#define MSEC_UNIT       "ms"
+#define SEC_UNIT        "s"
+#define MIN_UNIT        "m"
+#define HR_UNIT         "h"
+
 /*
  * timespec_to_ms: Convert timespec to milliseconds.
  *
This page took 0.0332 seconds and 4 git commands to generate.