Fix: userspace probe accessors are not const-correct
[lttng-tools.git] / src / bin / lttng / commands / list.c
index e05134cbb2d518f6f1dbfcea9ffa0fc151fd71e8..eabeb8132ecd36c6e15fb996cb8bdba96b61249d 100644 (file)
@@ -249,6 +249,82 @@ end:
        return exclusion_msg;
 }
 
+static void print_userspace_probe_location(struct lttng_event *event)
+{
+       const struct lttng_userspace_probe_location *location;
+       const struct lttng_userspace_probe_location_lookup_method *lookup_method;
+       enum lttng_userspace_probe_location_lookup_method_type lookup_type;
+
+       location = lttng_event_get_userspace_probe_location(event);
+       if (!location) {
+               MSG("Event has no userspace probe location");
+               return;
+       }
+
+       lookup_method = lttng_userspace_probe_location_get_lookup_method(location);
+       if (!lookup_method) {
+               MSG("Event has no userspace probe location lookup method");
+               return;
+       }
+
+       MSG("%s%s (type: userspace-probe)%s", indent6, event->name, enabled_string(event->enabled));
+
+       lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method);
+
+       switch (lttng_userspace_probe_location_get_type(location)) {
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN:
+               MSG("%sType: Unknown", indent8);
+               break;
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+       {
+               const char *function_name;
+               const char *binary_path;
+
+               MSG("%sType: Function", indent8);
+               function_name = lttng_userspace_probe_location_function_get_function_name(location);
+               binary_path = realpath(lttng_userspace_probe_location_function_get_binary_path(location), NULL);
+
+               MSG("%sBinary path:   %s", indent8, binary_path ? binary_path : "NULL");
+               MSG("%sFunction:      %s()", indent8, function_name ? function_name : "NULL");
+               switch (lookup_type) {
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
+                       MSG("%sLookup method: ELF", indent8);
+                       break;
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT:
+                       MSG("%sLookup method: default", indent8);
+                       break;
+               default:
+                       MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8);
+                       break;
+               }
+               break;
+       }
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+       {
+               const char *probe_name, *provider_name;
+               const char *binary_path;
+
+               MSG("%sType: Tracepoint", indent8);
+               probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location);
+               provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location);
+               binary_path = realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location), NULL);
+               MSG("%sBinary path:   %s", indent8, binary_path ? binary_path : "NULL");
+               MSG("%sTracepoint:    %s:%s", indent8, provider_name ? provider_name : "NULL", probe_name ? probe_name : "NULL");
+               switch (lookup_type) {
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
+                       MSG("%sLookup method: SDT", indent8);
+                       break;
+               default:
+                       MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8);
+                       break;
+               }
+               break;
+       }
+       default:
+               ERR("Invalid probe type encountered");
+       }
+}
+
 /*
  * Pretty print single event.
  */
@@ -324,6 +400,9 @@ static void print_events(struct lttng_event *event)
                        MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
                }
                break;
+       case LTTNG_EVENT_USERSPACE_PROBE:
+               print_userspace_probe_location(event);
+               break;
        case LTTNG_EVENT_FUNCTION_ENTRY:
                MSG("%s%s (type: function)%s%s", indent6,
                                event->name, enabled_string(event->enabled),
@@ -343,6 +422,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;
@@ -1520,55 +1601,145 @@ 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 rotate settings (timer/size if any).
+ * List the automatic rotation settings.
  */
-static int list_rotate_settings(const char *session_name)
+static enum cmd_error_code list_rotate_settings(const char *session_name)
 {
        int ret;
-       uint64_t size, timer;
-
-       ret = lttng_rotation_schedule_get_timer_period(session_name, &timer);
-       if (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;
        }
 
-       ret = lttng_rotation_schedule_get_size(session_name, &size);
-       if (ret) {
+       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 (!timer && !size) {
-               ret = 0;
+       if (count == 0) {
+               cmd_ret = CMD_SUCCESS;
                goto end;
        }
 
-       _MSG("Automatic rotation schedule settings:\n");
-
-       if (timer) {
-               _MSG("    timer period: %" PRIu64" µs\n", timer);
-               if (lttng_opt_mi) {
-                       ret = mi_lttng_writer_write_element_unsigned_int(writer,
-                                       config_element_rotation_timer_interval, timer);
-                       if (ret) {
-                               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;
                }
        }
-       if (size) {
-               _MSG("    size threshold:  %" PRIu64" bytes\n", size);
+
+       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_writer_write_element_unsigned_int(writer,
-                                       config_element_rotation_size, size);
+                       ret = mi_lttng_rotation_schedule(writer, schedule);
                        if (ret) {
-                               goto end;
+                               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");
 
+       _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:
-       return ret;
+       lttng_rotation_schedules_destroy(schedules);
+       return cmd_ret;
 }
 
 /*
This page took 0.026735 seconds and 4 git commands to generate.