Implement userspace probe location extraction and registration
[lttng-tools.git] / src / bin / lttng / commands / list.c
index 8f07bb2da253e8de18c7aff280e5b472294f8112..4a94690b038b4ca20fe9839a01c51637bc457ceb 100644 (file)
@@ -343,6 +343,8 @@ static void print_events(struct lttng_event *event)
                                safe_string(filter_msg));
                break;
        case LTTNG_EVENT_ALL:
+               /* Fall-through. */
+       default:
                /* We should never have "all" events in list. */
                assert(0);
                break;
@@ -1151,7 +1153,7 @@ static int list_events(const char *channel_name)
                }
        } else {
                /* Pretty print */
-               MSG("\n%sEvents:", indent4);
+               MSG("\n%sEvent rules:", indent4);
                if (count == 0) {
                        MSG("%sNone\n", indent6);
                        goto end;
@@ -1169,6 +1171,23 @@ error:
        return ret;
 }
 
+static
+void print_timer(const char *timer_name, uint32_t space_count, int64_t value)
+{
+       uint32_t i;
+
+       _MSG("%s%s:", indent6, timer_name);
+       for (i = 0; i < space_count; i++) {
+               _MSG(" ");
+       }
+
+       if (value) {
+               MSG("%" PRId64 " µs", value);
+       } else {
+               MSG("inactive");
+       }
+}
+
 /*
  * Pretty print channel
  */
@@ -1207,27 +1226,43 @@ static void print_channel(struct lttng_channel *channel)
        }
 
        MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
-
        MSG("%sAttributes:", indent4);
-       MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
-       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: %" PRIu64 " bytes", indent6, channel->attr.tracefile_size);
+       MSG("%sEvent-loss mode:  %s", indent6, channel->attr.overwrite ? "overwrite" : "discard");
+       MSG("%sSub-buffer size:  %" PRIu64 " bytes", indent6, channel->attr.subbuf_size);
+       MSG("%sSub-buffer count: %" PRIu64, indent6, channel->attr.num_subbuf);
+
+       print_timer("Switch timer", 5, channel->attr.switch_timer_interval);
+       print_timer("Read timer",  7, channel->attr.read_timer_interval);
+       print_timer("Monitor timer", 4, monitor_timer_interval);
+
+       if (!channel->attr.overwrite) {
+               if (blocking_timeout == -1) {
+                       MSG("%sBlocking timeout: infinite", indent6);
+               } else {
+                       MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
+               }
+       }
+
+       MSG("%sTrace file count: %" PRIu64 " per stream", indent6,
+                       channel->attr.tracefile_count == 0 ?
+                               1 : channel->attr.tracefile_count);
+       if (channel->attr.tracefile_size != 0 ) {
+               MSG("%sTrace file size:  %" PRIu64 " bytes", indent6,
+                               channel->attr.tracefile_size);
+       } else {
+               MSG("%sTrace file size:  %s", indent6, "unlimited");
+       }
        switch (channel->attr.output) {
                case LTTNG_EVENT_SPLICE:
-                       MSG("%soutput: splice()", indent6);
+                       MSG("%sOutput mode:      splice", indent6);
                        break;
                case LTTNG_EVENT_MMAP:
-                       MSG("%soutput: mmap()", indent6);
+                       MSG("%sOutput mode:      mmap", indent6);
                        break;
        }
 
-       if (!listed_session.snapshot_mode) {
+       MSG("\n%sStatistics:", indent4);
+       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
@@ -1241,13 +1276,14 @@ static void print_channel(struct lttng_channel *channel)
                 * packets lost between the first and last extracted
                 * packets of a given snapshot (which prevents most analyses).
                 */
+               MSG("%sNone", indent6);
                goto skip_stats_printing;
        }
 
        if (!channel->attr.overwrite) {
-               MSG("%sdiscarded events: %" PRIu64, indent6, discarded_events);
+               MSG("%sDiscarded events: %" PRIu64, indent6, discarded_events);
        } else {
-               MSG("%slost packets: %" PRIu64, indent6, lost_packets);
+               MSG("%sLost packets:     %" PRIu64, indent6, lost_packets);
        }
 skip_stats_printing:
        return;
@@ -1486,6 +1522,147 @@ end:
        return ret;
 }
 
+static enum cmd_error_code print_periodic_rotation_schedule(
+               const struct lttng_rotation_schedule *schedule)
+{
+       enum cmd_error_code ret;
+       enum lttng_rotation_status status;
+       uint64_t value;
+
+       status = lttng_rotation_schedule_periodic_get_period(schedule,
+                       &value);
+       if (status != LTTNG_ROTATION_STATUS_OK) {
+               ERR("Failed to retrieve period parameter from periodic rotation schedule.");
+               ret = CMD_ERROR;
+               goto end;
+       }
+
+       MSG("    timer period: %" PRIu64" µs", value);
+       ret = CMD_SUCCESS;
+end:
+       return ret;
+}
+
+static enum cmd_error_code print_size_threshold_rotation_schedule(
+               const struct lttng_rotation_schedule *schedule)
+{
+       enum cmd_error_code ret;
+       enum lttng_rotation_status status;
+       uint64_t value;
+
+       status = lttng_rotation_schedule_size_threshold_get_threshold(schedule,
+                       &value);
+       if (status != LTTNG_ROTATION_STATUS_OK) {
+               ERR("Failed to retrieve size parameter from size-based rotation schedule.");
+               ret = CMD_ERROR;
+               goto end;
+       }
+
+       MSG("    size threshold: %" PRIu64" bytes", value);
+       ret = CMD_SUCCESS;
+end:
+       return ret;
+}
+
+static enum cmd_error_code print_rotation_schedule(
+               const struct lttng_rotation_schedule *schedule)
+{
+       enum cmd_error_code ret;
+
+       switch (lttng_rotation_schedule_get_type(schedule)) {
+       case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD:
+               ret = print_size_threshold_rotation_schedule(schedule);
+               break;
+       case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC:
+               ret = print_periodic_rotation_schedule(schedule);
+               break;
+       default:
+               ret = CMD_ERROR;
+       }
+       return ret;
+}
+
+/*
+ * List the automatic rotation settings.
+ */
+static enum cmd_error_code list_rotate_settings(const char *session_name)
+{
+       int ret;
+       enum cmd_error_code cmd_ret = CMD_SUCCESS;
+       unsigned int count, i;
+       struct lttng_rotation_schedules *schedules = NULL;
+       enum lttng_rotation_status status;
+
+       ret = lttng_session_list_rotation_schedules(session_name, &schedules);
+       if (ret != LTTNG_OK) {
+               ERR("Failed to list session rotation schedules: %s", lttng_strerror(ret));
+               cmd_ret = CMD_ERROR;
+               goto end;
+       }
+
+       status = lttng_rotation_schedules_get_count(schedules, &count);
+       if (status != LTTNG_ROTATION_STATUS_OK) {
+               ERR("Failed to retrieve the number of session rotation schedules.");
+               cmd_ret = CMD_ERROR;
+               goto end;
+       }
+
+       if (count == 0) {
+               cmd_ret = CMD_SUCCESS;
+               goto end;
+       }
+
+       MSG("Automatic rotation schedules:");
+       if (lttng_opt_mi) {
+               ret = mi_lttng_writer_open_element(writer,
+                               mi_lttng_element_rotation_schedules);
+               if (ret) {
+                       cmd_ret = CMD_ERROR;
+                       goto end;
+               }
+       }
+
+       for (i = 0; i < count; i++) {
+               enum cmd_error_code tmp_ret = CMD_SUCCESS;
+               const struct lttng_rotation_schedule *schedule;
+
+               schedule = lttng_rotation_schedules_get_at_index(schedules, i);
+               if (!schedule) {
+                       ERR("Failed to retrieve session rotation schedule.");
+                       cmd_ret = CMD_ERROR;
+                       goto end;
+               }
+
+               if (lttng_opt_mi) {
+                       ret = mi_lttng_rotation_schedule(writer, schedule);
+                       if (ret) {
+                               tmp_ret = CMD_ERROR;
+                       }
+               } else {
+                       tmp_ret = print_rotation_schedule(schedule);
+               }
+
+               /*
+                * Report an error if the serialization of any of the
+                * descriptors failed.
+                */
+               cmd_ret = cmd_ret ? cmd_ret : tmp_ret;
+       }
+
+       _MSG("\n");
+       if (lttng_opt_mi) {
+               /* Close the rotation_schedules element. */
+               ret = mi_lttng_writer_close_element(writer);
+               if (ret) {
+                       cmd_ret = CMD_ERROR;
+                       goto end;
+               }
+       }
+end:
+       lttng_rotation_schedules_destroy(schedules);
+       return cmd_ret;
+}
+
 /*
  * Machine interface
  * Find the session with session_name as name
@@ -1742,7 +1919,7 @@ end:
 int cmd_list(int argc, const char **argv)
 {
        int opt, ret = CMD_SUCCESS;
-       const char *session_name;
+       const char *session_name, *leftover = NULL;
        static poptContext pc;
        struct lttng_domain domain;
        struct lttng_domain *domains = NULL;
@@ -1803,6 +1980,13 @@ int cmd_list(int argc, const char **argv)
        session_name = poptGetArg(pc);
        DBG2("Session name: %s", session_name);
 
+       leftover = poptGetArg(pc);
+       if (leftover) {
+               ERR("Unknown argument: %s", leftover);
+               ret = CMD_ERROR;
+               goto end;
+       }
+
        if (opt_kernel) {
                domain.type = LTTNG_DOMAIN_KERNEL;
        } else if (opt_userspace) {
@@ -1884,6 +2068,11 @@ int cmd_list(int argc, const char **argv)
                        goto end;
                }
 
+               ret = list_rotate_settings(session_name);
+               if (ret) {
+                       goto end;
+               }
+
                /* Domain listing */
                if (opt_domain) {
                        ret = list_domains(session_name);
This page took 0.027274 seconds and 4 git commands to generate.