2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include "event-notifier-error-accounting.h"
9 #include <lttng/error-query-internal.h>
10 #include <lttng/trigger/trigger-internal.h>
11 #include <lttng/action/action-internal.h>
14 enum lttng_trigger_status
lttng_trigger_add_error_results(
15 const struct lttng_trigger
*trigger
,
16 struct lttng_error_query_results
*results
)
18 enum lttng_trigger_status status
;
19 uint64_t discarded_tracer_messages_count
;
20 enum event_notifier_error_accounting_status error_accounting_status
;
21 struct lttng_error_query_result
*discarded_tracer_messages_counter
= NULL
;
22 const char *trigger_name
;
25 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
26 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
27 trigger_name
: "(unnamed)";
28 status
= lttng_trigger_get_owner_uid(trigger
,
30 assert(status
== LTTNG_TRIGGER_STATUS_OK
);
32 /* Only add discarded tracer messages count for applicable triggers. */
33 if (!lttng_trigger_needs_tracer_notifier(trigger
)) {
34 status
= LTTNG_TRIGGER_STATUS_OK
;
38 error_accounting_status
= event_notifier_error_accounting_get_count(
39 trigger
, &discarded_tracer_messages_count
);
40 if (error_accounting_status
!= EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK
) {
41 ERR("Failed to retrieve tracer discarded messages count for triger: triggger name = '%s', trigger owner uid = %d",
42 trigger_name
, (int) trigger_owner
);
43 status
= LTTNG_TRIGGER_STATUS_ERROR
;
47 discarded_tracer_messages_counter
= lttng_error_query_result_counter_create(
48 "discarded tracer messages",
49 "Count of messages discarded by the tracer due to a communication error with the session daemon",
50 discarded_tracer_messages_count
);
51 if (!discarded_tracer_messages_counter
) {
52 status
= LTTNG_TRIGGER_STATUS_ERROR
;
56 if (lttng_error_query_results_add_result(
57 results
, discarded_tracer_messages_counter
)) {
58 status
= LTTNG_TRIGGER_STATUS_ERROR
;
62 /* Ownership transferred to the results. */
63 discarded_tracer_messages_counter
= NULL
;
65 status
= LTTNG_TRIGGER_STATUS_OK
;
67 lttng_error_query_result_destroy(discarded_tracer_messages_counter
);
72 enum lttng_trigger_status
lttng_trigger_add_action_error_query_results(
73 struct lttng_trigger
*trigger
,
74 struct lttng_error_query_results
*results
)
76 enum lttng_trigger_status status
;
77 const char *trigger_name
;
79 enum lttng_action_status action_status
;
81 status
= lttng_trigger_get_name(trigger
, &trigger_name
);
82 trigger_name
= status
== LTTNG_TRIGGER_STATUS_OK
?
83 trigger_name
: "(unnamed)";
84 status
= lttng_trigger_get_owner_uid(trigger
,
86 assert(status
== LTTNG_TRIGGER_STATUS_OK
);
88 action_status
= lttng_action_add_error_query_results(
89 lttng_trigger_get_action(trigger
), results
);
90 switch (action_status
) {
91 case LTTNG_ACTION_STATUS_OK
:
94 status
= LTTNG_TRIGGER_STATUS_ERROR
;
98 status
= LTTNG_TRIGGER_STATUS_OK
;