From: Jonathan Rajotte Date: Tue, 13 Aug 2019 18:14:25 +0000 (-0400) Subject: Introduce LTTNG_KERNEL_SESSION_SET_CREATION_TIME X-Git-Tag: v2.11.0-rc6~2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a9550ab5b92e217b90a33c6bd9daa3863f787f72;p=lttng-modules.git Introduce LTTNG_KERNEL_SESSION_SET_CREATION_TIME Add trace_creation_datetime to the metadata env field This allows a viewer to get more information regarding the creation time of a trace. This information is normally inferred from the trace hierarchy. The ABI expects an ISO8601 compliant string value. We leave the formatting to the trace controller. Signed-off-by: Jonathan Rajotte Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-abi.c b/lttng-abi.c index aab2caca..cc8f1838 100644 --- a/lttng-abi.c +++ b/lttng-abi.c @@ -470,6 +470,23 @@ int lttng_abi_session_set_name(struct lttng_session *session, return 0; } +static +int lttng_abi_session_set_creation_time(struct lttng_session *session, + struct lttng_kernel_session_creation_time *time) +{ + size_t len; + + len = strnlen(time->iso8601, LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN); + + if (len == LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN) { + /* Time is too long/malformed */ + return -EINVAL; + } + + strcpy(session->creation_time, time->iso8601); + return 0; +} + /** * lttng_session_ioctl - lttng session fd ioctl * @@ -589,6 +606,16 @@ long lttng_session_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return -EFAULT; return lttng_abi_session_set_name(session, &name); } + case LTTNG_KERNEL_SESSION_SET_CREATION_TIME: + { + struct lttng_kernel_session_creation_time time; + + if (copy_from_user(&time, + (struct lttng_kernel_session_creation_time __user *) arg, + sizeof(struct lttng_kernel_session_creation_time))) + return -EFAULT; + return lttng_abi_session_set_creation_time(session, &time); + } default: return -ENOIOCTLCMD; } diff --git a/lttng-abi.h b/lttng-abi.h index 0dd9a9fe..c292de01 100644 --- a/lttng-abi.h +++ b/lttng-abi.h @@ -21,6 +21,7 @@ #define LTTNG_KERNEL_SYM_NAME_LEN 256 #define LTTNG_KERNEL_SESSION_NAME_LEN 256 +#define LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN 26 enum lttng_kernel_instrumentation { LTTNG_KERNEL_TRACEPOINT = 0, @@ -124,6 +125,10 @@ struct lttng_kernel_session_name { char name[LTTNG_KERNEL_SESSION_NAME_LEN]; } __attribute__((packed)); +struct lttng_kernel_session_creation_time { + char iso8601[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN]; +} __attribute__((packed)); + enum lttng_kernel_calibrate_type { LTTNG_KERNEL_CALIBRATE_KRETPROBE, }; @@ -219,6 +224,8 @@ struct lttng_kernel_filter_bytecode { #define LTTNG_KERNEL_SESSION_STATEDUMP _IO(0xF6, 0x5C) #define LTTNG_KERNEL_SESSION_SET_NAME \ _IOR(0xF6, 0x5D, struct lttng_kernel_session_name) +#define LTTNG_KERNEL_SESSION_SET_CREATION_TIME \ + _IOR(0xF6, 0x5E, struct lttng_kernel_session_creation_time) /* Channel FD ioctl */ #define LTTNG_KERNEL_STREAM _IO(0xF6, 0x62) diff --git a/lttng-events.c b/lttng-events.c index 46a8fe1b..25c616ee 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -2515,15 +2515,16 @@ error: } static -int print_metadata_session_name(struct lttng_session *session) +int print_metadata_escaped_field(struct lttng_session *session, const char *field, + const char *field_value) { int ret; - ret = lttng_metadata_printf(session, " trace_name = \""); + ret = lttng_metadata_printf(session, " %s = \"", field); if (ret) goto error; - ret = print_escaped_ctf_string(session, session->name); + ret = print_escaped_ctf_string(session, field_value); if (ret) goto error; @@ -2620,7 +2621,11 @@ int _lttng_session_metadata_statedump(struct lttng_session *session) if (ret) goto end; - ret = print_metadata_session_name(session); + ret = print_metadata_escaped_field(session, "trace_name", session->name); + if (ret) + goto end; + ret = print_metadata_escaped_field(session, "trace_creation_datetime", + session->creation_time); if (ret) goto end; diff --git a/lttng-events.h b/lttng-events.h index 14c65c00..93a10fed 100644 --- a/lttng-events.h +++ b/lttng-events.h @@ -522,6 +522,7 @@ struct lttng_session { /* Hash table of events */ struct lttng_event_ht events_ht; char name[LTTNG_KERNEL_SESSION_NAME_LEN]; + char creation_time[LTTNG_KERNEL_SESSION_CREATION_TIME_ISO8601_LEN]; }; struct lttng_metadata_cache {