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
);
510 void print_condition_on_event(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
;
517 lttng_condition_on_event_get_rule(condition
, &event_rule
);
518 assert(condition_status
== LTTNG_CONDITION_STATUS_OK
);
520 print_event_rule(event_rule
);
523 lttng_condition_on_event_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_on_event_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
);
559 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
561 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
562 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
564 error_query_ret
= lttng_error_query_execute(
565 query
, lttng_session_daemon_command_endpoint
, &results
);
566 if (error_query_ret
!= LTTNG_OK
) {
567 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
568 trigger_name
, (int) trigger_uid
,
569 lttng_strerror(-error_query_ret
));
573 results_status
= lttng_error_query_results_get_count(results
, &count
);
574 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
578 for (i
= 0; i
< count
; i
++) {
579 const struct lttng_error_query_result
*result
;
580 enum lttng_error_query_result_status result_status
;
581 const char *result_name
;
582 const char *result_description
;
583 uint64_t result_value
;
585 results_status
= lttng_error_query_results_get_result(
586 results
, &result
, i
);
587 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
589 result_status
= lttng_error_query_result_get_name(
590 result
, &result_name
);
591 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
592 result_status
= lttng_error_query_result_get_description(
593 result
, &result_description
);
594 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
596 if (lttng_error_query_result_get_type(result
) ==
597 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
598 result_status
= lttng_error_query_result_counter_get_value(
599 result
, &result_value
);
600 assert(result_status
==
601 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
602 if (result_value
== 0) {
607 _MSG(" %s: %" PRIu64
, result_name
,
609 printed_errors_count
++;
611 _MSG(" Unknown error query result type for result '%s' (%s)",
612 result_name
, result_description
);
617 if (printed_errors_count
== 0) {
623 lttng_error_query_destroy(query
);
624 lttng_error_query_results_destroy(results
);
628 void print_one_action(const struct lttng_trigger
*trigger
,
629 const struct lttng_action
*action
)
631 enum lttng_action_type action_type
;
632 enum lttng_action_status action_status
;
633 const struct lttng_rate_policy
*policy
= NULL
;
636 action_type
= lttng_action_get_type(action
);
637 assert(action_type
!= LTTNG_ACTION_TYPE_GROUP
);
639 switch (action_type
) {
640 case LTTNG_ACTION_TYPE_NOTIFY
:
643 action_status
= lttng_action_notify_get_rate_policy(
645 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
646 ERR("Failed to retrieve rate policy.");
650 case LTTNG_ACTION_TYPE_START_SESSION
:
651 action_status
= lttng_action_start_session_get_session_name(
653 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
654 _MSG("start session `%s`", value
);
656 action_status
= lttng_action_start_session_get_rate_policy(
658 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
659 ERR("Failed to retrieve rate policy.");
663 case LTTNG_ACTION_TYPE_STOP_SESSION
:
664 action_status
= lttng_action_stop_session_get_session_name(
666 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
667 _MSG("stop session `%s`", value
);
669 action_status
= lttng_action_stop_session_get_rate_policy(
671 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
672 ERR("Failed to retrieve rate policy.");
676 case LTTNG_ACTION_TYPE_ROTATE_SESSION
:
677 action_status
= lttng_action_rotate_session_get_session_name(
679 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
680 _MSG("rotate session `%s`", value
);
682 action_status
= lttng_action_rotate_session_get_rate_policy(
684 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
685 ERR("Failed to retrieve rate policy.");
689 case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION
:
691 const struct lttng_snapshot_output
*output
;
693 action_status
= lttng_action_snapshot_session_get_session_name(
695 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
696 _MSG("snapshot session `%s`", value
);
698 action_status
= lttng_action_snapshot_session_get_output(
700 if (action_status
== LTTNG_ACTION_STATUS_OK
) {
703 const char *ctrl_url
, *data_url
;
704 bool starts_with_file
, starts_with_net
, starts_with_net6
;
706 ctrl_url
= lttng_snapshot_output_get_ctrl_url(output
);
707 assert(ctrl_url
&& strlen(ctrl_url
) > 0);
709 data_url
= lttng_snapshot_output_get_data_url(output
);
712 starts_with_file
= strncmp(ctrl_url
, "file://", strlen("file://")) == 0;
713 starts_with_net
= strncmp(ctrl_url
, "net://", strlen("net://")) == 0;
714 starts_with_net6
= strncmp(ctrl_url
, "net6://", strlen("net6://")) == 0;
716 if (ctrl_url
[0] == '/' || starts_with_file
) {
717 if (starts_with_file
) {
718 ctrl_url
+= strlen("file://");
721 _MSG(", path: %s", ctrl_url
);
722 } else if (starts_with_net
|| starts_with_net6
) {
723 _MSG(", url: %s", ctrl_url
);
725 assert(strlen(data_url
) > 0);
727 _MSG(", control url: %s, data url: %s", ctrl_url
, data_url
);
730 name
= lttng_snapshot_output_get_name(output
);
732 if (strlen(name
) > 0) {
733 _MSG(", name: %s", name
);
736 max_size
= lttng_snapshot_output_get_maxsize(output
);
737 if (max_size
!= -1ULL) {
738 _MSG(", max size: %" PRIu64
, max_size
);
742 action_status
= lttng_action_snapshot_session_get_rate_policy(
744 if (action_status
!= LTTNG_ACTION_STATUS_OK
) {
745 ERR("Failed to retrieve rate policy.");
755 enum lttng_rate_policy_type policy_type
;
756 enum lttng_rate_policy_status policy_status
;
757 uint64_t policy_value
= 0;
759 policy_type
= lttng_rate_policy_get_type(policy
);
761 switch (policy_type
) {
762 case LTTNG_RATE_POLICY_TYPE_EVERY_N
:
763 policy_status
= lttng_rate_policy_every_n_get_interval(
764 policy
, &policy_value
);
765 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
766 ERR("Failed to get action rate policy interval");
769 if (policy_value
> 1) {
770 /* The default is 1 so print only when it is a
773 _MSG(", rate policy: after every %" PRIu64
778 case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N
:
779 policy_status
= lttng_rate_policy_once_after_n_get_threshold(
780 policy
, &policy_value
);
781 if (policy_status
!= LTTNG_RATE_POLICY_STATUS_OK
) {
782 ERR("Failed to get action rate policy interval");
785 _MSG(", rate policy: once after %" PRIu64
795 print_action_errors(trigger
, action
);
802 void print_trigger_errors(const struct lttng_trigger
*trigger
)
804 unsigned int i
, count
, printed_errors_count
= 0;
805 enum lttng_error_code error_query_ret
;
806 enum lttng_error_query_results_status results_status
;
807 struct lttng_error_query_results
*results
= NULL
;
808 enum lttng_trigger_status trigger_status
;
809 const char *trigger_name
;
811 struct lttng_error_query
*query
=
812 lttng_error_query_trigger_create(trigger
);
816 trigger_status
= lttng_trigger_get_name(trigger
, &trigger_name
);
817 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
819 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
820 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
822 error_query_ret
= lttng_error_query_execute(
823 query
, lttng_session_daemon_command_endpoint
, &results
);
824 if (error_query_ret
!= LTTNG_OK
) {
825 ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s",
826 trigger_name
, (int) trigger_uid
,
827 lttng_strerror(-error_query_ret
));
831 results_status
= lttng_error_query_results_get_count(results
, &count
);
832 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
836 for (i
= 0; i
< count
; i
++) {
837 const struct lttng_error_query_result
*result
;
838 enum lttng_error_query_result_status result_status
;
839 const char *result_name
;
840 const char *result_description
;
841 uint64_t result_value
;
843 results_status
= lttng_error_query_results_get_result(
844 results
, &result
, i
);
845 assert(results_status
== LTTNG_ERROR_QUERY_RESULTS_STATUS_OK
);
847 result_status
= lttng_error_query_result_get_name(
848 result
, &result_name
);
849 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
850 result_status
= lttng_error_query_result_get_description(
851 result
, &result_description
);
852 assert(result_status
== LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
854 if (lttng_error_query_result_get_type(result
) ==
855 LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER
) {
856 result_status
= lttng_error_query_result_counter_get_value(
857 result
, &result_value
);
858 assert(result_status
==
859 LTTNG_ERROR_QUERY_RESULT_STATUS_OK
);
860 if (result_value
== 0) {
865 _MSG(" %s: %" PRIu64
, result_name
,
867 printed_errors_count
++;
869 _MSG(" Unknown error query result type for result '%s' (%s)",
870 result_name
, result_description
);
875 if (printed_errors_count
== 0) {
881 lttng_error_query_destroy(query
);
882 lttng_error_query_results_destroy(results
);
886 void print_one_trigger(const struct lttng_trigger
*trigger
)
888 const struct lttng_condition
*condition
;
889 enum lttng_condition_type condition_type
;
890 const struct lttng_action
*action
;
891 enum lttng_action_type action_type
;
892 enum lttng_trigger_status trigger_status
;
896 trigger_status
= lttng_trigger_get_name(trigger
, &name
);
897 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
899 trigger_status
= lttng_trigger_get_owner_uid(trigger
, &trigger_uid
);
900 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
902 MSG("- name: %s", name
);
903 MSG(" owner uid: %d", trigger_uid
);
905 condition
= lttng_trigger_get_const_condition(trigger
);
906 condition_type
= lttng_condition_get_type(condition
);
907 MSG(" condition: %s", lttng_condition_type_str(condition_type
));
908 switch (condition_type
) {
909 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
910 print_condition_session_consumed_size(condition
);
912 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
913 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
914 print_condition_buffer_usage(condition
);
916 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
917 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
918 print_condition_session_rotation(condition
);
920 case LTTNG_CONDITION_TYPE_ON_EVENT
:
921 print_condition_on_event(condition
);
927 action
= lttng_trigger_get_const_action(trigger
);
928 action_type
= lttng_action_get_type(action
);
929 if (action_type
== LTTNG_ACTION_TYPE_GROUP
) {
930 unsigned int count
, i
;
931 enum lttng_action_status action_status
;
935 action_status
= lttng_action_group_get_count(action
, &count
);
936 assert(action_status
== LTTNG_ACTION_STATUS_OK
);
938 for (i
= 0; i
< count
; i
++) {
939 const struct lttng_action
*subaction
=
940 lttng_action_group_get_at_index(
944 print_one_action(trigger
, subaction
);
948 print_one_action(trigger
, action
);
951 print_trigger_errors(trigger
);
955 int compare_triggers_by_name(const void *a
, const void *b
)
957 const struct lttng_trigger
*trigger_a
= *((const struct lttng_trigger
**) a
);
958 const struct lttng_trigger
*trigger_b
= *((const struct lttng_trigger
**) b
);
959 const char *name_a
, *name_b
;
960 enum lttng_trigger_status trigger_status
;
962 trigger_status
= lttng_trigger_get_name(trigger_a
, &name_a
);
963 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
965 trigger_status
= lttng_trigger_get_name(trigger_b
, &name_b
);
966 assert(trigger_status
== LTTNG_TRIGGER_STATUS_OK
);
968 return strcmp(name_a
, name_b
);
971 int cmd_list_triggers(int argc
, const char **argv
)
974 struct argpar_parse_ret argpar_parse_ret
= {};
975 struct lttng_triggers
*triggers
= NULL
;
977 struct lttng_dynamic_pointer_array sorted_triggers
;
978 enum lttng_trigger_status trigger_status
;
979 unsigned int num_triggers
;
981 lttng_dynamic_pointer_array_init(&sorted_triggers
, NULL
);
983 argpar_parse_ret
= argpar_parse(
984 argc
- 1, argv
+ 1, list_trigger_options
, true);
985 if (!argpar_parse_ret
.items
) {
986 ERR("%s", argpar_parse_ret
.error
);
990 for (i
= 0; i
< argpar_parse_ret
.items
->n_items
; i
++) {
991 const struct argpar_item
*item
=
992 argpar_parse_ret
.items
->items
[i
];
994 if (item
->type
== ARGPAR_ITEM_TYPE_OPT
) {
995 const struct argpar_item_opt
*item_opt
=
996 (const struct argpar_item_opt
*) item
;
998 switch (item_opt
->descr
->id
) {
1004 case OPT_LIST_OPTIONS
:
1005 list_cmd_options_argpar(stdout
,
1006 list_trigger_options
);
1015 const struct argpar_item_non_opt
*item_non_opt
=
1016 (const struct argpar_item_non_opt
*) item
;
1018 ERR("Unexpected argument: %s", item_non_opt
->arg
);
1022 ret
= lttng_list_triggers(&triggers
);
1023 if (ret
!= LTTNG_OK
) {
1024 ERR("Error listing triggers: %s.", lttng_strerror(-ret
));
1028 trigger_status
= lttng_triggers_get_count(triggers
, &num_triggers
);
1029 if (trigger_status
!= LTTNG_TRIGGER_STATUS_OK
) {
1030 ERR("Failed to get trigger count.");
1034 for (i
= 0; i
< num_triggers
; i
++) {
1035 const int add_ret
= lttng_dynamic_pointer_array_add_pointer(
1037 (void *) lttng_triggers_get_at_index(triggers
, i
));
1040 ERR("Failed to allocate array of struct lttng_trigger *.");
1045 qsort(sorted_triggers
.array
.buffer
.data
, num_triggers
,
1046 sizeof(struct lttng_trigger
*),
1047 compare_triggers_by_name
);
1049 for (i
= 0; i
< num_triggers
; i
++) {
1050 const struct lttng_trigger
*trigger_to_print
=
1051 (const struct lttng_trigger
*)
1052 lttng_dynamic_pointer_array_get_pointer(
1053 &sorted_triggers
, i
);
1055 print_one_trigger(trigger_to_print
);
1065 argpar_parse_ret_fini(&argpar_parse_ret
);
1066 lttng_triggers_destroy(triggers
);
1067 lttng_dynamic_pointer_array_reset(&sorted_triggers
);