From: Simon Marchi Date: Thu, 21 May 2020 02:42:00 +0000 (-0400) Subject: CLI: make list-triggers command print capture expressions X-Git-Tag: v2.13.0-rc1~227 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b203b4b06b6d895d6745f3c45b83b2a36ae6a989;p=lttng-tools.git CLI: make list-triggers command print capture expressions When printing an event rule condition, in the `list-triggers` command, print the capture expressions associated with that condition. The result looks like: - id: T1 condition: event rule hit rule: allo (type: tracepoint, domain: ust) captures: - $ctx.foo actions: notify - id: T2 condition: event rule hit rule: allo (type: tracepoint, domain: ust) captures: - $app.iga:active_clients actions: notify Change-Id: Iaa902369a2df3edf2928a935f7565a7c21acb861 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau Depends-on: lttng-ust: I8423c510bf6af2f9bf85256e8d6f931d36f7054b --- diff --git a/src/bin/lttng/commands/list_triggers.c b/src/bin/lttng/commands/list_triggers.c index a6f021193..05090381e 100644 --- a/src/bin/lttng/commands/list_triggers.c +++ b/src/bin/lttng/commands/list_triggers.c @@ -294,17 +294,104 @@ void print_event_rule(const struct lttng_event_rule *event_rule) } } +static +void print_one_event_expr(const struct lttng_event_expr *event_expr) +{ + enum lttng_event_expr_type type; + + type = lttng_event_expr_get_type(event_expr); + + switch (type) { + case LTTNG_EVENT_EXPR_TYPE_EVENT_PAYLOAD_FIELD: + { + const char *name; + + name = lttng_event_expr_event_payload_field_get_name( + event_expr); + _MSG("%s", name); + + break; + } + case LTTNG_EVENT_EXPR_TYPE_CHANNEL_CONTEXT_FIELD: + { + const char *name; + + name = lttng_event_expr_channel_context_field_get_name( + event_expr); + _MSG("$ctx.%s", name); + + break; + } + case LTTNG_EVENT_EXPR_TYPE_APP_SPECIFIC_CONTEXT_FIELD: + { + const char *provider_name; + const char *type_name; + + provider_name = lttng_event_expr_app_specific_context_field_get_provider_name( + event_expr); + type_name = lttng_event_expr_app_specific_context_field_get_type_name( + event_expr); + + _MSG("$app.%s:%s", provider_name, type_name); + + break; + } + case LTTNG_EVENT_EXPR_TYPE_ARRAY_FIELD_ELEMENT: + { + unsigned int index; + const struct lttng_event_expr *parent_expr; + enum lttng_event_expr_status status; + + parent_expr = lttng_event_expr_array_field_element_get_parent_expr( + event_expr); + assert(parent_expr != NULL); + + print_one_event_expr(parent_expr); + + status = lttng_event_expr_array_field_element_get_index( + event_expr, &index); + assert(status == LTTNG_EVENT_EXPR_STATUS_OK); + + _MSG("[%u]", index); + + break; + } + default: + abort(); + } +} + static void print_condition_event_rule_hit(const struct lttng_condition *condition) { const struct lttng_event_rule *event_rule; enum lttng_condition_status condition_status; + unsigned int cap_desc_count, i; condition_status = lttng_condition_event_rule_get_rule(condition, &event_rule); assert(condition_status == LTTNG_CONDITION_STATUS_OK); print_event_rule(event_rule); + + condition_status = + lttng_condition_event_rule_get_capture_descriptor_count( + condition, &cap_desc_count); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + if (cap_desc_count > 0) { + MSG(" captures:"); + + for (i = 0; i < cap_desc_count; i++) { + const struct lttng_event_expr *cap_desc = + lttng_condition_event_rule_get_capture_descriptor_at_index( + condition, i); + + _MSG(" - "); + print_one_event_expr(cap_desc); + MSG(""); + } + } } static diff --git a/tests/regression/tools/trigger/test_list_triggers_cli b/tests/regression/tools/trigger/test_list_triggers_cli index e09d7cdc6..1257ec881 100755 --- a/tests/regression/tools/trigger/test_list_triggers_cli +++ b/tests/regression/tools/trigger/test_list_triggers_cli @@ -23,7 +23,7 @@ TESTDIR="$CURDIR/../../.." # shellcheck source=../../../utils/utils.sh source "$TESTDIR/utils/utils.sh" -plan_tests 40 +plan_tests 44 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" @@ -110,6 +110,11 @@ test_on_event_tracepoint () add_trigger --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify add_trigger --id BCD --condition on-event -u gerboise --loglevel INFO --action notify add_trigger --condition on-event -u lemming --loglevel-only WARNING --action notify + add_trigger --condition on-event -u capture-payload-field --capture a --action notify + add_trigger --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify + add_trigger --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify + add_trigger --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify + cat > "${tmp_expected_stdout}" <<- EOF - id: ABC @@ -142,6 +147,39 @@ test_on_event_tracepoint () rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING) actions: notify + - id: T3 + user id: ${uid} + condition: event rule hit + rule: capture-payload-field (type: tracepoint, domain: ust) + captures: + - a + actions: + notify + - id: T4 + user id: ${uid} + condition: event rule hit + rule: capture-array (type: tracepoint, domain: ust) + captures: + - a[2] + - \$ctx.tourlou[18] + actions: + notify + - id: T5 + user id: ${uid} + condition: event rule hit + rule: capture-chan-ctx (type: tracepoint, domain: ust) + captures: + - \$ctx.vpid + actions: + notify + - id: T6 + user id: ${uid} + condition: event rule hit + rule: capture-app-ctx (type: tracepoint, domain: ust) + captures: + - \$app.iga:active_clients + actions: + notify EOF list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"