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_kernel_syscall_emission_site_str() */
22 #include "lttng/event-rule/kernel-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>
32 typedef enum lttng_event_rule_status (*event_rule_logging_get_name_pattern
)(
33 const struct lttng_event_rule
*rule
, const char **pattern
);
34 typedef enum lttng_event_rule_status (*event_rule_logging_get_filter
)(
35 const struct lttng_event_rule
*rule
, const char **expression
);
36 typedef enum lttng_event_rule_status (*event_rule_logging_get_log_level_rule
)(
37 const struct lttng_event_rule
*rule
,
38 const struct lttng_log_level_rule
**log_level_rule
);
46 struct argpar_opt_descr list_trigger_options
[] = {
47 { OPT_HELP
, 'h', "help", false },
48 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
49 ARGPAR_OPT_DESCR_SENTINEL
,
52 static void print_condition_session_consumed_size(
53 const struct lttng_condition
*condition
)
55 enum lttng_condition_status condition_status
;
56 const char *session_name
;
60 lttng_condition_session_consumed_size_get_session_name(
61 condition
, &session_name
);
62 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
64 lttng_condition_session_consumed_size_get_threshold(
65 condition
, &threshold
);
66 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
68 MSG(" session name: %s", session_name
);
69 MSG(" threshold: %" PRIu64
" bytes", threshold
);
72 static void print_condition_buffer_usage(
73 const struct lttng_condition
*condition
)
75 enum lttng_condition_status condition_status
;
76 const char *session_name
, *channel_name
;
77 enum lttng_domain_type domain_type
;
80 condition_status
= lttng_condition_buffer_usage_get_session_name(
81 condition
, &session_name
);
82 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
84 condition_status
= lttng_condition_buffer_usage_get_channel_name(
85 condition
, &channel_name
);
86 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
88 condition_status
= lttng_condition_buffer_usage_get_domain_type(
89 condition
, &domain_type
);
90 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
92 MSG(" session name: %s", session_name
);
93 MSG(" channel name: %s", channel_name
);
94 MSG(" domain: %s", lttng_domain_type_str(domain_type
));
96 condition_status
= lttng_condition_buffer_usage_get_threshold(
97 condition
, &threshold
);
98 if (condition_status
== LTTNG_CONDITION_STATUS_OK
) {
99 MSG(" threshold (bytes): %" PRIu64
, threshold
);
101 double threshold_ratio
;
103 assert(condition_status
== LTTNG_CONDITION_STATUS_UNSET
);
106 lttng_condition_buffer_usage_get_threshold_ratio(
107 condition
, &threshold_ratio
);
108 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
110 MSG(" threshold (ratio): %.2f", threshold_ratio
);
114 static void print_condition_session_rotation(
115 const struct lttng_condition
*condition
)
117 enum lttng_condition_status condition_status
;
118 const char *session_name
;
120 condition_status
= lttng_condition_session_rotation_get_session_name(
121 condition
, &session_name
);
122 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
124 MSG(" session name: %s", session_name
);
128 * Returns the human-readable log level name associated with a numerical value
129 * if there is one. The Log4j and JUL event rule have discontinuous log level
130 * values (a value can fall between two labels). In those cases, NULL is
133 static const char *get_pretty_loglevel_name(
134 enum lttng_event_rule_type event_rule_type
, int loglevel
)
136 const char *name
= NULL
;
138 switch (event_rule_type
) {
139 case LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT
:
140 name
= loglevel_value_to_name(loglevel
);
142 case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING
:
143 name
= loglevel_log4j_value_to_name(loglevel
);
145 case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING
:
146 name
= loglevel_jul_value_to_name(loglevel
);
148 case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING
:
149 name
= loglevel_python_value_to_name(loglevel
);
159 void print_event_rule_user_tracepoint(const struct lttng_event_rule
*event_rule
)
161 enum lttng_event_rule_status event_rule_status
;
165 const struct lttng_log_level_rule
*log_level_rule
= NULL
;
166 unsigned int exclusions_count
;
169 event_rule_status
= lttng_event_rule_user_tracepoint_get_name_pattern(
170 event_rule
, &pattern
);
171 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
173 _MSG(" rule: %s (type: user tracepoint", pattern
);
175 event_rule_status
= lttng_event_rule_user_tracepoint_get_filter(
176 event_rule
, &filter
);
177 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
178 _MSG(", filter: %s", filter
);
180 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
183 event_rule_status
= lttng_event_rule_user_tracepoint_get_log_level_rule(
184 event_rule
, &log_level_rule
);
185 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
186 enum lttng_log_level_rule_status llr_status
;
187 const char *log_level_op
;
188 const char *pretty_loglevel_name
;
190 switch (lttng_log_level_rule_get_type(log_level_rule
)) {
191 case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY
:
193 llr_status
= lttng_log_level_rule_exactly_get_level(
194 log_level_rule
, &log_level
);
196 case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS
:
197 log_level_op
= "at least";
198 llr_status
= lttng_log_level_rule_at_least_as_severe_as_get_level(
199 log_level_rule
, &log_level
);
205 assert(llr_status
== LTTNG_LOG_LEVEL_RULE_STATUS_OK
);
207 pretty_loglevel_name
= get_pretty_loglevel_name(
208 LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT
, log_level
);
209 if (pretty_loglevel_name
) {
210 _MSG(", log level %s %s", log_level_op
,
211 pretty_loglevel_name
);
213 _MSG(", log level %s %d", log_level_op
, log_level
);
216 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
219 event_rule_status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count(
220 event_rule
, &exclusions_count
);
221 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
222 if (exclusions_count
> 0) {
223 _MSG(", exclusions: ");
224 for (i
= 0; i
< exclusions_count
; i
++) {
225 const char *exclusion
;
227 event_rule_status
= lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index(
228 event_rule
, i
, &exclusion
);
229 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
231 _MSG("%s%s", i
> 0 ? "," : "", exclusion
);
239 void print_event_rule_kernel_tracepoint(const struct lttng_event_rule
*event_rule
)
241 enum lttng_event_rule_status event_rule_status
;
245 event_rule_status
= lttng_event_rule_kernel_tracepoint_get_name_pattern(
246 event_rule
, &pattern
);
247 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
249 _MSG(" rule: %s (type: kernel tracepoint", pattern
);
251 event_rule_status
= lttng_event_rule_kernel_tracepoint_get_filter(
252 event_rule
, &filter
);
253 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
254 _MSG(", filter: %s", filter
);
256 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
263 void print_event_rule_logging(const struct lttng_event_rule
*event_rule
)
265 enum lttng_event_rule_status event_rule_status
;
266 enum lttng_event_rule_type event_rule_type
= lttng_event_rule_get_type(event_rule
);
270 const struct lttng_log_level_rule
*log_level_rule
= NULL
;
271 const char *type_str
= NULL
;
273 event_rule_logging_get_name_pattern logging_get_name_pattern
;
274 event_rule_logging_get_filter logging_get_filter
;
275 event_rule_logging_get_log_level_rule logging_get_log_level_rule
;
277 switch (event_rule_type
) {
278 case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING
:
279 logging_get_name_pattern
=
280 lttng_event_rule_jul_logging_get_name_pattern
;
281 logging_get_filter
= lttng_event_rule_jul_logging_get_filter
;
282 logging_get_log_level_rule
=
283 lttng_event_rule_jul_logging_get_log_level_rule
;
286 case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING
:
287 logging_get_name_pattern
=
288 lttng_event_rule_log4j_logging_get_name_pattern
;
289 logging_get_filter
= lttng_event_rule_log4j_logging_get_filter
;
290 logging_get_log_level_rule
=
291 lttng_event_rule_log4j_logging_get_log_level_rule
;
294 case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING
:
295 logging_get_name_pattern
=
296 lttng_event_rule_python_logging_get_name_pattern
;
297 logging_get_filter
= lttng_event_rule_python_logging_get_filter
;
298 logging_get_log_level_rule
=
299 lttng_event_rule_python_logging_get_log_level_rule
;
307 event_rule_status
= logging_get_name_pattern(
308 event_rule
, &pattern
);
309 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
311 _MSG(" rule: %s (type: %s:logging", pattern
, type_str
);
313 event_rule_status
= logging_get_filter(
314 event_rule
, &filter
);
315 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
316 _MSG(", filter: %s", filter
);
318 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
321 event_rule_status
= logging_get_log_level_rule(
322 event_rule
, &log_level_rule
);
323 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
324 enum lttng_log_level_rule_status llr_status
;
325 const char *log_level_op
;
326 const char *pretty_loglevel_name
;
328 switch (lttng_log_level_rule_get_type(log_level_rule
)) {
329 case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY
:
331 llr_status
= lttng_log_level_rule_exactly_get_level(
332 log_level_rule
, &log_level
);
334 case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS
:
335 log_level_op
= "at least";
336 llr_status
= lttng_log_level_rule_at_least_as_severe_as_get_level(
337 log_level_rule
, &log_level
);
343 assert(llr_status
== LTTNG_LOG_LEVEL_RULE_STATUS_OK
);
345 pretty_loglevel_name
= get_pretty_loglevel_name(
346 event_rule_type
, log_level
);
347 if (pretty_loglevel_name
) {
348 _MSG(", log level %s %s", log_level_op
,
349 pretty_loglevel_name
);
351 _MSG(", log level %s %d", log_level_op
, log_level
);
354 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
360 static void print_kernel_probe_location(
361 const struct lttng_kernel_probe_location
*location
)
363 enum lttng_kernel_probe_location_status status
;
364 switch (lttng_kernel_probe_location_get_type(location
)) {
365 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
:
369 status
= lttng_kernel_probe_location_address_get_address(
371 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
372 ERR("Getting kernel probe location address failed.");
376 _MSG("0x%" PRIx64
, address
);
380 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
:
383 const char *symbol_name
;
385 symbol_name
= lttng_kernel_probe_location_symbol_get_name(
388 ERR("Getting kernel probe location symbol name failed.");
392 status
= lttng_kernel_probe_location_symbol_get_offset(
394 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
395 ERR("Getting kernel probe location address failed.");
400 _MSG("%s", symbol_name
);
402 _MSG("%s+0x%" PRIx64
, symbol_name
, offset
);
415 void print_event_rule_kernel_probe(const struct lttng_event_rule
*event_rule
)
417 enum lttng_event_rule_status event_rule_status
;
419 const struct lttng_kernel_probe_location
*location
;
421 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_KPROBE
);
423 event_rule_status
= lttng_event_rule_kernel_kprobe_get_event_name(event_rule
, &name
);
424 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
425 ERR("Failed to get kprobe event rule's name.");
429 event_rule_status
= lttng_event_rule_kernel_kprobe_get_location(
430 event_rule
, &location
);
431 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
432 ERR("Failed to get kprobe event rule's location.");
436 _MSG(" rule: %s (type: kernel:kprobe, location: ", name
);
438 print_kernel_probe_location(location
);
447 void print_event_rule_userspace_probe(const struct lttng_event_rule
*event_rule
)
449 enum lttng_event_rule_status event_rule_status
;
451 const struct lttng_userspace_probe_location
*location
;
452 enum lttng_userspace_probe_location_type userspace_probe_location_type
;
454 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
);
456 event_rule_status
= lttng_event_rule_kernel_uprobe_get_event_name(
458 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
459 ERR("Failed to get uprobe event rule's name.");
463 event_rule_status
= lttng_event_rule_kernel_uprobe_get_location(
464 event_rule
, &location
);
465 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
466 ERR("Failed to get uprobe event rule's location.");
470 _MSG(" rule: %s (type: kernel:uprobe, ", name
);
472 userspace_probe_location_type
=
473 lttng_userspace_probe_location_get_type(location
);
475 switch (userspace_probe_location_type
) {
476 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
478 const char *binary_path
, *function_name
;
480 binary_path
= lttng_userspace_probe_location_function_get_binary_path(
482 function_name
= lttng_userspace_probe_location_function_get_function_name(
485 _MSG("location type: ELF, location: %s:%s", binary_path
, function_name
);
488 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
490 const char *binary_path
, *provider_name
, *probe_name
;
492 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(
494 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(
496 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(
498 _MSG("location type: SDT, location: %s:%s:%s", binary_path
, provider_name
, probe_name
);
512 void print_event_rule_syscall(const struct lttng_event_rule
*event_rule
)
514 const char *pattern
, *filter
;
515 enum lttng_event_rule_status event_rule_status
;
516 enum lttng_event_rule_kernel_syscall_emission_site emission_site
;
518 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL
);
521 lttng_event_rule_kernel_syscall_get_emission_site(event_rule
);
523 event_rule_status
= lttng_event_rule_kernel_syscall_get_name_pattern(
524 event_rule
, &pattern
);
525 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
527 _MSG(" rule: %s (type: kernel:syscall:%s", pattern
,
528 lttng_event_rule_kernel_syscall_emission_site_str(
531 event_rule_status
= lttng_event_rule_kernel_syscall_get_filter(
532 event_rule
, &filter
);
533 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
534 _MSG(", filter: %s", filter
);
536 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
543 void print_event_rule(const struct lttng_event_rule
*event_rule
)
545 const enum lttng_event_rule_type event_rule_type
=
546 lttng_event_rule_get_type(event_rule
);
548 switch (event_rule_type
) {
549 case LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT
:
550 print_event_rule_user_tracepoint(event_rule
);
552 case LTTNG_EVENT_RULE_TYPE_KERNEL_TRACEPOINT
:
553 print_event_rule_kernel_tracepoint(event_rule
);
555 case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING
:
556 case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING
:
557 case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING
:
558 print_event_rule_logging(event_rule
);
560 case LTTNG_EVENT_RULE_TYPE_KERNEL_KPROBE
:
561 print_event_rule_kernel_probe(event_rule
);
563 case LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE
:
564 print_event_rule_userspace_probe(event_rule
);
566 case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL
:
567 print_event_rule_syscall(event_rule
);
575 void print_one_event_expr(const struct lttng_event_expr
*event_expr
)
577 enum lttng_event_expr_type type
;
579 type
= lttng_event_expr_get_type(event_expr
);
582 case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD
:
586 name
= lttng_event_expr_event_payload_field_get_name(
592 case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD
:
596 name
= lttng_event_expr_channel_context_field_get_name(
598 _MSG("$ctx.%s", name
);
602 case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD
:
604 const char *provider_name
;
605 const char *type_name
;
607 provider_name
= lttng_event_expr_app_specific_context_field_get_provider_name(
609 type_name
= lttng_event_expr_app_specific_context_field_get_type_name(
612 _MSG("$app.%s:%s", provider_name
, type_name
);
616 case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT
:
619 const struct lttng_event_expr
*parent_expr
;
620 enum lttng_event_expr_status status
;
622 parent_expr
= lttng_event_expr_array_field_element_get_parent_expr(
624 assert(parent_expr
!= NULL
);
626 print_one_event_expr(parent_expr
);
628 status
= lttng_event_expr_array_field_element_get_index(
630 assert(status
== LTTNG_EVENT_EXPR_STATUS_OK
);
641 static void print_condition_event_rule_matches(
642 const struct lttng_condition
*condition
)
644 const struct lttng_event_rule
*event_rule
;
645 enum lttng_condition_status condition_status
;
646 unsigned int cap_desc_count
, i
;
648 condition_status
= lttng_condition_event_rule_matches_get_rule(
649 condition
, &event_rule
);
650 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
652 print_event_rule(event_rule
);
655 lttng_condition_event_rule_matches_get_capture_descriptor_count(
656 condition
, &cap_desc_count
);
657 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
659 if (cap_desc_count
> 0) {
662 for (i
= 0; i
< cap_desc_count
; i
++) {
663 const struct lttng_event_expr
*cap_desc
=
664 lttng_condition_event_rule_matches_get_capture_descriptor_at_index(
668 print_one_event_expr(cap_desc
);
674 static void print_action_errors(const struct lttng_trigger
*trigger
,
675 const struct lttng_action
*action
,
676 const uint64_t *action_path_indexes
,
677 size_t action_path_length
)
679 unsigned int i
, count
, printed_errors_count
= 0;
680 enum lttng_error_code error_query_ret
;
681 enum lttng_error_query_results_status results_status
;
682 struct lttng_error_query_results
*results
= NULL
;
683 const char *trigger_name
;
685 enum lttng_trigger_status trigger_status
;
686 struct lttng_error_query
*query
;
687 struct lttng_action_path
*action_path
= lttng_action_path_create(
688 action_path_indexes
, action_path_length
);
692 query
= lttng_error_query_action_create(trigger
, action_path
);
695 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
697 * Anonymous triggers are not listed; this would be an internal error.
699 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
701 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
702 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
704 error_query_ret
= lttng_error_query_execute(
705 query
, lttng_session_daemon_command_endpoint
, &results
);
706 if (error_query_ret
!= LTTNG_OK
) {
707 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
708 trigger_name
, (int) trigger_uid
,
709 lttng_strerror(-error_query_ret
));
713 results_status
= lttng_error_query_results_get_count(results
, &count
);
714 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
718 for (i
= 0; i
< count
; i
++) {
719 const struct lttng_error_query_result
*result
;
720 enum lttng_error_query_result_status result_status
;
721 const char *result_name
;
722 const char *result_description
;
723 uint64_t result_value
;
725 results_status
= lttng_error_query_results_get_result(
726 results
, &result
, i
);
727 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
729 result_status
= lttng_error_query_result_get_name(
730 result
, &result_name
);
731 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
732 result_status
= lttng_error_query_result_get_description(
733 result
, &result_description
);
734 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
736 if (lttng_error_query_result_get_type(result
) ==
737 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
738 result_status
= lttng_error_query_result_counter_get_value(
739 result
, &result_value
);
740 assert(result_status
==
741 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
742 if (result_value
== 0) {
747 _MSG(" %s: %" PRIu64
, result_name
,
749 printed_errors_count
++;
751 _MSG(" Unknown error query result type for result '%s' (%s)",
752 result_name
, result_description
);
757 if (printed_errors_count
== 0) {
763 lttng_error_query_destroy(query
);
764 lttng_error_query_results_destroy(results
);
765 lttng_action_path_destroy(action_path
);
769 void print_one_action(const struct lttng_trigger
*trigger
,
770 const struct lttng_action
*action
,
771 const uint64_t *action_path_indexes
,
772 size_t action_path_length
)
774 enum lttng_action_type action_type
;
775 enum lttng_action_status action_status
;
776 const struct lttng_rate_policy
*policy
= NULL
;
779 action_type
= lttng_action_get_type(action
);
780 assert(action_type
!= LTTNG_ACTION_TYPE_LIST
);
782 switch (action_type
) {
783 case LTTNG_ACTION_TYPE_NOTIFY
:
786 action_status
= lttng_action_notify_get_rate_policy(
788 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
789 ERR("Failed to retrieve rate policy.");
793 case LTTNG_ACTION_TYPE_START_SESSION
:
794 action_status
= lttng_action_start_session_get_session_name(
796 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
797 _MSG("start session `%s`", value
);
799 action_status
= lttng_action_start_session_get_rate_policy(
801 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
802 ERR("Failed to retrieve rate policy.");
806 case LTTNG_ACTION_TYPE_STOP_SESSION
:
807 action_status
= lttng_action_stop_session_get_session_name(
809 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
810 _MSG("stop session `%s`", value
);
812 action_status
= lttng_action_stop_session_get_rate_policy(
814 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
815 ERR("Failed to retrieve rate policy.");
819 case LTTNG_ACTION_TYPE_ROTATE_SESSION
:
820 action_status
= lttng_action_rotate_session_get_session_name(
822 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
823 _MSG("rotate session `%s`", value
);
825 action_status
= lttng_action_rotate_session_get_rate_policy(
827 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
828 ERR("Failed to retrieve rate policy.");
832 case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION
:
834 const struct lttng_snapshot_output
*output
;
836 action_status
= lttng_action_snapshot_session_get_session_name(
838 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
839 _MSG("snapshot session `%s`", value
);
841 action_status
= lttng_action_snapshot_session_get_output(
843 if (action_status
== LTTNG_ACTION_STATUS_OK
) {
846 const char *ctrl_url
, *data_url
;
847 bool starts_with_file
, starts_with_net
, starts_with_net6
;
849 ctrl_url
= lttng_snapshot_output_get_ctrl_url(output
);
850 assert(ctrl_url
&& strlen(ctrl_url
) > 0);
852 data_url
= lttng_snapshot_output_get_data_url(output
);
855 starts_with_file
= strncmp(ctrl_url
, "file://", strlen("file://")) == 0;
856 starts_with_net
= strncmp(ctrl_url
, "net://", strlen("net://")) == 0;
857 starts_with_net6
= strncmp(ctrl_url
, "net6://", strlen("net6://")) == 0;
859 if (ctrl_url
[0] == '/' || starts_with_file
) {
860 if (starts_with_file
) {
861 ctrl_url
+= strlen("file://");
864 _MSG(", path: %s", ctrl_url
);
865 } else if (starts_with_net
|| starts_with_net6
) {
866 _MSG(", url: %s", ctrl_url
);
868 assert(strlen(data_url
) > 0);
870 _MSG(", control url: %s, data url: %s", ctrl_url
, data_url
);
873 name
= lttng_snapshot_output_get_name(output
);
875 if (strlen(name
) > 0) {
876 _MSG(", name: %s", name
);
879 max_size
= lttng_snapshot_output_get_maxsize(output
);
880 if (max_size
!= -1ULL) {
881 _MSG(", max size: %" PRIu64
, max_size
);
885 action_status
= lttng_action_snapshot_session_get_rate_policy(
887 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
888 ERR("Failed to retrieve rate policy.");
898 enum lttng_rate_policy_type policy_type
;
899 enum lttng_rate_policy_status policy_status
;
900 uint64_t policy_value
= 0;
902 policy_type
= lttng_rate_policy_get_type(policy
);
904 switch (policy_type
) {
905 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
906 policy_status
= lttng_rate_policy_every_n_get_interval(
907 policy
, &policy_value
);
908 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
909 ERR("Failed to get action rate policy interval");
912 if (policy_value
> 1) {
913 /* The default is 1 so print only when it is a
916 _MSG(", rate policy: every %" PRIu64
921 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
922 policy_status
= lttng_rate_policy_once_after_n_get_threshold(
923 policy
, &policy_value
);
924 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
925 ERR("Failed to get action rate policy interval");
928 _MSG(", rate policy: once after %" PRIu64
938 print_action_errors(trigger
, action
, action_path_indexes
,
946 void print_trigger_errors(const struct lttng_trigger
*trigger
)
948 unsigned int i
, count
, printed_errors_count
= 0;
949 enum lttng_error_code error_query_ret
;
950 enum lttng_error_query_results_status results_status
;
951 struct lttng_error_query_results
*results
= NULL
;
952 enum lttng_trigger_status trigger_status
;
953 const char *trigger_name
;
955 struct lttng_error_query
*query
=
956 lttng_error_query_trigger_create(trigger
);
960 * Anonymous triggers are not listed; this would be an internal error.
962 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
963 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
965 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
966 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
968 error_query_ret
= lttng_error_query_execute(
969 query
, lttng_session_daemon_command_endpoint
, &results
);
970 if (error_query_ret
!= LTTNG_OK
) {
971 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
972 trigger_name
, (int) trigger_uid
,
973 lttng_strerror(-error_query_ret
));
977 results_status
= lttng_error_query_results_get_count(results
, &count
);
978 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
982 for (i
= 0; i
< count
; i
++) {
983 const struct lttng_error_query_result
*result
;
984 enum lttng_error_query_result_status result_status
;
985 const char *result_name
;
986 const char *result_description
;
987 uint64_t result_value
;
989 results_status
= lttng_error_query_results_get_result(
990 results
, &result
, i
);
991 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
993 result_status
= lttng_error_query_result_get_name(
994 result
, &result_name
);
995 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
996 result_status
= lttng_error_query_result_get_description(
997 result
, &result_description
);
998 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
1000 if (lttng_error_query_result_get_type(result
) ==
1001 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
1002 result_status
= lttng_error_query_result_counter_get_value(
1003 result
, &result_value
);
1004 assert(result_status
==
1005 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
1006 if (result_value
== 0) {
1011 _MSG(" %s: %" PRIu64
, result_name
,
1013 printed_errors_count
++;
1015 _MSG(" Unknown error query result type for result '%s' (%s)",
1016 result_name
, result_description
);
1021 if (printed_errors_count
== 0) {
1027 lttng_error_query_destroy(query
);
1028 lttng_error_query_results_destroy(results
);
1032 void print_one_trigger(const struct lttng_trigger
*trigger
)
1034 const struct lttng_condition
*condition
;
1035 enum lttng_condition_type condition_type
;
1036 const struct lttng_action
*action
;
1037 enum lttng_action_type action_type
;
1038 enum lttng_trigger_status trigger_status
;
1043 * Anonymous triggers are not listed since they can't be specified nor
1044 * referenced through the CLI.
1046 trigger_status
= lttng_trigger_get_name(trigger
, &name
);
1047 if (trigger_status
== LTTNG_TRIGGER_STATUS_UNSET
) {
1051 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1053 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
1054 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1056 MSG("- name: %s", name
);
1057 MSG(" owner uid: %d", trigger_uid
);
1059 condition
= lttng_trigger_get_const_condition(trigger
);
1060 condition_type
= lttng_condition_get_type(condition
);
1061 MSG(" condition: %s", lttng_condition_type_str(condition_type
));
1062 switch (condition_type
) {
1063 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
1064 print_condition_session_consumed_size(condition
);
1066 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
1067 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
1068 print_condition_buffer_usage(condition
);
1070 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
1071 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
1072 print_condition_session_rotation(condition
);
1074 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
1075 print_condition_event_rule_matches(condition
);
1081 action
= lttng_trigger_get_const_action(trigger
);
1082 action_type
= lttng_action_get_type(action
);
1083 if (action_type
== LTTNG_ACTION_TYPE_LIST
) {
1084 unsigned int count
, i
;
1085 enum lttng_action_status action_status
;
1089 action_status
= lttng_action_list_get_count(action
, &count
);
1090 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
1092 for (i
= 0; i
< count
; i
++) {
1093 const uint64_t action_path_index
= i
;
1094 const struct lttng_action
*subaction
=
1095 lttng_action_list_get_at_index(
1099 print_one_action(trigger
, subaction
, &action_path_index
,
1104 print_one_action(trigger
, action
, NULL
, 0);
1107 print_trigger_errors(trigger
);
1113 int compare_triggers_by_name(const void *a
, const void *b
)
1115 const struct lttng_trigger
*trigger_a
= *((const struct lttng_trigger
**) a
);
1116 const struct lttng_trigger
*trigger_b
= *((const struct lttng_trigger
**) b
);
1117 const char *name_a
, *name_b
;
1118 enum lttng_trigger_status trigger_status
;
1120 /* Anonymous triggers are not reachable here. */
1121 trigger_status
= lttng_trigger_get_name(trigger_a
, &name_a
);
1122 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1124 trigger_status
= lttng_trigger_get_name(trigger_b
, &name_b
);
1125 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
1127 return strcmp(name_a
, name_b
);
1130 int cmd_list_triggers(int argc
, const char **argv
)
1133 struct argpar_parse_ret argpar_parse_ret
= {};
1134 struct lttng_triggers
*triggers
= NULL
;
1136 struct lttng_dynamic_pointer_array sorted_triggers
;
1137 enum lttng_trigger_status trigger_status
;
1138 unsigned int num_triggers
;
1140 lttng_dynamic_pointer_array_init(&sorted_triggers
, NULL
);
1142 argpar_parse_ret
= argpar_parse(
1143 argc
- 1, argv
+ 1, list_trigger_options
, true);
1144 if (!argpar_parse_ret
.items
) {
1145 ERR("%s", argpar_parse_ret
.error
);
1149 for (i
= 0; i
< argpar_parse_ret
.items
->n_items
; i
++) {
1150 const struct argpar_item
*item
=
1151 argpar_parse_ret
.items
->items
[i
];
1153 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1154 const struct argpar_item_opt
*item_opt
=
1155 (const struct argpar_item_opt
*) item
;
1157 switch (item_opt
->descr
->id
) {
1163 case OPT_LIST_OPTIONS
:
1164 list_cmd_options_argpar(stdout
,
1165 list_trigger_options
);
1174 const struct argpar_item_non_opt
*item_non_opt
=
1175 (const struct argpar_item_non_opt
*) item
;
1177 ERR("Unexpected argument: %s", item_non_opt
->arg
);
1181 ret
= lttng_list_triggers(&triggers
);
1182 if (ret
!= LTTNG_OK
) {
1183 ERR("Error listing triggers: %s.", lttng_strerror(-ret
));
1187 trigger_status
= lttng_triggers_get_count(triggers
, &num_triggers
);
1188 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
1189 ERR("Failed to get trigger count.");
1193 for (i
= 0; i
< num_triggers
; i
++) {
1195 const char *unused_name
;
1196 const struct lttng_trigger
*trigger
=
1197 lttng_triggers_get_at_index(triggers
, i
);
1199 trigger_status
= lttng_trigger_get_name(trigger
, &unused_name
);
1200 switch (trigger_status
) {
1201 case LTTNG_TRIGGER_STATUS_OK
:
1203 case LTTNG_TRIGGER_STATUS_UNSET
:
1204 /* Don't list anonymous triggers. */
1210 add_ret
= lttng_dynamic_pointer_array_add_pointer(
1211 &sorted_triggers
, (void *) trigger
);
1214 ERR("Failed to allocate array of struct lttng_trigger *.");
1219 qsort(sorted_triggers
.array
.buffer
.data
, num_triggers
,
1220 sizeof(struct lttng_trigger
*),
1221 compare_triggers_by_name
);
1223 for (i
= 0; i
< num_triggers
; i
++) {
1224 const struct lttng_trigger
*trigger_to_print
=
1225 (const struct lttng_trigger
*)
1226 lttng_dynamic_pointer_array_get_pointer(
1227 &sorted_triggers
, i
);
1229 print_one_trigger(trigger_to_print
);
1239 argpar_parse_ret_fini(&argpar_parse_ret
);
1240 lttng_triggers_destroy(triggers
);
1241 lttng_dynamic_pointer_array_reset(&sorted_triggers
);