Clean-up: Remove ifdef-ed out lttng list options
[lttng-tools.git] / src / bin / lttng / commands / list.c
index 7c3211a5927ffc2c34a0f3f5e72528be8c8c4575..b436777d671b74bb2165d97eae9a5e6a1c6604e7 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <inttypes.h>
 #include <popt.h>
 #include <stdio.h>
@@ -36,11 +37,6 @@ static char *opt_channel;
 static int opt_domain;
 static int opt_fields;
 static int opt_syscall;
-#if 0
-/* Not implemented yet */
-static char *opt_cmd_name;
-static pid_t opt_pid;
-#endif
 
 const char *indent4 = "    ";
 const char *indent6 = "      ";
@@ -57,22 +53,16 @@ static struct mi_writer *writer;
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
-       {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
-       {"kernel",    'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
-       {"jul",       'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
-       {"log4j",     'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
-       {"python",    'p', POPT_ARG_VAL, &opt_python, 1, 0, 0},
-#if 0
-       /* Not implemented yet */
-       {"userspace",      'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
-       {"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
-#else
-       {"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
-#endif
-       {"channel",   'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
-       {"domain",    'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
-       {"fields",    'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
-       {"syscall",   'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0},
+       {"help",        'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"kernel",      'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
+       {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
+       {"log4j",       'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
+       {"python",      'p', POPT_ARG_VAL, &opt_python, 1, 0, 0},
+       {"userspace",   'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
+       {"channel",     'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
+       {"domain",      'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
+       {"fields",      'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
+       {"syscall",     'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0},
        {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
@@ -98,9 +88,6 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -p, --python            Apply for Python application using logging\n");
        fprintf(ofp, "  -f, --fields            List event fields.\n");
        fprintf(ofp, "      --syscall           List available system calls.\n");
-#if 0
-       fprintf(ofp, "  -p, --pid PID           List user-space events by PID\n");
-#endif
        fprintf(ofp, "\n");
        fprintf(ofp, "Session Options:\n");
        fprintf(ofp, "  -c, --channel NAME      List details of a channel\n");
@@ -128,14 +115,14 @@ static char *get_cmdline_by_pid(pid_t pid)
        }
 
        /* Caller must free() *cmdline */
-       cmdline = malloc(PATH_MAX);
+       cmdline = zmalloc(PATH_MAX);
        if (!cmdline) {
-               perror("malloc cmdline");
+               PERROR("malloc cmdline");
                goto end;
        }
        ret = fread(cmdline, 1, PATH_MAX, fp);
        if (ret < 0) {
-               perror("fread proc list");
+               PERROR("fread proc list");
        }
 
 end:
@@ -1207,7 +1194,7 @@ static int list_channels(const char *channel_name)
                }
        } else {
                /* Pretty print */
-               if (channel_name == NULL) {
+               if (count) {
                        MSG("Channels:\n-------------");
                }
 
@@ -1245,6 +1232,36 @@ error_channels:
        return ret;
 }
 
+/*
+ * List tracker PID(s) of session and domain.
+ */
+static int list_tracker_pids(void)
+{
+       int enabled, ret;
+       int *pids = NULL;
+       size_t nr_pids;
+
+       ret = lttng_list_tracker_pids(handle,
+               &enabled, &pids, &nr_pids);
+       if (ret) {
+               return ret;
+       }
+       if (enabled) {
+               int i;
+               _MSG("PID tracker: [");
+
+               for (i = 0; i < nr_pids; i++) {
+                       if (i) {
+                               _MSG(",");
+                       }
+                       _MSG(" %d", pids[i]);
+               }
+               _MSG(" ]\n\n");
+       }
+       free(pids);
+       return 0;
+}
+
 /*
  * Machine interface
  * Find the session with session_name as name
@@ -1377,8 +1394,11 @@ static int list_sessions(const char *session_name)
                                                active_string(sessions[i].enabled),
                                                snapshot_string(sessions[i].snapshot_mode));
                                MSG("%sTrace path: %s", indent4, sessions[i].path);
-                               MSG("%sLive timer interval (usec): %u\n", indent4,
-                                               sessions[i].live_timer_interval);
+                               if (sessions[i].live_timer_interval != 0) {
+                                       MSG("%sLive timer interval (usec): %u", indent4,
+                                                       sessions[i].live_timer_interval);
+                               }
+                               MSG("");
                        }
                }
 
@@ -1666,6 +1686,11 @@ int cmd_list(int argc, const char **argv)
 
                        }
 
+                       ret = list_tracker_pids();
+                       if (ret) {
+                               goto end;
+                       }
+
                        ret = list_channels(opt_channel);
                        if (ret) {
                                goto end;
@@ -1753,6 +1778,18 @@ int cmd_list(int argc, const char **argv)
                                        continue;
                                }
 
+                               switch (domains[i].type) {
+                               case LTTNG_DOMAIN_KERNEL:
+                               case LTTNG_DOMAIN_UST:
+                                       ret = list_tracker_pids();
+                                       if (ret) {
+                                               goto end;
+                                       }
+                                       break;
+                               default:
+                                       break;
+                               }
+
                                ret = list_channels(opt_channel);
                                if (ret) {
                                        goto end;
This page took 0.025036 seconds and 4 git commands to generate.