2 * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
10 #include "../command.h"
12 #include "common/argpar/argpar.h"
13 #include "common/dynamic-array.h"
14 #include "common/mi-lttng.h"
15 /* For lttng_condition_type_str(). */
16 #include "lttng/condition/condition-internal.h"
17 #include "lttng/condition/event-rule-matches.h"
18 #include "lttng/condition/event-rule-matches-internal.h"
19 /* For lttng_domain_type_str(). */
20 #include "lttng/domain-internal.h"
21 /* For lttng_event_rule_syscall_emission_site_str() */
22 #include "lttng/event-rule/syscall-internal.h"
23 #include "../loglevel.h"
24 #include <lttng/lttng.h>
26 #ifdef LTTNG_EMBED_HELP
27 static const char help_msg
[] =
28 #include <lttng-list-triggers.1.h>
38 struct argpar_opt_descr list_trigger_options
[] = {
39 { OPT_HELP
, 'h', "help", false },
40 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
41 ARGPAR_OPT_DESCR_SENTINEL
,
44 static void print_condition_session_consumed_size(
45 const struct lttng_condition
*condition
)
47 enum lttng_condition_status condition_status
;
48 const char *session_name
;
52 lttng_condition_session_consumed_size_get_session_name(
53 condition
, &session_name
);
54 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
56 lttng_condition_session_consumed_size_get_threshold(
57 condition
, &threshold
);
58 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
60 MSG(" session name: %s", session_name
);
61 MSG(" threshold: %" PRIu64
" bytes", threshold
);
64 static void print_condition_buffer_usage(
65 const struct lttng_condition
*condition
)
67 enum lttng_condition_status condition_status
;
68 const char *session_name
, *channel_name
;
69 enum lttng_domain_type domain_type
;
72 condition_status
= lttng_condition_buffer_usage_get_session_name(
73 condition
, &session_name
);
74 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
76 condition_status
= lttng_condition_buffer_usage_get_channel_name(
77 condition
, &channel_name
);
78 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
80 condition_status
= lttng_condition_buffer_usage_get_domain_type(
81 condition
, &domain_type
);
82 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
84 MSG(" session name: %s", session_name
);
85 MSG(" channel name: %s", channel_name
);
86 MSG(" domain: %s", lttng_domain_type_str(domain_type
));
88 condition_status
= lttng_condition_buffer_usage_get_threshold(
89 condition
, &threshold
);
90 if (condition_status
== LTTNG_CONDITION_STATUS_OK
) {
91 MSG(" threshold (bytes): %" PRIu64
, threshold
);
93 double threshold_ratio
;
95 assert(condition_status
== LTTNG_CONDITION_STATUS_UNSET
);
98 lttng_condition_buffer_usage_get_threshold_ratio(
99 condition
, &threshold_ratio
);
100 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
102 MSG(" threshold (ratio): %.2f", threshold_ratio
);
106 static void print_condition_session_rotation(
107 const struct lttng_condition
*condition
)
109 enum lttng_condition_status condition_status
;
110 const char *session_name
;
112 condition_status
= lttng_condition_session_rotation_get_session_name(
113 condition
, &session_name
);
114 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
116 MSG(" session name: %s", session_name
);
120 * Returns the human-readable log level name associated with a numerical value
121 * if there is one. The Log4j and JUL domains have discontinuous log level
122 * values (a value can fall between two labels). In those cases, NULL is
125 static const char *get_pretty_loglevel_name(
126 enum lttng_domain_type domain
, int loglevel
)
128 const char *name
= NULL
;
131 case LTTNG_DOMAIN_UST
:
132 name
= loglevel_value_to_name(loglevel
);
134 case LTTNG_DOMAIN_LOG4J
:
135 name
= loglevel_log4j_value_to_name(loglevel
);
137 case LTTNG_DOMAIN_JUL
:
138 name
= loglevel_jul_value_to_name(loglevel
);
140 case LTTNG_DOMAIN_PYTHON
:
141 name
= loglevel_python_value_to_name(loglevel
);
151 void print_event_rule_tracepoint(const struct lttng_event_rule
*event_rule
)
153 enum lttng_event_rule_status event_rule_status
;
154 enum lttng_domain_type domain_type
;
158 const struct lttng_log_level_rule
*log_level_rule
= NULL
;
159 unsigned int exclusions_count
;
162 event_rule_status
= lttng_event_rule_tracepoint_get_name_pattern(
163 event_rule
, &pattern
);
164 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
166 event_rule_status
= lttng_event_rule_tracepoint_get_domain_type(
167 event_rule
, &domain_type
);
168 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
170 _MSG(" rule: %s (type: tracepoint, domain: %s", pattern
,
171 lttng_domain_type_str(domain_type
));
173 event_rule_status
= lttng_event_rule_tracepoint_get_filter(
174 event_rule
, &filter
);
175 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
176 _MSG(", filter: %s", filter
);
178 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
181 event_rule_status
= lttng_event_rule_tracepoint_get_log_level_rule(
182 event_rule
, &log_level_rule
);
183 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
184 enum lttng_log_level_rule_status llr_status
;
185 const char *log_level_op
;
186 const char *pretty_loglevel_name
;
188 switch (lttng_log_level_rule_get_type(log_level_rule
)) {
189 case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY
:
191 llr_status
= lttng_log_level_rule_exactly_get_level(
192 log_level_rule
, &log_level
);
194 case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS
:
195 log_level_op
= "at least";
196 llr_status
= lttng_log_level_rule_at_least_as_severe_as_get_level(
197 log_level_rule
, &log_level
);
203 assert(llr_status
== LTTNG_LOG_LEVEL_RULE_STATUS_OK
);
205 pretty_loglevel_name
= get_pretty_loglevel_name(
206 domain_type
, log_level
);
207 if (pretty_loglevel_name
) {
208 _MSG(", log level %s %s", log_level_op
,
209 pretty_loglevel_name
);
211 _MSG(", log level %s %d", log_level_op
, log_level
);
214 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
217 event_rule_status
= lttng_event_rule_tracepoint_get_name_pattern_exclusion_count(
218 event_rule
, &exclusions_count
);
219 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
220 if (exclusions_count
> 0) {
221 _MSG(", exclusions: ");
222 for (i
= 0; i
< exclusions_count
; i
++) {
223 const char *exclusion
;
225 event_rule_status
= lttng_event_rule_tracepoint_get_name_pattern_exclusion_at_index(
226 event_rule
, i
, &exclusion
);
227 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
229 _MSG("%s%s", i
> 0 ? "," : "", exclusion
);
236 static void print_kernel_probe_location(
237 const struct lttng_kernel_probe_location
*location
)
239 enum lttng_kernel_probe_location_status status
;
240 switch (lttng_kernel_probe_location_get_type(location
)) {
241 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
:
245 status
= lttng_kernel_probe_location_address_get_address(
247 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
248 ERR("Getting kernel probe location address failed.");
252 _MSG("0x%" PRIx64
, address
);
256 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
:
259 const char *symbol_name
;
261 symbol_name
= lttng_kernel_probe_location_symbol_get_name(
264 ERR("Getting kernel probe location symbol name failed.");
268 status
= lttng_kernel_probe_location_symbol_get_offset(
270 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
271 ERR("Getting kernel probe location address failed.");
276 _MSG("%s", symbol_name
);
278 _MSG("%s+0x%" PRIx64
, symbol_name
, offset
);
291 void print_event_rule_kernel_probe(const struct lttng_event_rule
*event_rule
)
293 enum lttng_event_rule_status event_rule_status
;
295 const struct lttng_kernel_probe_location
*location
;
297 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
);
299 event_rule_status
= lttng_event_rule_kernel_probe_get_event_name(event_rule
, &name
);
300 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
301 ERR("Failed to get kprobe event rule's name.");
305 event_rule_status
= lttng_event_rule_kernel_probe_get_location(
306 event_rule
, &location
);
307 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
308 ERR("Failed to get kprobe event rule's location.");
312 _MSG(" rule: %s (type: probe, location: ", name
);
314 print_kernel_probe_location(location
);
323 void print_event_rule_userspace_probe(const struct lttng_event_rule
*event_rule
)
325 enum lttng_event_rule_status event_rule_status
;
327 const struct lttng_userspace_probe_location
*location
;
328 enum lttng_userspace_probe_location_type userspace_probe_location_type
;
330 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
);
332 event_rule_status
= lttng_event_rule_userspace_probe_get_event_name(
334 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
335 ERR("Failed to get uprobe event rule's name.");
339 event_rule_status
= lttng_event_rule_userspace_probe_get_location(
340 event_rule
, &location
);
341 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
342 ERR("Failed to get uprobe event rule's location.");
346 _MSG(" rule: %s (type: userspace probe, ", name
);
348 userspace_probe_location_type
=
349 lttng_userspace_probe_location_get_type(location
);
351 switch (userspace_probe_location_type
) {
352 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
354 const char *binary_path
, *function_name
;
356 binary_path
= lttng_userspace_probe_location_function_get_binary_path(
358 function_name
= lttng_userspace_probe_location_function_get_function_name(
361 _MSG("location type: ELF, location: %s:%s", binary_path
, function_name
);
364 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
366 const char *binary_path
, *provider_name
, *probe_name
;
368 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(
370 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(
372 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(
374 _MSG("location type: SDT, location: %s:%s:%s", binary_path
, provider_name
, probe_name
);
388 void print_event_rule_syscall(const struct lttng_event_rule
*event_rule
)
390 const char *pattern
, *filter
;
391 enum lttng_event_rule_status event_rule_status
;
392 enum lttng_event_rule_syscall_emission_site emission_site
;
394 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_SYSCALL
);
397 lttng_event_rule_syscall_get_emission_site(event_rule
);
399 event_rule_status
= lttng_event_rule_syscall_get_name_pattern(
400 event_rule
, &pattern
);
401 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
403 _MSG(" rule: %s (type: syscall:%s", pattern
,
404 lttng_event_rule_syscall_emission_site_str(
407 event_rule_status
= lttng_event_rule_syscall_get_filter(
408 event_rule
, &filter
);
409 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
410 _MSG(", filter: %s", filter
);
412 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
419 void print_event_rule(const struct lttng_event_rule
*event_rule
)
421 const enum lttng_event_rule_type event_rule_type
=
422 lttng_event_rule_get_type(event_rule
);
424 switch (event_rule_type
) {
425 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
426 print_event_rule_tracepoint(event_rule
);
428 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
429 print_event_rule_kernel_probe(event_rule
);
431 case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
:
432 print_event_rule_userspace_probe(event_rule
);
434 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
435 print_event_rule_syscall(event_rule
);
443 void print_one_event_expr(const struct lttng_event_expr
*event_expr
)
445 enum lttng_event_expr_type type
;
447 type
= lttng_event_expr_get_type(event_expr
);
450 case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD
:
454 name
= lttng_event_expr_event_payload_field_get_name(
460 case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD
:
464 name
= lttng_event_expr_channel_context_field_get_name(
466 _MSG("$ctx.%s", name
);
470 case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD
:
472 const char *provider_name
;
473 const char *type_name
;
475 provider_name
= lttng_event_expr_app_specific_context_field_get_provider_name(
477 type_name
= lttng_event_expr_app_specific_context_field_get_type_name(
480 _MSG("$app.%s:%s", provider_name
, type_name
);
484 case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT
:
487 const struct lttng_event_expr
*parent_expr
;
488 enum lttng_event_expr_status status
;
490 parent_expr
= lttng_event_expr_array_field_element_get_parent_expr(
492 assert(parent_expr
!= NULL
);
494 print_one_event_expr(parent_expr
);
496 status
= lttng_event_expr_array_field_element_get_index(
498 assert(status
== LTTNG_EVENT_EXPR_STATUS_OK
);
509 static void print_condition_event_rule_matches(
510 const struct lttng_condition
*condition
)
512 const struct lttng_event_rule
*event_rule
;
513 enum lttng_condition_status condition_status
;
514 unsigned int cap_desc_count
, i
;
516 condition_status
= lttng_condition_event_rule_matches_get_rule(
517 condition
, &event_rule
);
518 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
520 print_event_rule(event_rule
);
523 lttng_condition_event_rule_matches_get_capture_descriptor_count(
524 condition
, &cap_desc_count
);
525 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
527 if (cap_desc_count
> 0) {
530 for (i
= 0; i
< cap_desc_count
; i
++) {
531 const struct lttng_event_expr
*cap_desc
=
532 lttng_condition_event_rule_matches_get_capture_descriptor_at_index(
536 print_one_event_expr(cap_desc
);
542 static void print_action_errors(const struct lttng_trigger
*trigger
,
543 const struct lttng_action
*action
,
544 const uint64_t *action_path_indexes
,
545 size_t action_path_length
)
547 unsigned int i
, count
, printed_errors_count
= 0;
548 enum lttng_error_code error_query_ret
;
549 enum lttng_error_query_results_status results_status
;
550 struct lttng_error_query_results
*results
= NULL
;
551 const char *trigger_name
;
553 enum lttng_trigger_status trigger_status
;
554 struct lttng_error_query
*query
;
555 struct lttng_action_path
*action_path
= lttng_action_path_create(
556 action_path_indexes
, action_path_length
);
560 query
= lttng_error_query_action_create(trigger
, action_path
);
563 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
565 * Anonymous triggers are not listed; this would be an internal error.
567 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
569 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
570 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
572 error_query_ret
= lttng_error_query_execute(
573 query
, lttng_session_daemon_command_endpoint
, &results
);
574 if (error_query_ret
!= LTTNG_OK
) {
575 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
576 trigger_name
, (int) trigger_uid
,
577 lttng_strerror(-error_query_ret
));
581 results_status
= lttng_error_query_results_get_count(results
, &count
);
582 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
586 for (i
= 0; i
< count
; i
++) {
587 const struct lttng_error_query_result
*result
;
588 enum lttng_error_query_result_status result_status
;
589 const char *result_name
;
590 const char *result_description
;
591 uint64_t result_value
;
593 results_status
= lttng_error_query_results_get_result(
594 results
, &result
, i
);
595 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
597 result_status
= lttng_error_query_result_get_name(
598 result
, &result_name
);
599 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
600 result_status
= lttng_error_query_result_get_description(
601 result
, &result_description
);
602 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
604 if (lttng_error_query_result_get_type(result
) ==
605 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
606 result_status
= lttng_error_query_result_counter_get_value(
607 result
, &result_value
);
608 assert(result_status
==
609 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
610 if (result_value
== 0) {
615 _MSG(" %s: %" PRIu64
, result_name
,
617 printed_errors_count
++;
619 _MSG(" Unknown error query result type for result '%s' (%s)",
620 result_name
, result_description
);
625 if (printed_errors_count
== 0) {
631 lttng_error_query_destroy(query
);
632 lttng_error_query_results_destroy(results
);
633 lttng_action_path_destroy(action_path
);
637 void print_one_action(const struct lttng_trigger
*trigger
,
638 const struct lttng_action
*action
,
639 const uint64_t *action_path_indexes
,
640 size_t action_path_length
)
642 enum lttng_action_type action_type
;
643 enum lttng_action_status action_status
;
644 const struct lttng_rate_policy
*policy
= NULL
;
647 action_type
= lttng_action_get_type(action
);
648 assert(action_type
!= LTTNG_ACTION_TYPE_LIST
);
650 switch (action_type
) {
651 case LTTNG_ACTION_TYPE_NOTIFY
:
654 action_status
= lttng_action_notify_get_rate_policy(
656 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
657 ERR("Failed to retrieve rate policy.");
661 case LTTNG_ACTION_TYPE_START_SESSION
:
662 action_status
= lttng_action_start_session_get_session_name(
664 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
665 _MSG("start session `%s`", value
);
667 action_status
= lttng_action_start_session_get_rate_policy(
669 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
670 ERR("Failed to retrieve rate policy.");
674 case LTTNG_ACTION_TYPE_STOP_SESSION
:
675 action_status
= lttng_action_stop_session_get_session_name(
677 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
678 _MSG("stop session `%s`", value
);
680 action_status
= lttng_action_stop_session_get_rate_policy(
682 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
683 ERR("Failed to retrieve rate policy.");
687 case LTTNG_ACTION_TYPE_ROTATE_SESSION
:
688 action_status
= lttng_action_rotate_session_get_session_name(
690 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
691 _MSG("rotate session `%s`", value
);
693 action_status
= lttng_action_rotate_session_get_rate_policy(
695 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
696 ERR("Failed to retrieve rate policy.");
700 case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION
:
702 const struct lttng_snapshot_output
*output
;
704 action_status
= lttng_action_snapshot_session_get_session_name(
706 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
707 _MSG("snapshot session `%s`", value
);
709 action_status
= lttng_action_snapshot_session_get_output(
711 if (action_status
== LTTNG_ACTION_STATUS_OK
) {
714 const char *ctrl_url
, *data_url
;
715 bool starts_with_file
, starts_with_net
, starts_with_net6
;
717 ctrl_url
= lttng_snapshot_output_get_ctrl_url(output
);
718 assert(ctrl_url
&& strlen(ctrl_url
) > 0);
720 data_url
= lttng_snapshot_output_get_data_url(output
);
723 starts_with_file
= strncmp(ctrl_url
, "file://", strlen("file://")) == 0;
724 starts_with_net
= strncmp(ctrl_url
, "net://", strlen("net://")) == 0;
725 starts_with_net6
= strncmp(ctrl_url
, "net6://", strlen("net6://")) == 0;
727 if (ctrl_url
[0] == '/' || starts_with_file
) {
728 if (starts_with_file
) {
729 ctrl_url
+= strlen("file://");
732 _MSG(", path: %s", ctrl_url
);
733 } else if (starts_with_net
|| starts_with_net6
) {
734 _MSG(", url: %s", ctrl_url
);
736 assert(strlen(data_url
) > 0);
738 _MSG(", control url: %s, data url: %s", ctrl_url
, data_url
);
741 name
= lttng_snapshot_output_get_name(output
);
743 if (strlen(name
) > 0) {
744 _MSG(", name: %s", name
);
747 max_size
= lttng_snapshot_output_get_maxsize(output
);
748 if (max_size
!= -1ULL) {
749 _MSG(", max size: %" PRIu64
, max_size
);
753 action_status
= lttng_action_snapshot_session_get_rate_policy(
755 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
756 ERR("Failed to retrieve rate policy.");
766 enum lttng_rate_policy_type policy_type
;
767 enum lttng_rate_policy_status policy_status
;
768 uint64_t policy_value
= 0;
770 policy_type
= lttng_rate_policy_get_type(policy
);
772 switch (policy_type
) {
773 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
774 policy_status
= lttng_rate_policy_every_n_get_interval(
775 policy
, &policy_value
);
776 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
777 ERR("Failed to get action rate policy interval");
780 if (policy_value
> 1) {
781 /* The default is 1 so print only when it is a
784 _MSG(", rate policy: every %" PRIu64
789 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
790 policy_status
= lttng_rate_policy_once_after_n_get_threshold(
791 policy
, &policy_value
);
792 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
793 ERR("Failed to get action rate policy interval");
796 _MSG(", rate policy: once after %" PRIu64
806 print_action_errors(trigger
, action
, action_path_indexes
,
814 void print_trigger_errors(const struct lttng_trigger
*trigger
)
816 unsigned int i
, count
, printed_errors_count
= 0;
817 enum lttng_error_code error_query_ret
;
818 enum lttng_error_query_results_status results_status
;
819 struct lttng_error_query_results
*results
= NULL
;
820 enum lttng_trigger_status trigger_status
;
821 const char *trigger_name
;
823 struct lttng_error_query
*query
=
824 lttng_error_query_trigger_create(trigger
);
828 * Anonymous triggers are not listed; this would be an internal error.
830 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
831 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
833 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
834 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
836 error_query_ret
= lttng_error_query_execute(
837 query
, lttng_session_daemon_command_endpoint
, &results
);
838 if (error_query_ret
!= LTTNG_OK
) {
839 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
840 trigger_name
, (int) trigger_uid
,
841 lttng_strerror(-error_query_ret
));
845 results_status
= lttng_error_query_results_get_count(results
, &count
);
846 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
850 for (i
= 0; i
< count
; i
++) {
851 const struct lttng_error_query_result
*result
;
852 enum lttng_error_query_result_status result_status
;
853 const char *result_name
;
854 const char *result_description
;
855 uint64_t result_value
;
857 results_status
= lttng_error_query_results_get_result(
858 results
, &result
, i
);
859 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
861 result_status
= lttng_error_query_result_get_name(
862 result
, &result_name
);
863 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
864 result_status
= lttng_error_query_result_get_description(
865 result
, &result_description
);
866 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
868 if (lttng_error_query_result_get_type(result
) ==
869 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
870 result_status
= lttng_error_query_result_counter_get_value(
871 result
, &result_value
);
872 assert(result_status
==
873 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
874 if (result_value
== 0) {
879 _MSG(" %s: %" PRIu64
, result_name
,
881 printed_errors_count
++;
883 _MSG(" Unknown error query result type for result '%s' (%s)",
884 result_name
, result_description
);
889 if (printed_errors_count
== 0) {
895 lttng_error_query_destroy(query
);
896 lttng_error_query_results_destroy(results
);
900 void print_one_trigger(const struct lttng_trigger
*trigger
)
902 const struct lttng_condition
*condition
;
903 enum lttng_condition_type condition_type
;
904 const struct lttng_action
*action
;
905 enum lttng_action_type action_type
;
906 enum lttng_trigger_status trigger_status
;
911 * Anonymous triggers are not listed since they can't be specified nor
912 * referenced through the CLI.
914 trigger_status
= lttng_trigger_get_name(trigger
, &name
);
915 if (trigger_status
== LTTNG_TRIGGER_STATUS_UNSET
) {
919 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
921 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
922 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
924 MSG("- name: %s", name
);
925 MSG(" owner uid: %d", trigger_uid
);
927 condition
= lttng_trigger_get_const_condition(trigger
);
928 condition_type
= lttng_condition_get_type(condition
);
929 MSG(" condition: %s", lttng_condition_type_str(condition_type
));
930 switch (condition_type
) {
931 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
932 print_condition_session_consumed_size(condition
);
934 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
935 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
936 print_condition_buffer_usage(condition
);
938 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
939 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
940 print_condition_session_rotation(condition
);
942 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
943 print_condition_event_rule_matches(condition
);
949 action
= lttng_trigger_get_const_action(trigger
);
950 action_type
= lttng_action_get_type(action
);
951 if (action_type
== LTTNG_ACTION_TYPE_LIST
) {
952 unsigned int count
, i
;
953 enum lttng_action_status action_status
;
957 action_status
= lttng_action_list_get_count(action
, &count
);
958 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
960 for (i
= 0; i
< count
; i
++) {
961 const uint64_t action_path_index
= i
;
962 const struct lttng_action
*subaction
=
963 lttng_action_list_get_at_index(
967 print_one_action(trigger
, subaction
, &action_path_index
,
972 print_one_action(trigger
, action
, NULL
, 0);
975 print_trigger_errors(trigger
);
981 int compare_triggers_by_name(const void *a
, const void *b
)
983 const struct lttng_trigger
*trigger_a
= *((const struct lttng_trigger
**) a
);
984 const struct lttng_trigger
*trigger_b
= *((const struct lttng_trigger
**) b
);
985 const char *name_a
, *name_b
;
986 enum lttng_trigger_status trigger_status
;
988 /* Anonymous triggers are not reachable here. */
989 trigger_status
= lttng_trigger_get_name(trigger_a
, &name_a
);
990 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
992 trigger_status
= lttng_trigger_get_name(trigger_b
, &name_b
);
993 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
995 return strcmp(name_a
, name_b
);
998 int cmd_list_triggers(int argc
, const char **argv
)
1001 struct argpar_parse_ret argpar_parse_ret
= {};
1002 struct lttng_triggers
*triggers
= NULL
;
1004 struct lttng_dynamic_pointer_array sorted_triggers
;
1005 enum lttng_trigger_status trigger_status
;
1006 unsigned int num_triggers
;
1008 lttng_dynamic_pointer_array_init(&sorted_triggers
, NULL
);
1010 argpar_parse_ret
= argpar_parse(
1011 argc
- 1, argv
+ 1, list_trigger_options
, true);
1012 if (!argpar_parse_ret
.items
) {
1013 ERR("%s", argpar_parse_ret
.error
);
1017 for (i
= 0; i
< argpar_parse_ret
.items
->n_items
; i
++) {
1018 const struct argpar_item
*item
=
1019 argpar_parse_ret
.items
->items
[i
];
1021 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1022 const struct argpar_item_opt
*item_opt
=
1023 (const struct argpar_item_opt
*) item
;
1025 switch (item_opt
->descr
->id
) {
1031 case OPT_LIST_OPTIONS
:
1032 list_cmd_options_argpar(stdout
,
1033 list_trigger_options
);
1042 const struct argpar_item_non_opt
*item_non_opt
=
1043 (const struct argpar_item_non_opt
*) item
;
1045 ERR("Unexpected argument: %s", item_non_opt
->arg
);
1049 ret
= lttng_list_triggers(&triggers
);
1050 if (ret
!= LTTNG_OK
) {
1051 ERR("Error listing triggers: %s.", lttng_strerror(-ret
));
1055 trigger_status
= lttng_triggers_get_count(triggers
, &num_triggers
);
1056 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
1057 ERR("Failed to get trigger count.");
1061 for (i
= 0; i
< num_triggers
; i
++) {
1063 const char *unused_name
;
1064 const struct lttng_trigger
*trigger
=
1065 lttng_triggers_get_at_index(triggers
, i
);
1067 trigger_status
= lttng_trigger_get_name(trigger
, &unused_name
);
1068 switch (trigger_status
) {
1069 case LTTNG_TRIGGER_STATUS_OK
:
1071 case LTTNG_TRIGGER_STATUS_UNSET
:
1072 /* Don't list anonymous triggers. */
1078 add_ret
= lttng_dynamic_pointer_array_add_pointer(
1079 &sorted_triggers
, (void *) trigger
);
1082 ERR("Failed to allocate array of struct lttng_trigger *.");
1087 qsort(sorted_triggers
.array
.buffer
.data
, num_triggers
,
1088 sizeof(struct lttng_trigger
*),
1089 compare_triggers_by_name
);
1091 for (i
= 0; i
< num_triggers
; i
++) {
1092 const struct lttng_trigger
*trigger_to_print
=
1093 (const struct lttng_trigger
*)
1094 lttng_dynamic_pointer_array_get_pointer(
1095 &sorted_triggers
, i
);
1097 print_one_trigger(trigger_to_print
);
1107 argpar_parse_ret_fini(&argpar_parse_ret
);
1108 lttng_triggers_destroy(triggers
);
1109 lttng_dynamic_pointer_array_reset(&sorted_triggers
);