From: David Goulet Date: Tue, 26 Jul 2011 15:43:35 +0000 (-0400) Subject: Trace path creation made on the client side X-Git-Tag: v2.0-pre4~5 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d6175221183d58027dcac4a6814d2a3457550628;p=lttng-tools.git Trace path creation made on the client side The traces output path is set on the client side with the date and time if no output path is specified. Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/session.c b/ltt-sessiond/session.c index ff79bf2a9..7a7bf3e57 100644 --- a/ltt-sessiond/session.c +++ b/ltt-sessiond/session.c @@ -184,10 +184,7 @@ int destroy_session(char *name) int create_session(char *name, char *path) { int ret; - char date_time[NAME_MAX]; struct ltt_session *new_session; - time_t rawtime; - struct tm *timeinfo; new_session = find_session_by_name(name); if (new_session != NULL) { @@ -217,15 +214,7 @@ int create_session(char *name, char *path) /* Define session system path */ if (path != NULL) { - if (strstr(name, "auto-") == NULL) { - time(&rawtime); - timeinfo = localtime(&rawtime); - strftime(date_time, sizeof(date_time), "-%Y%m%d-%H%M%S", timeinfo); - } else { - date_time[0] = '\0'; - } - - if (asprintf(&new_session->path, "%s/%s%s", path, name, date_time) < 0) { + if (asprintf(&new_session->path, "%s", path) < 0) { ret = -ENOMEM; goto error_asprintf; } diff --git a/lttng/commands/create.c b/lttng/commands/create.c index dbed8f021..b8bbdb7e7 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -65,17 +65,23 @@ static void usage(FILE *ofp) static int create_session() { int ret, have_name = 0; - char name[NAME_MAX]; + char datetime[16]; char *session_name, *traces_path = NULL, *alloc_path = NULL; time_t rawtime; struct tm *timeinfo; + /* Get date and time for automatic session name/path */ + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo); + /* Auto session name creation */ if (opt_session_name == NULL) { - time(&rawtime); - timeinfo = localtime(&rawtime); - strftime(name, sizeof(name), "auto-%Y%m%d-%H%M%S", timeinfo); - session_name = name; + ret = asprintf(&session_name, "auto-%s", datetime); + if (ret < 0) { + perror("asprintf session name"); + goto error; + } DBG("Auto session name set to %s", session_name); } else { session_name = opt_session_name; @@ -92,7 +98,8 @@ static int create_session() goto error; } - ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME, alloc_path); + ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME + "/%s-%s", alloc_path, session_name, datetime); if (ret < 0) { perror("asprintf trace dir name"); goto error; @@ -117,7 +124,7 @@ static int create_session() MSG("Session %s created.", session_name); if (have_name) { - MSG("Traces will be written in %s/%s--