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/on-event.h"
18 #include "lttng/condition/on-event-internal.h"
19 /* For lttng_domain_type_str(). */
20 #include "lttng/domain-internal.h"
21 #include "../loglevel.h"
22 #include <lttng/lttng.h>
24 #ifdef LTTNG_EMBED_HELP
25 static const char help_msg
[] =
26 #include <lttng-list-triggers.1.h>
36 struct argpar_opt_descr list_trigger_options
[] = {
37 { OPT_HELP
, 'h', "help", false },
38 { OPT_LIST_OPTIONS
, '\0', "list-options", false },
39 ARGPAR_OPT_DESCR_SENTINEL
,
42 static void print_condition_session_consumed_size(
43 const struct lttng_condition
*condition
)
45 enum lttng_condition_status condition_status
;
46 const char *session_name
;
50 lttng_condition_session_consumed_size_get_session_name(
51 condition
, &session_name
);
52 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
54 lttng_condition_session_consumed_size_get_threshold(
55 condition
, &threshold
);
56 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
58 MSG(" session name: %s", session_name
);
59 MSG(" threshold: %" PRIu64
" bytes", threshold
);
62 static void print_condition_buffer_usage(
63 const struct lttng_condition
*condition
)
65 enum lttng_condition_status condition_status
;
66 const char *session_name
, *channel_name
;
67 enum lttng_domain_type domain_type
;
70 condition_status
= lttng_condition_buffer_usage_get_session_name(
71 condition
, &session_name
);
72 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
74 condition_status
= lttng_condition_buffer_usage_get_channel_name(
75 condition
, &channel_name
);
76 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
78 condition_status
= lttng_condition_buffer_usage_get_domain_type(
79 condition
, &domain_type
);
80 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
82 MSG(" session name: %s", session_name
);
83 MSG(" channel name: %s", channel_name
);
84 MSG(" domain: %s", lttng_domain_type_str(domain_type
));
86 condition_status
= lttng_condition_buffer_usage_get_threshold(
87 condition
, &threshold
);
88 if (condition_status
== LTTNG_CONDITION_STATUS_OK
) {
89 MSG(" threshold (bytes): %" PRIu64
, threshold
);
91 double threshold_ratio
;
93 assert(condition_status
== LTTNG_CONDITION_STATUS_UNSET
);
96 lttng_condition_buffer_usage_get_threshold_ratio(
97 condition
, &threshold_ratio
);
98 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
100 MSG(" threshold (ratio): %.2f", threshold_ratio
);
104 static void print_condition_session_rotation(
105 const struct lttng_condition
*condition
)
107 enum lttng_condition_status condition_status
;
108 const char *session_name
;
110 condition_status
= lttng_condition_session_rotation_get_session_name(
111 condition
, &session_name
);
112 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
114 MSG(" session name: %s", session_name
);
118 * Returns the human-readable log level name associated with a numerical value
119 * if there is one. The Log4j and JUL domains have discontinuous log level
120 * values (a value can fall between two labels). In those cases, NULL is
123 static const char *get_pretty_loglevel_name(
124 enum lttng_domain_type domain
, int loglevel
)
126 const char *name
= NULL
;
129 case LTTNG_DOMAIN_UST
:
130 name
= loglevel_value_to_name(loglevel
);
132 case LTTNG_DOMAIN_LOG4J
:
133 name
= loglevel_log4j_value_to_name(loglevel
);
135 case LTTNG_DOMAIN_JUL
:
136 name
= loglevel_jul_value_to_name(loglevel
);
138 case LTTNG_DOMAIN_PYTHON
:
139 name
= loglevel_python_value_to_name(loglevel
);
149 void print_event_rule_tracepoint(const struct lttng_event_rule
*event_rule
)
151 enum lttng_event_rule_status event_rule_status
;
152 enum lttng_domain_type domain_type
;
156 const struct lttng_log_level_rule
*log_level_rule
= NULL
;
157 unsigned int exclusions_count
;
160 event_rule_status
= lttng_event_rule_tracepoint_get_pattern(
161 event_rule
, &pattern
);
162 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
164 event_rule_status
= lttng_event_rule_tracepoint_get_domain_type(
165 event_rule
, &domain_type
);
166 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
168 _MSG(" rule: %s (type: tracepoint, domain: %s", pattern
,
169 lttng_domain_type_str(domain_type
));
171 event_rule_status
= lttng_event_rule_tracepoint_get_filter(
172 event_rule
, &filter
);
173 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
174 _MSG(", filter: %s", filter
);
176 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
179 event_rule_status
= lttng_event_rule_tracepoint_get_log_level_rule(
180 event_rule
, &log_level_rule
);
181 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
182 enum lttng_log_level_rule_status llr_status
;
183 const char *log_level_op
;
184 const char *pretty_loglevel_name
;
186 switch (lttng_log_level_rule_get_type(log_level_rule
)) {
187 case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY
:
189 llr_status
= lttng_log_level_rule_exactly_get_level(
190 log_level_rule
, &log_level
);
192 case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS
:
193 log_level_op
= "at least";
194 llr_status
= lttng_log_level_rule_at_least_as_severe_as_get_level(
195 log_level_rule
, &log_level
);
201 assert(llr_status
== LTTNG_LOG_LEVEL_RULE_STATUS_OK
);
203 pretty_loglevel_name
= get_pretty_loglevel_name(
204 domain_type
, log_level
);
205 if (pretty_loglevel_name
) {
206 _MSG(", log level %s %s", log_level_op
,
207 pretty_loglevel_name
);
209 _MSG(", log level %s %d", log_level_op
, log_level
);
212 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
215 event_rule_status
= lttng_event_rule_tracepoint_get_exclusions_count(
216 event_rule
, &exclusions_count
);
217 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
218 if (exclusions_count
> 0) {
219 _MSG(", exclusions: ");
220 for (i
= 0; i
< exclusions_count
; i
++) {
221 const char *exclusion
;
223 event_rule_status
= lttng_event_rule_tracepoint_get_exclusion_at_index(
224 event_rule
, i
, &exclusion
);
225 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
227 _MSG("%s%s", i
> 0 ? "," : "", exclusion
);
234 static void print_kernel_probe_location(
235 const struct lttng_kernel_probe_location
*location
)
237 enum lttng_kernel_probe_location_status status
;
238 switch (lttng_kernel_probe_location_get_type(location
)) {
239 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS
:
243 status
= lttng_kernel_probe_location_address_get_address(
245 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
246 ERR("Getting kernel probe location address failed.");
250 _MSG("0x%" PRIx64
, address
);
254 case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET
:
257 const char *symbol_name
;
259 symbol_name
= lttng_kernel_probe_location_symbol_get_name(
262 ERR("Getting kernel probe location symbol name failed.");
266 status
= lttng_kernel_probe_location_symbol_get_offset(
268 if (status
!= LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK
) {
269 ERR("Getting kernel probe location address failed.");
274 _MSG("%s", symbol_name
);
276 _MSG("%s+0x%" PRIx64
, symbol_name
, offset
);
289 void print_event_rule_kernel_probe(const struct lttng_event_rule
*event_rule
)
291 enum lttng_event_rule_status event_rule_status
;
293 const struct lttng_kernel_probe_location
*location
;
295 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
);
297 event_rule_status
= lttng_event_rule_kernel_probe_get_event_name(event_rule
, &name
);
298 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
299 ERR("Failed to get kprobe event rule's name.");
303 event_rule_status
= lttng_event_rule_kernel_probe_get_location(
304 event_rule
, &location
);
305 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
306 ERR("Failed to get kprobe event rule's location.");
310 _MSG(" rule: %s (type: probe, location: ", name
);
312 print_kernel_probe_location(location
);
321 void print_event_rule_userspace_probe(const struct lttng_event_rule
*event_rule
)
323 enum lttng_event_rule_status event_rule_status
;
325 const struct lttng_userspace_probe_location
*location
;
326 enum lttng_userspace_probe_location_type userspace_probe_location_type
;
328 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
);
330 event_rule_status
= lttng_event_rule_userspace_probe_get_event_name(
332 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
333 ERR("Failed to get uprobe event rule's name.");
337 event_rule_status
= lttng_event_rule_userspace_probe_get_location(
338 event_rule
, &location
);
339 if (event_rule_status
!= LTTNG_EVENT_RULE_STATUS_OK
) {
340 ERR("Failed to get uprobe event rule's location.");
344 _MSG(" rule: %s (type: userspace probe, ", name
);
346 userspace_probe_location_type
=
347 lttng_userspace_probe_location_get_type(location
);
349 switch (userspace_probe_location_type
) {
350 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION
:
352 const char *binary_path
, *function_name
;
354 binary_path
= lttng_userspace_probe_location_function_get_binary_path(
356 function_name
= lttng_userspace_probe_location_function_get_function_name(
359 _MSG("location type: ELF, location: %s:%s", binary_path
, function_name
);
362 case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT
:
364 const char *binary_path
, *provider_name
, *probe_name
;
366 binary_path
= lttng_userspace_probe_location_tracepoint_get_binary_path(
368 provider_name
= lttng_userspace_probe_location_tracepoint_get_provider_name(
370 probe_name
= lttng_userspace_probe_location_tracepoint_get_probe_name(
372 _MSG("location type: SDT, location: %s:%s:%s", binary_path
, provider_name
, probe_name
);
386 void print_event_rule_syscall(const struct lttng_event_rule
*event_rule
)
388 const char *pattern
, *filter
;
389 enum lttng_event_rule_status event_rule_status
;
391 assert(lttng_event_rule_get_type(event_rule
) == LTTNG_EVENT_RULE_TYPE_SYSCALL
);
393 event_rule_status
= lttng_event_rule_syscall_get_pattern(
394 event_rule
, &pattern
);
395 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
);
397 _MSG(" rule: %s (type: syscall", pattern
);
399 event_rule_status
= lttng_event_rule_syscall_get_filter(
400 event_rule
, &filter
);
401 if (event_rule_status
== LTTNG_EVENT_RULE_STATUS_OK
) {
402 _MSG(", filter: %s", filter
);
404 assert(event_rule_status
== LTTNG_EVENT_RULE_STATUS_UNSET
);
411 void print_event_rule(const struct lttng_event_rule
*event_rule
)
413 const enum lttng_event_rule_type event_rule_type
=
414 lttng_event_rule_get_type(event_rule
);
416 switch (event_rule_type
) {
417 case LTTNG_EVENT_RULE_TYPE_TRACEPOINT
:
418 print_event_rule_tracepoint(event_rule
);
420 case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE
:
421 print_event_rule_kernel_probe(event_rule
);
423 case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE
:
424 print_event_rule_userspace_probe(event_rule
);
426 case LTTNG_EVENT_RULE_TYPE_SYSCALL
:
427 print_event_rule_syscall(event_rule
);
435 void print_one_event_expr(const struct lttng_event_expr
*event_expr
)
437 enum lttng_event_expr_type type
;
439 type
= lttng_event_expr_get_type(event_expr
);
442 case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD
:
446 name
= lttng_event_expr_event_payload_field_get_name(
452 case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD
:
456 name
= lttng_event_expr_channel_context_field_get_name(
458 _MSG("$ctx.%s", name
);
462 case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD
:
464 const char *provider_name
;
465 const char *type_name
;
467 provider_name
= lttng_event_expr_app_specific_context_field_get_provider_name(
469 type_name
= lttng_event_expr_app_specific_context_field_get_type_name(
472 _MSG("$app.%s:%s", provider_name
, type_name
);
476 case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT
:
479 const struct lttng_event_expr
*parent_expr
;
480 enum lttng_event_expr_status status
;
482 parent_expr
= lttng_event_expr_array_field_element_get_parent_expr(
484 assert(parent_expr
!= NULL
);
486 print_one_event_expr(parent_expr
);
488 status
= lttng_event_expr_array_field_element_get_index(
490 assert(status
== LTTNG_EVENT_EXPR_STATUS_OK
);
502 void print_condition_on_event(const struct lttng_condition
*condition
)
504 const struct lttng_event_rule
*event_rule
;
505 enum lttng_condition_status condition_status
;
506 unsigned int cap_desc_count
, i
;
509 lttng_condition_on_event_get_rule(condition
, &event_rule
);
510 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
512 print_event_rule(event_rule
);
515 lttng_condition_on_event_get_capture_descriptor_count(
516 condition
, &cap_desc_count
);
517 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
519 if (cap_desc_count
> 0) {
522 for (i
= 0; i
< cap_desc_count
; i
++) {
523 const struct lttng_event_expr
*cap_desc
=
524 lttng_condition_on_event_get_capture_descriptor_at_index(
528 print_one_event_expr(cap_desc
);
535 void print_action_errors(const struct lttng_trigger
*trigger
,
536 const struct lttng_action
*action
)
538 unsigned int i
, count
, printed_errors_count
= 0;
539 enum lttng_error_code error_query_ret
;
540 enum lttng_error_query_results_status results_status
;
541 struct lttng_error_query_results
*results
= NULL
;
542 const char *trigger_name
;
544 enum lttng_trigger_status trigger_status
;
545 struct lttng_error_query
*query
=
546 lttng_error_query_action_create(trigger
, action
);
550 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
551 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
553 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
554 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
556 error_query_ret
= lttng_error_query_execute(
557 query
, lttng_session_daemon_command_endpoint
, &results
);
558 if (error_query_ret
!= LTTNG_OK
) {
559 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
560 trigger_name
, (int) trigger_uid
,
561 lttng_strerror(-error_query_ret
));
565 results_status
= lttng_error_query_results_get_count(results
, &count
);
566 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
570 for (i
= 0; i
< count
; i
++) {
571 const struct lttng_error_query_result
*result
;
572 enum lttng_error_query_result_status result_status
;
573 const char *result_name
;
574 const char *result_description
;
575 uint64_t result_value
;
577 results_status
= lttng_error_query_results_get_result(
578 results
, &result
, i
);
579 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
581 result_status
= lttng_error_query_result_get_name(
582 result
, &result_name
);
583 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
584 result_status
= lttng_error_query_result_get_description(
585 result
, &result_description
);
586 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
588 if (lttng_error_query_result_get_type(result
) ==
589 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
590 result_status
= lttng_error_query_result_counter_get_value(
591 result
, &result_value
);
592 assert(result_status
==
593 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
594 if (result_value
== 0) {
599 _MSG(" %s: %" PRIu64
, result_name
,
601 printed_errors_count
++;
603 _MSG(" Unknown error query result type for result '%s' (%s)",
604 result_name
, result_description
);
609 if (printed_errors_count
== 0) {
615 lttng_error_query_destroy(query
);
616 lttng_error_query_results_destroy(results
);
620 void print_one_action(const struct lttng_trigger
*trigger
,
621 const struct lttng_action
*action
)
623 enum lttng_action_type action_type
;
624 enum lttng_action_status action_status
;
625 const struct lttng_rate_policy
*policy
= NULL
;
628 action_type
= lttng_action_get_type(action
);
629 assert(action_type
!= LTTNG_ACTION_TYPE_GROUP
);
631 switch (action_type
) {
632 case LTTNG_ACTION_TYPE_NOTIFY
:
635 action_status
= lttng_action_notify_get_rate_policy(
637 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
638 ERR("Failed to retrieve rate policy.");
642 case LTTNG_ACTION_TYPE_START_SESSION
:
643 action_status
= lttng_action_start_session_get_session_name(
645 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
646 _MSG("start session `%s`", value
);
648 action_status
= lttng_action_start_session_get_rate_policy(
650 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
651 ERR("Failed to retrieve rate policy.");
655 case LTTNG_ACTION_TYPE_STOP_SESSION
:
656 action_status
= lttng_action_stop_session_get_session_name(
658 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
659 _MSG("stop session `%s`", value
);
661 action_status
= lttng_action_stop_session_get_rate_policy(
663 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
664 ERR("Failed to retrieve rate policy.");
668 case LTTNG_ACTION_TYPE_ROTATE_SESSION
:
669 action_status
= lttng_action_rotate_session_get_session_name(
671 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
672 _MSG("rotate session `%s`", value
);
674 action_status
= lttng_action_rotate_session_get_rate_policy(
676 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
677 ERR("Failed to retrieve rate policy.");
681 case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION
:
683 const struct lttng_snapshot_output
*output
;
685 action_status
= lttng_action_snapshot_session_get_session_name(
687 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
688 _MSG("snapshot session `%s`", value
);
690 action_status
= lttng_action_snapshot_session_get_output(
692 if (action_status
== LTTNG_ACTION_STATUS_OK
) {
695 const char *ctrl_url
, *data_url
;
696 bool starts_with_file
, starts_with_net
, starts_with_net6
;
698 ctrl_url
= lttng_snapshot_output_get_ctrl_url(output
);
699 assert(ctrl_url
&& strlen(ctrl_url
) > 0);
701 data_url
= lttng_snapshot_output_get_data_url(output
);
704 starts_with_file
= strncmp(ctrl_url
, "file://", strlen("file://")) == 0;
705 starts_with_net
= strncmp(ctrl_url
, "net://", strlen("net://")) == 0;
706 starts_with_net6
= strncmp(ctrl_url
, "net6://", strlen("net6://")) == 0;
708 if (ctrl_url
[0] == '/' || starts_with_file
) {
709 if (starts_with_file
) {
710 ctrl_url
+= strlen("file://");
713 _MSG(", path: %s", ctrl_url
);
714 } else if (starts_with_net
|| starts_with_net6
) {
715 _MSG(", url: %s", ctrl_url
);
717 assert(strlen(data_url
) > 0);
719 _MSG(", control url: %s, data url: %s", ctrl_url
, data_url
);
722 name
= lttng_snapshot_output_get_name(output
);
724 if (strlen(name
) > 0) {
725 _MSG(", name: %s", name
);
728 max_size
= lttng_snapshot_output_get_maxsize(output
);
729 if (max_size
!= -1ULL) {
730 _MSG(", max size: %" PRIu64
, max_size
);
734 action_status
= lttng_action_snapshot_session_get_rate_policy(
736 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
737 ERR("Failed to retrieve rate policy.");
747 enum lttng_rate_policy_type policy_type
;
748 enum lttng_rate_policy_status policy_status
;
749 uint64_t policy_value
= 0;
751 policy_type
= lttng_rate_policy_get_type(policy
);
753 switch (policy_type
) {
754 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
755 policy_status
= lttng_rate_policy_every_n_get_interval(
756 policy
, &policy_value
);
757 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
758 ERR("Failed to get action rate policy interval");
761 if (policy_value
> 1) {
762 /* The default is 1 so print only when it is a
765 _MSG(", rate policy: after every %" PRIu64
770 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
771 policy_status
= lttng_rate_policy_once_after_n_get_threshold(
772 policy
, &policy_value
);
773 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
774 ERR("Failed to get action rate policy interval");
777 _MSG(", rate policy: once after %" PRIu64
787 print_action_errors(trigger
, action
);
794 void print_trigger_errors(const struct lttng_trigger
*trigger
)
796 unsigned int i
, count
, printed_errors_count
= 0;
797 enum lttng_error_code error_query_ret
;
798 enum lttng_error_query_results_status results_status
;
799 struct lttng_error_query_results
*results
= NULL
;
800 enum lttng_trigger_status trigger_status
;
801 const char *trigger_name
;
803 struct lttng_error_query
*query
=
804 lttng_error_query_trigger_create(trigger
);
808 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
809 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
811 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
812 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
814 error_query_ret
= lttng_error_query_execute(
815 query
, lttng_session_daemon_command_endpoint
, &results
);
816 if (error_query_ret
!= LTTNG_OK
) {
817 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
818 trigger_name
, (int) trigger_uid
,
819 lttng_strerror(-error_query_ret
));
823 results_status
= lttng_error_query_results_get_count(results
, &count
);
824 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
828 for (i
= 0; i
< count
; i
++) {
829 const struct lttng_error_query_result
*result
;
830 enum lttng_error_query_result_status result_status
;
831 const char *result_name
;
832 const char *result_description
;
833 uint64_t result_value
;
835 results_status
= lttng_error_query_results_get_result(
836 results
, &result
, i
);
837 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
839 result_status
= lttng_error_query_result_get_name(
840 result
, &result_name
);
841 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
842 result_status
= lttng_error_query_result_get_description(
843 result
, &result_description
);
844 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
846 if (lttng_error_query_result_get_type(result
) ==
847 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
848 result_status
= lttng_error_query_result_counter_get_value(
849 result
, &result_value
);
850 assert(result_status
==
851 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
852 if (result_value
== 0) {
857 _MSG(" %s: %" PRIu64
, result_name
,
859 printed_errors_count
++;
861 _MSG(" Unknown error query result type for result '%s' (%s)",
862 result_name
, result_description
);
867 if (printed_errors_count
== 0) {
873 lttng_error_query_destroy(query
);
874 lttng_error_query_results_destroy(results
);
878 void print_one_trigger(const struct lttng_trigger
*trigger
)
880 const struct lttng_condition
*condition
;
881 enum lttng_condition_type condition_type
;
882 const struct lttng_action
*action
;
883 enum lttng_action_type action_type
;
884 enum lttng_trigger_status trigger_status
;
888 trigger_status
= lttng_trigger_get_name(trigger
, &name
);
889 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
891 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
892 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
894 MSG("- name: %s", name
);
895 MSG(" owner uid: %d", trigger_uid
);
897 condition
= lttng_trigger_get_const_condition(trigger
);
898 condition_type
= lttng_condition_get_type(condition
);
899 MSG(" condition: %s", lttng_condition_type_str(condition_type
));
900 switch (condition_type
) {
901 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
902 print_condition_session_consumed_size(condition
);
904 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
905 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
906 print_condition_buffer_usage(condition
);
908 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
909 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
910 print_condition_session_rotation(condition
);
912 case LTTNG_CONDITION_TYPE_ON_EVENT
:
913 print_condition_on_event(condition
);
919 action
= lttng_trigger_get_const_action(trigger
);
920 action_type
= lttng_action_get_type(action
);
921 if (action_type
== LTTNG_ACTION_TYPE_GROUP
) {
922 unsigned int count
, i
;
923 enum lttng_action_status action_status
;
927 action_status
= lttng_action_group_get_count(action
, &count
);
928 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
930 for (i
= 0; i
< count
; i
++) {
931 const struct lttng_action
*subaction
=
932 lttng_action_group_get_at_index(
936 print_one_action(trigger
, subaction
);
940 print_one_action(trigger
, action
);
943 print_trigger_errors(trigger
);
947 int compare_triggers_by_name(const void *a
, const void *b
)
949 const struct lttng_trigger
*trigger_a
= *((const struct lttng_trigger
**) a
);
950 const struct lttng_trigger
*trigger_b
= *((const struct lttng_trigger
**) b
);
951 const char *name_a
, *name_b
;
952 enum lttng_trigger_status trigger_status
;
954 trigger_status
= lttng_trigger_get_name(trigger_a
, &name_a
);
955 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
957 trigger_status
= lttng_trigger_get_name(trigger_b
, &name_b
);
958 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
960 return strcmp(name_a
, name_b
);
963 int cmd_list_triggers(int argc
, const char **argv
)
966 struct argpar_parse_ret argpar_parse_ret
= {};
967 struct lttng_triggers
*triggers
= NULL
;
969 struct lttng_dynamic_pointer_array sorted_triggers
;
970 enum lttng_trigger_status trigger_status
;
971 unsigned int num_triggers
;
973 lttng_dynamic_pointer_array_init(&sorted_triggers
, NULL
);
975 argpar_parse_ret
= argpar_parse(
976 argc
- 1, argv
+ 1, list_trigger_options
, true);
977 if (!argpar_parse_ret
.items
) {
978 ERR("%s", argpar_parse_ret
.error
);
982 for (i
= 0; i
< argpar_parse_ret
.items
->n_items
; i
++) {
983 const struct argpar_item
*item
=
984 argpar_parse_ret
.items
->items
[i
];
986 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
987 const struct argpar_item_opt
*item_opt
=
988 (const struct argpar_item_opt
*) item
;
990 switch (item_opt
->descr
->id
) {
996 case OPT_LIST_OPTIONS
:
997 list_cmd_options_argpar(stdout
,
998 list_trigger_options
);
1007 const struct argpar_item_non_opt
*item_non_opt
=
1008 (const struct argpar_item_non_opt
*) item
;
1010 ERR("Unexpected argument: %s", item_non_opt
->arg
);
1014 ret
= lttng_list_triggers(&triggers
);
1015 if (ret
!= LTTNG_OK
) {
1016 ERR("Error listing triggers: %s.", lttng_strerror(-ret
));
1020 trigger_status
= lttng_triggers_get_count(triggers
, &num_triggers
);
1021 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
1022 ERR("Failed to get trigger count.");
1026 for (i
= 0; i
< num_triggers
; i
++) {
1027 const int add_ret
= lttng_dynamic_pointer_array_add_pointer(
1029 (void *) lttng_triggers_get_at_index(triggers
, i
));
1032 ERR("Failed to allocate array of struct lttng_trigger *.");
1037 qsort(sorted_triggers
.array
.buffer
.data
, num_triggers
,
1038 sizeof(struct lttng_trigger
*),
1039 compare_triggers_by_name
);
1041 for (i
= 0; i
< num_triggers
; i
++) {
1042 const struct lttng_trigger
*trigger_to_print
=
1043 (const struct lttng_trigger
*)
1044 lttng_dynamic_pointer_array_get_pointer(
1045 &sorted_triggers
, i
);
1047 print_one_trigger(trigger_to_print
);
1057 argpar_parse_ret_fini(&argpar_parse_ret
);
1058 lttng_triggers_destroy(triggers
);
1059 lttng_dynamic_pointer_array_reset(&sorted_triggers
);