CLI: make list-triggers command print capture expressions
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 21 May 2020 02:42:00 +0000 (22:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 16 Mar 2021 20:40:01 +0000 (16:40 -0400)
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 <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Depends-on: lttng-ust: I8423c510bf6af2f9bf85256e8d6f931d36f7054b

src/bin/lttng/commands/list_triggers.c
tests/regression/tools/trigger/test_list_triggers_cli

index a6f0211938649e269176a3fd60a75de6184df097..05090381e0ca43605f1263f6751a87fdf2a132db 100644 (file)
@@ -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
index e09d7cdc6894763dc50697abd2b0f716e268d5a2..1257ec881cca6ea047ba6ebee10f4ffb6aa2e5b1 100755 (executable)
@@ -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}"
This page took 0.037919 seconds and 4 git commands to generate.