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_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_exclusions_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_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_type emission_site_type
;
394 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_SYSCALL
);
397 lttng_event_rule_syscall_get_emission_site_type(event_rule
);
399 event_rule_status
= lttng_event_rule_syscall_get_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(
405 emission_site_type
));
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
);
543 void print_action_errors(const struct lttng_trigger
*trigger
,
544 const struct lttng_action
*action
)
546 unsigned int i
, count
, printed_errors_count
= 0;
547 enum lttng_error_code error_query_ret
;
548 enum lttng_error_query_results_status results_status
;
549 struct lttng_error_query_results
*results
= NULL
;
550 const char *trigger_name
;
552 enum lttng_trigger_status trigger_status
;
553 struct lttng_error_query
*query
=
554 lttng_error_query_action_create(trigger
, action
);
558 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
560 * Anonymous triggers are not listed; this would be an internal error.
562 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
564 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
565 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
567 error_query_ret
= lttng_error_query_execute(
568 query
, lttng_session_daemon_command_endpoint
, &results
);
569 if (error_query_ret
!= LTTNG_OK
) {
570 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
571 trigger_name
, (int) trigger_uid
,
572 lttng_strerror(-error_query_ret
));
576 results_status
= lttng_error_query_results_get_count(results
, &count
);
577 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
581 for (i
= 0; i
< count
; i
++) {
582 const struct lttng_error_query_result
*result
;
583 enum lttng_error_query_result_status result_status
;
584 const char *result_name
;
585 const char *result_description
;
586 uint64_t result_value
;
588 results_status
= lttng_error_query_results_get_result(
589 results
, &result
, i
);
590 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
592 result_status
= lttng_error_query_result_get_name(
593 result
, &result_name
);
594 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
595 result_status
= lttng_error_query_result_get_description(
596 result
, &result_description
);
597 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
599 if (lttng_error_query_result_get_type(result
) ==
600 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
601 result_status
= lttng_error_query_result_counter_get_value(
602 result
, &result_value
);
603 assert(result_status
==
604 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
605 if (result_value
== 0) {
610 _MSG(" %s: %" PRIu64
, result_name
,
612 printed_errors_count
++;
614 _MSG(" Unknown error query result type for result '%s' (%s)",
615 result_name
, result_description
);
620 if (printed_errors_count
== 0) {
626 lttng_error_query_destroy(query
);
627 lttng_error_query_results_destroy(results
);
631 void print_one_action(const struct lttng_trigger
*trigger
,
632 const struct lttng_action
*action
)
634 enum lttng_action_type action_type
;
635 enum lttng_action_status action_status
;
636 const struct lttng_rate_policy
*policy
= NULL
;
639 action_type
= lttng_action_get_type(action
);
640 assert(action_type
!= LTTNG_ACTION_TYPE_LIST
);
642 switch (action_type
) {
643 case LTTNG_ACTION_TYPE_NOTIFY
:
646 action_status
= lttng_action_notify_get_rate_policy(
648 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
649 ERR("Failed to retrieve rate policy.");
653 case LTTNG_ACTION_TYPE_START_SESSION
:
654 action_status
= lttng_action_start_session_get_session_name(
656 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
657 _MSG("start session `%s`", value
);
659 action_status
= lttng_action_start_session_get_rate_policy(
661 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
662 ERR("Failed to retrieve rate policy.");
666 case LTTNG_ACTION_TYPE_STOP_SESSION
:
667 action_status
= lttng_action_stop_session_get_session_name(
669 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
670 _MSG("stop session `%s`", value
);
672 action_status
= lttng_action_stop_session_get_rate_policy(
674 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
675 ERR("Failed to retrieve rate policy.");
679 case LTTNG_ACTION_TYPE_ROTATE_SESSION
:
680 action_status
= lttng_action_rotate_session_get_session_name(
682 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
683 _MSG("rotate session `%s`", value
);
685 action_status
= lttng_action_rotate_session_get_rate_policy(
687 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
688 ERR("Failed to retrieve rate policy.");
692 case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION
:
694 const struct lttng_snapshot_output
*output
;
696 action_status
= lttng_action_snapshot_session_get_session_name(
698 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
699 _MSG("snapshot session `%s`", value
);
701 action_status
= lttng_action_snapshot_session_get_output(
703 if (action_status
== LTTNG_ACTION_STATUS_OK
) {
706 const char *ctrl_url
, *data_url
;
707 bool starts_with_file
, starts_with_net
, starts_with_net6
;
709 ctrl_url
= lttng_snapshot_output_get_ctrl_url(output
);
710 assert(ctrl_url
&& strlen(ctrl_url
) > 0);
712 data_url
= lttng_snapshot_output_get_data_url(output
);
715 starts_with_file
= strncmp(ctrl_url
, "file://", strlen("file://")) == 0;
716 starts_with_net
= strncmp(ctrl_url
, "net://", strlen("net://")) == 0;
717 starts_with_net6
= strncmp(ctrl_url
, "net6://", strlen("net6://")) == 0;
719 if (ctrl_url
[0] == '/' || starts_with_file
) {
720 if (starts_with_file
) {
721 ctrl_url
+= strlen("file://");
724 _MSG(", path: %s", ctrl_url
);
725 } else if (starts_with_net
|| starts_with_net6
) {
726 _MSG(", url: %s", ctrl_url
);
728 assert(strlen(data_url
) > 0);
730 _MSG(", control url: %s, data url: %s", ctrl_url
, data_url
);
733 name
= lttng_snapshot_output_get_name(output
);
735 if (strlen(name
) > 0) {
736 _MSG(", name: %s", name
);
739 max_size
= lttng_snapshot_output_get_maxsize(output
);
740 if (max_size
!= -1ULL) {
741 _MSG(", max size: %" PRIu64
, max_size
);
745 action_status
= lttng_action_snapshot_session_get_rate_policy(
747 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
748 ERR("Failed to retrieve rate policy.");
758 enum lttng_rate_policy_type policy_type
;
759 enum lttng_rate_policy_status policy_status
;
760 uint64_t policy_value
= 0;
762 policy_type
= lttng_rate_policy_get_type(policy
);
764 switch (policy_type
) {
765 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
766 policy_status
= lttng_rate_policy_every_n_get_interval(
767 policy
, &policy_value
);
768 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
769 ERR("Failed to get action rate policy interval");
772 if (policy_value
> 1) {
773 /* The default is 1 so print only when it is a
776 _MSG(", rate policy: after every %" PRIu64
781 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
782 policy_status
= lttng_rate_policy_once_after_n_get_threshold(
783 policy
, &policy_value
);
784 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
785 ERR("Failed to get action rate policy interval");
788 _MSG(", rate policy: once after %" PRIu64
798 print_action_errors(trigger
, action
);
805 void print_trigger_errors(const struct lttng_trigger
*trigger
)
807 unsigned int i
, count
, printed_errors_count
= 0;
808 enum lttng_error_code error_query_ret
;
809 enum lttng_error_query_results_status results_status
;
810 struct lttng_error_query_results
*results
= NULL
;
811 enum lttng_trigger_status trigger_status
;
812 const char *trigger_name
;
814 struct lttng_error_query
*query
=
815 lttng_error_query_trigger_create(trigger
);
819 * Anonymous triggers are not listed; this would be an internal error.
821 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
822 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
824 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
825 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
827 error_query_ret
= lttng_error_query_execute(
828 query
, lttng_session_daemon_command_endpoint
, &results
);
829 if (error_query_ret
!= LTTNG_OK
) {
830 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
831 trigger_name
, (int) trigger_uid
,
832 lttng_strerror(-error_query_ret
));
836 results_status
= lttng_error_query_results_get_count(results
, &count
);
837 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
841 for (i
= 0; i
< count
; i
++) {
842 const struct lttng_error_query_result
*result
;
843 enum lttng_error_query_result_status result_status
;
844 const char *result_name
;
845 const char *result_description
;
846 uint64_t result_value
;
848 results_status
= lttng_error_query_results_get_result(
849 results
, &result
, i
);
850 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
852 result_status
= lttng_error_query_result_get_name(
853 result
, &result_name
);
854 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
855 result_status
= lttng_error_query_result_get_description(
856 result
, &result_description
);
857 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
859 if (lttng_error_query_result_get_type(result
) ==
860 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
861 result_status
= lttng_error_query_result_counter_get_value(
862 result
, &result_value
);
863 assert(result_status
==
864 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
865 if (result_value
== 0) {
870 _MSG(" %s: %" PRIu64
, result_name
,
872 printed_errors_count
++;
874 _MSG(" Unknown error query result type for result '%s' (%s)",
875 result_name
, result_description
);
880 if (printed_errors_count
== 0) {
886 lttng_error_query_destroy(query
);
887 lttng_error_query_results_destroy(results
);
891 void print_one_trigger(const struct lttng_trigger
*trigger
)
893 const struct lttng_condition
*condition
;
894 enum lttng_condition_type condition_type
;
895 const struct lttng_action
*action
;
896 enum lttng_action_type action_type
;
897 enum lttng_trigger_status trigger_status
;
902 * Anonymous triggers are not listed since they can't be specified nor
903 * referenced through the CLI.
905 trigger_status
= lttng_trigger_get_name(trigger
, &name
);
906 if (trigger_status
== LTTNG_TRIGGER_STATUS_UNSET
) {
910 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
912 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
913 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
915 MSG("- name: %s", name
);
916 MSG(" owner uid: %d", trigger_uid
);
918 condition
= lttng_trigger_get_const_condition(trigger
);
919 condition_type
= lttng_condition_get_type(condition
);
920 MSG(" condition: %s", lttng_condition_type_str(condition_type
));
921 switch (condition_type
) {
922 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
923 print_condition_session_consumed_size(condition
);
925 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
926 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
927 print_condition_buffer_usage(condition
);
929 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
930 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
931 print_condition_session_rotation(condition
);
933 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
934 print_condition_event_rule_matches(condition
);
940 action
= lttng_trigger_get_const_action(trigger
);
941 action_type
= lttng_action_get_type(action
);
942 if (action_type
== LTTNG_ACTION_TYPE_LIST
) {
943 unsigned int count
, i
;
944 enum lttng_action_status action_status
;
948 action_status
= lttng_action_list_get_count(action
, &count
);
949 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
951 for (i
= 0; i
< count
; i
++) {
952 const struct lttng_action
*subaction
=
953 lttng_action_list_get_at_index(
957 print_one_action(trigger
, subaction
);
961 print_one_action(trigger
, action
);
964 print_trigger_errors(trigger
);
970 int compare_triggers_by_name(const void *a
, const void *b
)
972 const struct lttng_trigger
*trigger_a
= *((const struct lttng_trigger
**) a
);
973 const struct lttng_trigger
*trigger_b
= *((const struct lttng_trigger
**) b
);
974 const char *name_a
, *name_b
;
975 enum lttng_trigger_status trigger_status
;
977 /* Anonymous triggers are not reachable here. */
978 trigger_status
= lttng_trigger_get_name(trigger_a
, &name_a
);
979 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
981 trigger_status
= lttng_trigger_get_name(trigger_b
, &name_b
);
982 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
984 return strcmp(name_a
, name_b
);
987 int cmd_list_triggers(int argc
, const char **argv
)
990 struct argpar_parse_ret argpar_parse_ret
= {};
991 struct lttng_triggers
*triggers
= NULL
;
993 struct lttng_dynamic_pointer_array sorted_triggers
;
994 enum lttng_trigger_status trigger_status
;
995 unsigned int num_triggers
;
997 lttng_dynamic_pointer_array_init(&sorted_triggers
, NULL
);
999 argpar_parse_ret
= argpar_parse(
1000 argc
- 1, argv
+ 1, list_trigger_options
, true);
1001 if (!argpar_parse_ret
.items
) {
1002 ERR("%s", argpar_parse_ret
.error
);
1006 for (i
= 0; i
< argpar_parse_ret
.items
->n_items
; i
++) {
1007 const struct argpar_item
*item
=
1008 argpar_parse_ret
.items
->items
[i
];
1010 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
1011 const struct argpar_item_opt
*item_opt
=
1012 (const struct argpar_item_opt
*) item
;
1014 switch (item_opt
->descr
->id
) {
1020 case OPT_LIST_OPTIONS
:
1021 list_cmd_options_argpar(stdout
,
1022 list_trigger_options
);
1031 const struct argpar_item_non_opt
*item_non_opt
=
1032 (const struct argpar_item_non_opt
*) item
;
1034 ERR("Unexpected argument: %s", item_non_opt
->arg
);
1038 ret
= lttng_list_triggers(&triggers
);
1039 if (ret
!= LTTNG_OK
) {
1040 ERR("Error listing triggers: %s.", lttng_strerror(-ret
));
1044 trigger_status
= lttng_triggers_get_count(triggers
, &num_triggers
);
1045 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
1046 ERR("Failed to get trigger count.");
1050 for (i
= 0; i
< num_triggers
; i
++) {
1052 const char *unused_name
;
1053 const struct lttng_trigger
*trigger
=
1054 lttng_triggers_get_at_index(triggers
, i
);
1056 trigger_status
= lttng_trigger_get_name(trigger
, &unused_name
);
1057 switch (trigger_status
) {
1058 case LTTNG_TRIGGER_STATUS_OK
:
1060 case LTTNG_TRIGGER_STATUS_UNSET
:
1061 /* Don't list anonymous triggers. */
1067 add_ret
= lttng_dynamic_pointer_array_add_pointer(
1068 &sorted_triggers
, (void *) trigger
);
1071 ERR("Failed to allocate array of struct lttng_trigger *.");
1076 qsort(sorted_triggers
.array
.buffer
.data
, num_triggers
,
1077 sizeof(struct lttng_trigger
*),
1078 compare_triggers_by_name
);
1080 for (i
= 0; i
< num_triggers
; i
++) {
1081 const struct lttng_trigger
*trigger_to_print
=
1082 (const struct lttng_trigger
*)
1083 lttng_dynamic_pointer_array_get_pointer(
1084 &sorted_triggers
, i
);
1086 print_one_trigger(trigger_to_print
);
1096 argpar_parse_ret_fini(&argpar_parse_ret
);
1097 lttng_triggers_destroy(triggers
);
1098 lttng_dynamic_pointer_array_reset(&sorted_triggers
);