Use pipe instead of eventfd() for notification command queue
[lttng-tools.git] / src / bin / lttng / commands / list.c
index b122b5b789284ce78be1e1a327894575fe5dc023..8f07bb2da253e8de18c7aff280e5b472294f8112 100644 (file)
@@ -42,6 +42,12 @@ const char *indent4 = "    ";
 const char *indent6 = "      ";
 const char *indent8 = "        ";
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-list.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
@@ -51,6 +57,9 @@ enum {
 static struct lttng_handle *handle;
 static struct mi_writer *writer;
 
+/* Only set when listing a single session. */
+static struct lttng_session listed_session;
+
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",        'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
@@ -67,34 +76,6 @@ static struct poptOption long_options[] = {
        {0, 0, 0, 0, 0, 0, 0}
 };
 
-/*
- * usage
- */
-static void usage(FILE *ofp)
-{
-       fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "With no arguments, list available tracing session(s)\n");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "Without a session, -k lists available kernel events\n");
-       fprintf(ofp, "Without a session, -u lists available userspace events\n");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "  -h, --help              Show this help\n");
-       fprintf(ofp, "      --list-options      Simple listing of options\n");
-       fprintf(ofp, "  -k, --kernel            Select kernel domain\n");
-       fprintf(ofp, "  -u, --userspace         Select user-space domain.\n");
-       fprintf(ofp, "  -j, --jul               Apply for Java application using JUL\n");
-       fprintf(ofp, "  -l, --log4j             Apply for Java application using LOG4J\n");
-       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");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "Session Options:\n");
-       fprintf(ofp, "  -c, --channel NAME      List details of a channel\n");
-       fprintf(ofp, "  -d, --domain            List available domain(s)\n");
-       fprintf(ofp, "\n");
-}
-
 /*
  * Get command line from /proc for a specific pid.
  *
@@ -649,6 +630,8 @@ static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
        int event_element_open = 0;
        struct lttng_event cur_event;
 
+       memset(&cur_event, 0, sizeof(cur_event));
+
        /* Open domains element */
        ret = mi_lttng_domains_open(writer);
        if (ret) {
@@ -671,7 +654,6 @@ static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
                if (cur_pid != fields[i].event.pid) {
                        if (pid_element_open) {
                                if (event_element_open) {
-
                                        /* Close the previous field element and event. */
                                        ret = mi_lttng_close_multi_element(writer, 2);
                                        if (ret) {
@@ -1193,7 +1175,8 @@ error:
 static void print_channel(struct lttng_channel *channel)
 {
        int ret;
-       uint64_t discarded_events, lost_packets;
+       uint64_t discarded_events, lost_packets, monitor_timer_interval;
+       int64_t blocking_timeout;
 
        ret = lttng_channel_get_discarded_event_count(channel,
                        &discarded_events);
@@ -1209,18 +1192,32 @@ static void print_channel(struct lttng_channel *channel)
                return;
        }
 
+       ret = lttng_channel_get_monitor_timer_interval(channel,
+                       &monitor_timer_interval);
+       if (ret) {
+               ERR("Failed to retrieve monitor interval of channel");
+               return;
+       }
+
+       ret = lttng_channel_get_blocking_timeout(channel,
+                       &blocking_timeout);
+       if (ret) {
+               ERR("Failed to retrieve blocking timeout of channel");
+               return;
+       }
+
        MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
 
        MSG("%sAttributes:", indent4);
        MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
-       MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
-       MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
-       MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
-       MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
+       MSG("%ssubbuffers size: %" PRIu64 " bytes", indent6, channel->attr.subbuf_size);
+       MSG("%snumber of subbuffers: %" PRIu64, indent6, channel->attr.num_subbuf);
+       MSG("%sswitch timer interval: %u µs", indent6, channel->attr.switch_timer_interval);
+       MSG("%sread timer interval: %u µs", indent6, channel->attr.read_timer_interval);
+       MSG("%smonitor timer interval: %" PRIu64 " µs", indent6, monitor_timer_interval);
+       MSG("%sblocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
        MSG("%strace file count: %" PRIu64, indent6, channel->attr.tracefile_count);
-       MSG("%strace file size (bytes): %" PRIu64, indent6, channel->attr.tracefile_size);
-       MSG("%sdiscarded events: %" PRIu64, indent6, discarded_events);
-       MSG("%slost packets: %" PRIu64, indent6, lost_packets);
+       MSG("%strace file size: %" PRIu64 " bytes", indent6, channel->attr.tracefile_size);
        switch (channel->attr.output) {
                case LTTNG_EVENT_SPLICE:
                        MSG("%soutput: splice()", indent6);
@@ -1229,6 +1226,31 @@ static void print_channel(struct lttng_channel *channel)
                        MSG("%soutput: mmap()", indent6);
                        break;
        }
+
+       if (!listed_session.snapshot_mode) {
+               /*
+                * The lost packet count is omitted for sessions in snapshot
+                * mode as it is misleading: it would indicate the number of
+                * packets that the consumer could not extract during the
+                * course of recording the snapshot. It does not have the
+                * same meaning as the "regular" lost packet count that
+                * would result from the consumer not keeping up with
+                * event production in an overwrite-mode channel.
+                *
+                * A more interesting statistic would be the number of
+                * packets lost between the first and last extracted
+                * packets of a given snapshot (which prevents most analyses).
+                */
+               goto skip_stats_printing;
+       }
+
+       if (!channel->attr.overwrite) {
+               MSG("%sdiscarded events: %" PRIu64, indent6, discarded_events);
+       } else {
+               MSG("%slost packets: %" PRIu64, indent6, lost_packets);
+       }
+skip_stats_printing:
+       return;
 }
 
 /*
@@ -1588,6 +1610,8 @@ static int list_sessions(const char *session_name)
                                                        active_string(sessions[i].enabled),
                                                        snapshot_string(sessions[i].snapshot_mode));
                                        MSG("%sTrace path: %s\n", indent4, sessions[i].path);
+                                       memcpy(&listed_session, &sessions[i],
+                                                       sizeof(listed_session));
                                        break;
                                }
                        } else {
@@ -1597,7 +1621,7 @@ static int list_sessions(const char *session_name)
                                                snapshot_string(sessions[i].snapshot_mode));
                                MSG("%sTrace path: %s", indent4, sessions[i].path);
                                if (sessions[i].live_timer_interval != 0) {
-                                       MSG("%sLive timer interval (usec): %u", indent4,
+                                       MSG("%sLive timer interval: %u µs", indent4,
                                                        sessions[i].live_timer_interval);
                                }
                                MSG("");
@@ -1726,7 +1750,6 @@ int cmd_list(int argc, const char **argv)
        memset(&domain, 0, sizeof(domain));
 
        if (argc < 1) {
-               usage(stderr);
                ret = CMD_ERROR;
                goto end;
        }
@@ -1737,7 +1760,7 @@ int cmd_list(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_USERSPACE:
                        opt_userspace = 1;
@@ -1746,7 +1769,6 @@ int cmd_list(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                default:
-                       usage(stderr);
                        ret = CMD_UNDEFINED;
                        goto end;
                }
This page took 0.026022 seconds and 4 git commands to generate.