From 939950af98d044a3b0632cad5293f91cb1493ef8 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 30 Jan 2012 09:02:04 -0500 Subject: [PATCH] Use boot_id as monotonic clock uuid Signed-off-by: Mathieu Desnoyers --- liblttng-ust/clock.h | 31 +++++++++++++++++++++++++++++-- liblttng-ust/ltt-events.c | 22 +++++++++++++++++----- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/liblttng-ust/clock.h b/liblttng-ust/clock.h index 95e3e43b..82a7b45c 100644 --- a/liblttng-ust/clock.h +++ b/liblttng-ust/clock.h @@ -24,6 +24,12 @@ #include #include #include +#include + +/* + * Includes final \0. + */ +#define CLOCK_UUID_LEN 37 /* TRACE CLOCK */ @@ -50,9 +56,30 @@ uint64_t trace_clock_freq(void) } static __inline__ -const char *trace_clock_uuid(void) +const int trace_clock_uuid(char *uuid) { - return "CLOCK_MONOTONIC"; + int ret = 0; + size_t len; + FILE *fp; + + /* + * boot_id needs to be read once before being used concurrently + * to deal with a Linux kernel race. A fix is proposed for + * upstream, but the work-around is needed for older kernels. + */ + fp = fopen("/proc/sys/kernel/random/boot_id", "r"); + if (!fp) { + return -ENOENT; + } + len = fread(uuid, 1, CLOCK_UUID_LEN - 1, fp); + if (len < CLOCK_UUID_LEN - 1) { + ret = -EINVAL; + goto end; + } + uuid[CLOCK_UUID_LEN - 1] = '\0'; +end: + fclose(fp); + return ret; } #endif /* _UST_CLOCK_H */ diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 7d2dc31a..85afc1ba 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -1075,7 +1075,7 @@ static int _ltt_session_metadata_statedump(struct ltt_session *session) { unsigned char *uuid_c = session->uuid; - char uuid_s[37]; + char uuid_s[37], clock_uuid_s[CLOCK_UUID_LEN]; struct ltt_channel *chan; struct ltt_event *event; int ret = 0; @@ -1133,15 +1133,27 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) ret = lttng_metadata_printf(session, "clock {\n" - " name = %s;\n" - " uuid = %s;\n" + " name = %s;\n", + "monotonic" + ); + if (ret) + goto end; + + if (!trace_clock_uuid(clock_uuid_s)) { + ret = lttng_metadata_printf(session, + " uuid = \"%s\";\n", + clock_uuid_s + ); + if (ret) + goto end; + } + + ret = lttng_metadata_printf(session, " description = \"Monotonic Clock\";\n" " freq = %" PRIu64 "; /* Frequency, in Hz */\n" " /* clock value offset from Epoch is: offset * (1/freq) */\n" " offset = %" PRIu64 ";\n" "};\n\n", - "monotonic", - trace_clock_uuid(), trace_clock_freq(), measure_clock_offset() ); -- 2.34.1