Add listing session option
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 21 Apr 2011 18:50:18 +0000 (14:50 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 21 Apr 2011 18:52:02 +0000 (14:52 -0400)
The lttng client can now list available sessions using the liblttngctl
API and session daemon support.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
include/lttng/liblttngctl.h
liblttngctl/liblttngctl.c
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/ltt-sessiond.c
lttng/lttng.c
lttng/lttng.h
lttng/options.c

index eadc74a606d0da95fef91ccf1eca3e20c45c980c..ea6d001e1c58053d00575ecd1fab339c29c71cc7 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef _LIBLTTNGCTL_H
 #define _LIBLTTNGCTL_H
 
+#include <limits.h>
+
 /* Default unix group name for tracing.
  */
 #define DEFAULT_TRACING_GROUP "tracing"
  */
 #define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
 
-/* 
- * From libuuid
+/* From libuuid
  */
 #define UUID_STR_LEN 37
 
+/* Simple structure representing a session.
+ */
+struct lttng_session {
+       char name[NAME_MAX];
+       char uuid[UUID_STR_LEN];
+};
+
 extern int lttng_create_session(const char *name, char *session_id);
 extern int lttng_connect_sessiond(void);
 extern int lttng_set_tracing_group(const char *name);
 extern int lttng_check_session_daemon(void);
 extern const char *lttng_get_readable_code(int code);
 extern size_t lttng_ust_list_apps(pid_t **pids);
+extern size_t lttng_list_sessions(struct lttng_session **sessions);
 
 #endif /* _LIBLTTNGCTL_H */
index d8481496d042b6c3c2b2c9375edf9c374e1a0aae..658f646f0fe7fc4c49e21d3917b7b08592959def 100644 (file)
@@ -201,6 +201,51 @@ error:
        return ret;
 }
 
+/*
+ *  lttng_list_sessions
+ *
+ *  Ask the session daemon for all available sessions.
+ *
+ *  Return number of sessions
+ */
+size_t lttng_list_sessions(struct lttng_session **sessions)
+{
+       int ret, first = 0;
+       size_t size = 0;
+       struct lttng_session *ls = NULL;
+
+       lsm.cmd_type = LTTNG_LIST_SESSIONS;
+
+       ret = ask_sessiond();
+       if (ret < 0) {
+               goto error;
+       }
+
+       do {
+               ret = recvfrom_sessiond();
+               if (ret < 0) {
+                       goto error;
+               }
+
+               if (first == 0) {
+                       first = 1;
+                       size = llm.num_pckt;
+                       ls = malloc(sizeof(struct lttng_session) * size);
+               }
+               strncpy(ls[size - llm.num_pckt].name, llm.u.list_sessions.name,
+                               sizeof(ls[size - llm.num_pckt].name));
+               strncpy(ls[size - llm.num_pckt].uuid, llm.u.list_sessions.uuid,
+                               sizeof(ls[size - llm.num_pckt].uuid));
+       } while ((llm.num_pckt - 1) != 0);
+
+       *sessions = ls;
+
+       return size;
+
+error:
+       return ret;
+}
+
 /*
  *  lttng_connect_sessiond
  *
index d2d22bc5d69ca1946ae6270c30cdb889c5da5661..adae8410401ba41c19ef4176e8b6aea45cc8a443 100644 (file)
@@ -39,6 +39,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESSION) ] = "No session found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_LIST_FAIL) ] = "Unable to list traceable apps",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found",
 };
 
 /*
index 84385ce71d077de12bdccfa95f4d787d931afb30..f4180cf0a4cd65413b46f6e6f575068cdf7cac02 100644 (file)
@@ -74,6 +74,7 @@ enum lttcomm_return_code {
        LTTCOMM_START_FAIL,             /* Start tracing fail */
        LTTCOMM_LIST_FAIL,              /* Listing apps fail */
        LTTCOMM_NO_APPS,                /* No traceable application */
+       LTTCOMM_NO_SESS,                /* No sessions available */
        LTTCOMM_NR,                             /* Last element */
 };
 
@@ -132,6 +133,11 @@ struct lttcomm_lttng_msg {
                struct {
                        pid_t pid;
                } list_apps;
+               /* LTTNG_LIST_SESSIONS */
+               struct {
+                       char name[NAME_MAX];
+                       char uuid[37];  /* See libuuid not exported size UUID_STR_LEN */
+               } list_sessions;
        } u;
 };
 
index 050c67397345eb0fa97a04239342959364926d90..f257ddb0904de50d1eb2ab83c7db2f95c4bd6f29 100644 (file)
@@ -56,6 +56,7 @@ static int connect_app(pid_t);
 static int init_daemon_socket(void);
 static int process_client_msg(int sock, struct lttcomm_session_msg*);
 static int send_unix_sock(int sock, void *buf, size_t len);
+static size_t ust_list_apps(pid_t **pids);
 
 static void *thread_manage_clients(void *);
 static void *thread_manage_apps(void *);
@@ -487,6 +488,29 @@ static int process_client_msg(int sock, struct lttcomm_session_msg *lsm)
 
                        break;
                }
+               case LTTNG_LIST_SESSIONS:
+               {
+                       struct ltt_session *iter = NULL;
+
+                       llm.num_pckt = session_count;
+                       if (llm.num_pckt == 0) {
+                               ret = LTTCOMM_NO_SESS;
+                               goto error;
+                       }
+
+                       cds_list_for_each_entry(iter, &ltt_session_list.head, list) {
+                               uuid_unparse(iter->uuid, llm.u.list_sessions.uuid);
+                               strncpy(llm.u.list_sessions.name, iter->name,
+                                               sizeof(llm.u.list_sessions.name));
+                               ret = send_unix_sock(sock, (void*) &llm, sizeof(llm));
+                               if (ret < 0) {
+                                       goto send_error;
+                               }
+                               llm.num_pckt--;
+                       }
+
+                       break;
+               }
                default:
                {
                        /* Undefined command */
index 907984370edf7831e4fdb5b0f8a135345d58b357..095ebe5e1c898343b86d177bfd39a926115b3090 100644 (file)
@@ -41,6 +41,7 @@ static char *progname;
 /* Prototypes */
 static int process_client_opt(void);
 static int process_opt_list_apps(void);
+static int process_opt_list_sessions(void);
 static void sighandler(int sig);
 static int set_signal_handler(void);
 
@@ -68,6 +69,13 @@ static int process_client_opt(void)
                }
        }
 
+       if (opt_list_session) {
+               ret = process_opt_list_sessions();
+               if (ret < 0) {
+                       goto end;
+               }
+       }
+
        return 0;
 
 end:
@@ -75,6 +83,37 @@ end:
        return ret;
 }
 
+/*
+ *  process_opt_list_sessions
+ *
+ *  Get the list of available sessions from
+ *  the session daemon and print it to user.
+ */
+static int process_opt_list_sessions(void)
+{
+       int ret, count, i;
+       struct lttng_session *sess;
+
+       count = lttng_list_sessions(&sess);
+       if (count < 0) {
+               ret = count;
+               goto error;
+       }
+
+       MSG("Available sessions [Name (uuid)]:");
+       for (i = 0; i < count; i++) {
+               MSG("\tName: %s (uuid: %s)", sess[i].name, sess[i].uuid);
+       }
+
+       free(sess);
+       MSG("\nTo select a session, use --session UUID.");
+
+       return 0;
+
+error:
+       return ret;
+}
+
 /*
  *  process_opt_list_apps
  *
index 4a4d181d5b473bd0ff25c5284fd3bc2296971b8b..be32bf7efa50bd179b181dbc5b1487c7a9d164a7 100644 (file)
@@ -31,6 +31,7 @@ extern char *opt_session_name;
 extern char *opt_sessiond_path;
 extern int opt_list_apps;
 extern int opt_no_sessiond;
+extern int opt_list_session;
 
 #define SESSIOND_PATH_NUM 6
 
index ee13f120bf16fee21c4bcb0b9da7d76ea70d05a9..78e1764f9196091f6be3905b5aa3cab4f8d66417 100644 (file)
@@ -30,6 +30,7 @@ int opt_quiet = 0;
 int opt_verbose = 0;
 int opt_list_apps = 0;
 int opt_no_sessiond = 0;
+int opt_list_session = 0;
 
 enum {
        OPT_HELP = 42,
@@ -47,6 +48,7 @@ static struct poptOption long_options[] = {
        {"list-apps",           'l',    POPT_ARG_VAL,           &opt_list_apps, 1, 0},
        {"no-sessiond",         0,              POPT_ARG_VAL,           &opt_no_sessiond, 1, 0},
        {"sessiond-path",       0,              POPT_ARG_STRING,        &opt_sessiond_path, 0, 0},
+       {"list-session",        0,              POPT_ARG_VAL,           &opt_list_session, 1, 0},
        {0, 0, 0, 0, 0, 0}
 };
 
@@ -67,6 +69,9 @@ static void usage(FILE *ofp)
        fprintf(ofp, "      --no-sessiond       Don't spawn a session daemon.\n");
        fprintf(ofp, "      --sessiond-path     Session daemon full path\n");
        fprintf(ofp, "\n");
+       fprintf(ofp, "Session options:\n");
+       fprintf(ofp, "      --list-session      List all available sessions\n");
+       fprintf(ofp, "\n");
        fprintf(ofp, "Tracing options:\n");
        //fprintf(ofp, "      --session [NAME]    Specify tracing session. If no NAME is given\n");
        //fprintf(ofp, "                          or option is ommited, a session will be created\n");
This page took 0.031399 seconds and 4 git commands to generate.