X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_trigger.c;h=a885aea61c88acdbe5086c20838e1f6b9a80c9c5;hp=17e06445b49ca9f8d6b9a935beecd77c38ca05a8;hb=50ad08620ff49e3c27e6eb3fea5151e744ae13ec;hpb=e45dd625d3e802d8e6e2ec3de180c73546e8f9fe diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index 17e06445b..a885aea61 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -40,13 +40,13 @@ enum { OPT_CONDITION, OPT_ACTION, OPT_ID, - OPT_FIRE_ONCE_AFTER, - OPT_FIRE_EVERY, OPT_USER_ID, + OPT_RATE_POLICY, - OPT_ALL, + OPT_NAME, OPT_FILTER, - OPT_EXCLUDE, + OPT_EXCLUDE_NAMES, + OPT_EVENT_NAME, OPT_LOGLEVEL, OPT_LOGLEVEL_ONLY, @@ -62,7 +62,6 @@ enum { OPT_SYSCALL, OPT_TRACEPOINT, - OPT_NAME, OPT_MAX_SIZE, OPT_DATA_URL, OPT_CTRL_URL, @@ -73,11 +72,12 @@ enum { }; static const struct argpar_opt_descr event_rule_opt_descrs[] = { - { OPT_ALL, 'a', "all", false }, { OPT_FILTER, 'f', "filter", true }, - { OPT_EXCLUDE, 'x', "exclude", true }, + { OPT_NAME, 'n', "name", true }, + { OPT_EXCLUDE_NAMES, 'x', "exclude-names", true }, { OPT_LOGLEVEL, '\0', "loglevel", true }, { OPT_LOGLEVEL_ONLY, '\0', "loglevel-only", true }, + { OPT_EVENT_NAME, 'E', "event-name", true }, /* Domains */ { OPT_USERSPACE, 'u', "userspace", false }, @@ -543,22 +543,18 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) struct filter_parser_ctx *parser_ctx = NULL; struct lttng_log_level_rule *log_level_rule = NULL; - /* Was the -a/--all flag provided? */ - bool all_events = false; - - /* Tracepoint name (non-option argument). */ - const char *tracepoint_name = NULL; + /* Tracepoint and syscall options. */ + char *name = NULL; + char *exclude_names = NULL; + char **exclusion_list = NULL; /* Holds the argument of --probe / --userspace-probe. */ - char *source = NULL; + char *probe_source = NULL; + char *probe_event_name = NULL; /* Filter. */ char *filter = NULL; - /* Exclude. */ - char *exclude = NULL; - char **exclusion_list = NULL; - /* Log level. */ char *loglevel_str = NULL; bool loglevel_only = false; @@ -639,7 +635,8 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - if (!assign_string(&source, item_opt->arg, "source")) { + if (!assign_string(&probe_source, item_opt->arg, + "--probe")) { goto error; } @@ -650,8 +647,17 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - if (!assign_string(&source, item_opt->arg, "source")) { - goto error; + if (!assign_string(&probe_source, item_opt->arg, + "--userspace-probe")) { + goto error; + } + + break; + case OPT_EVENT_NAME: + if (!assign_string(&probe_event_name, + item_opt->arg, + "--event-name/-E")) { + goto error; } break; @@ -668,9 +674,6 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - break; - case OPT_ALL: - all_events = true; break; case OPT_FILTER: if (!assign_string(&filter, item_opt->arg, @@ -679,9 +682,17 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } break; - case OPT_EXCLUDE: - if (!assign_string(&exclude, item_opt->arg, - "--exclude/-x")) { + case OPT_NAME: + if (!assign_string(&name, item_opt->arg, + "--name/-n")) { + goto error; + } + + break; + case OPT_EXCLUDE_NAMES: + if (!assign_string(&exclude_names, + item_opt->arg, + "--exclude-names/-x")) { goto error; } @@ -743,17 +754,9 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) (const struct argpar_item_non_opt *) item; - /* - * Don't accept two non-option arguments/tracepoint - * names. - */ - if (tracepoint_name) { - ERR("Unexpected argument '%s'", - item_non_opt->arg); - goto error; - } - - tracepoint_name = item_non_opt->arg; + /* Don't accept non-option arguments. */ + ERR("Unexpected argument '%s'", item_non_opt->arg); + goto error; } } @@ -762,44 +765,54 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } /* - * Option -a is applicable to event rules of type tracepoint and - * syscall, and it is equivalent to using "*" as the tracepoint name. + * Option --name is applicable to event rules of type tracepoint + * and syscall. For tracepoint and syscall rules, if --name is + * omitted, it is implicitly "*". */ - if (all_events) { - switch (event_rule_type) { - case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: - case LTTNG_EVENT_RULE_TYPE_SYSCALL: - break; - default: - ERR("Can't use -a/--all with %s event rules.", - lttng_event_rule_type_str(event_rule_type)); - goto error; + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: + case LTTNG_EVENT_RULE_TYPE_SYSCALL: + if (!name) { + name = strdup("*"); } + break; - if (tracepoint_name) { - ERR("Can't provide a tracepoint name with -a/--all."); + default: + if (name) { + ERR("Can't use --name with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); goto error; } - /* In which case, it's equivalent to tracepoint name "*". */ - tracepoint_name = "*"; + if (exclude_names) { + ERR("Can't use --exclude-names/-x with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); + goto error; + } } /* - * A tracepoint name (or -a, for the event rule types that accept it) - * is required. + * Option --event-name is only applicable to event rules of type probe. + * If omitted, it defaults to the probe location. */ - if (!tracepoint_name) { - ERR("Need to provide either a tracepoint name or -a/--all."); - goto error; - } + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: + case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: + if (!probe_event_name) { + probe_event_name = strdup(probe_source); + } - /* - * We don't support multiple tracepoint names for now. - */ - if (strchr(tracepoint_name, ',')) { - ERR("Comma separated tracepoint names are not supported."); - goto error; + break; + + default: + if (probe_event_name) { + ERR("Can't use --event-name with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); + goto error; + } } /* @@ -853,16 +866,15 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } /* If --exclude/-x was passed, split it into an exclusion list. */ - if (exclude) { + if (exclude_names) { if (domain_type != LTTNG_DOMAIN_UST) { ERR("Event name exclusions are not yet implemented for %s event rules.", get_domain_str(domain_type)); goto error; } - - if (create_exclusion_list_and_validate(tracepoint_name, exclude, - &exclusion_list) != 0) { + if (create_exclusion_list_and_validate(name, + exclude_names, &exclusion_list) != 0) { ERR("Failed to create exclusion list."); goto error; } @@ -887,10 +899,10 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) /* Set pattern. */ event_rule_status = lttng_event_rule_tracepoint_set_pattern( - res.er, tracepoint_name); + res.er, name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set tracepoint event rule's pattern to '%s'.", - tracepoint_name); + name); goto error; } @@ -966,8 +978,8 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) int ret; enum lttng_event_rule_status event_rule_status; - - ret = parse_kernel_probe_opts(source, &kernel_probe_location); + ret = parse_kernel_probe_opts( + probe_source, &kernel_probe_location); if (ret) { ERR("Failed to parse kernel probe location."); goto error; @@ -980,9 +992,12 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - event_rule_status = lttng_event_rule_kernel_probe_set_event_name(res.er, tracepoint_name); + event_rule_status = + lttng_event_rule_kernel_probe_set_event_name( + res.er, probe_event_name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { - ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name); + ERR("Failed to set kprobe event rule's name to '%s'.", + probe_event_name); goto error; } @@ -994,7 +1009,7 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) enum lttng_event_rule_status event_rule_status; ret = parse_userspace_probe_opts( - source, &userspace_probe_location); + probe_source, &userspace_probe_location); if (ret) { ERR("Failed to parse user space probe location."); goto error; @@ -1006,11 +1021,12 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - event_rule_status = lttng_event_rule_userspace_probe_set_event_name( - res.er, tracepoint_name); + event_rule_status = + lttng_event_rule_userspace_probe_set_event_name( + res.er, probe_event_name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set user space probe event rule's name to '%s'.", - tracepoint_name); + probe_event_name); goto error; } @@ -1027,10 +1043,10 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } event_rule_status = lttng_event_rule_syscall_set_pattern( - res.er, tracepoint_name); + res.er, name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set syscall event rule's pattern to '%s'.", - tracepoint_name); + name); goto error; } @@ -1068,9 +1084,12 @@ end: free(error); argpar_state_destroy(state); free(filter); - free(exclude); + free(name); + free(exclude_names); free(loglevel_str); - free(source); + free(probe_source); + free(probe_event_name); + strutils_free_null_terminated_array_of_strings(exclusion_list); lttng_kernel_probe_location_destroy(kernel_probe_location); lttng_userspace_probe_location_destroy(userspace_probe_location); @@ -1285,7 +1304,7 @@ struct condition_descr { static const struct condition_descr condition_descrs[] = { - { "on-event", handle_condition_event }, + { "event-rule-matches", handle_condition_event }, { "on-session-consumed-size", handle_condition_session_consumed_size }, { "on-buffer-usage-high", handle_condition_buffer_usage_high }, { "on-buffer-usage-low", handle_condition_buffer_usage_low }, @@ -1294,23 +1313,13 @@ struct condition_descr condition_descrs[] = { }; static -struct lttng_condition *parse_condition(int *argc, const char ***argv) +struct lttng_condition *parse_condition(const char *condition_name, int *argc, + const char ***argv) { int i; struct lttng_condition *cond; - const char *condition_name; const struct condition_descr *descr = NULL; - if (*argc == 0) { - ERR("Missing condition name."); - goto error; - } - - condition_name = (*argv)[0]; - - (*argc)--; - (*argv)++; - for (i = 0; i < ARRAY_SIZE(condition_descrs); i++) { if (strcmp(condition_name, condition_descrs[i].name) == 0) { descr = &condition_descrs[i]; @@ -1335,13 +1344,84 @@ error: end: return cond; } + +static struct lttng_rate_policy *parse_rate_policy(const char *policy_str) +{ + int num_token; + char **tokens = NULL; + struct lttng_rate_policy *policy = NULL; + enum lttng_rate_policy_type policy_type; + unsigned long long value; + char *policy_type_str; + char *policy_value_str; + + assert(policy_str); + + /* + * rate policy fields are separated by ':'. + */ + tokens = strutils_split(policy_str, ':', 1); + num_token = strutils_array_of_strings_len(tokens); + + /* + * Early sanity check that the number of parameter is exactly 2. + * i.e : type:value + */ + if (num_token != 2) { + ERR("Rate policy format is invalid."); + goto end; + } + + policy_type_str = tokens[0]; + policy_value_str = tokens[1]; + + /* Parse the type. */ + if (strcmp(policy_type_str, "once-after") == 0) { + policy_type = LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N; + } else if (strcmp(policy_type_str, "every") == 0) { + policy_type = LTTNG_RATE_POLICY_TYPE_EVERY_N; + } else { + ERR("Rate policy type `%s` unknown.", policy_type_str); + goto end; + } + + /* Parse the value. */ + if (utils_parse_unsigned_long_long(policy_value_str, &value) != 0) { + ERR("Failed to parse rate policy value `%s` as an integer.", + policy_value_str); + goto end; + } + + if (value == 0) { + ERR("Rate policy value `%s` must be > 0.", policy_value_str); + goto end; + } + + switch (policy_type) { + case LTTNG_RATE_POLICY_TYPE_EVERY_N: + policy = lttng_rate_policy_every_n_create(value); + break; + case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N: + policy = lttng_rate_policy_once_after_n_create(value); + break; + default: + abort(); + } + + if (policy == NULL) { + ERR("Failed to create rate policy `%s`.", policy_str); + } + +end: + strutils_free_null_terminated_array_of_strings(tokens); + return policy; +} + static const struct argpar_opt_descr notify_action_opt_descrs[] = { - { OPT_FIRE_ONCE_AFTER, '\0', "fire-once-after", true }, - { OPT_FIRE_EVERY, '\0', "fire-every", true }, + { OPT_RATE_POLICY, '\0', "rate-policy", true }, ARGPAR_OPT_DESCR_SENTINEL }; - static struct lttng_action *handle_action_notify(int *argc, const char ***argv) { @@ -1349,9 +1429,7 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv) struct argpar_state *state = NULL; struct argpar_item *item = NULL; char *error = NULL; - char *fire_once_after_str = NULL; - char *fire_every_str = NULL; - struct lttng_firing_policy *policy = NULL; + struct lttng_rate_policy *policy = NULL; state = argpar_state_create(*argc, *argv, notify_action_opt_descrs); if (!state) { @@ -1381,27 +1459,14 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv) (const struct argpar_item_opt *) item; switch (item_opt->descr->id) { - case OPT_FIRE_ONCE_AFTER: + case OPT_RATE_POLICY: { - if (!assign_string(&fire_once_after_str, - item_opt->arg, - "--fire-once-after")) { + policy = parse_rate_policy(item_opt->arg); + if (!policy) { goto error; } - break; } - case OPT_FIRE_EVERY: - { - if (!assign_string(&fire_every_str, - item_opt->arg, - "--fire-every")) { - goto error; - } - - break; - } - default: abort(); } @@ -1424,55 +1489,6 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv) *argc -= argpar_state_get_ingested_orig_args(state); *argv += argpar_state_get_ingested_orig_args(state); - if (fire_once_after_str && fire_every_str) { - ERR("--fire-once and --fire-every are mutually exclusive."); - goto error; - } - - if (fire_once_after_str) { - unsigned long long threshold; - - if (utils_parse_unsigned_long_long( - fire_once_after_str, &threshold) != 0) { - ERR("Failed to parse `%s` as an integer.", - fire_once_after_str); - goto error; - } - - if (threshold == 0) { - ERR("Once after N policy threshold cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_once_after_n_create(threshold); - if (!policy) { - ERR("Failed to create policy once after `%s`.", - fire_once_after_str); - goto error; - } - } - - if (fire_every_str) { - unsigned long long interval; - if (utils_parse_unsigned_long_long(fire_every_str, &interval) != - 0) { - ERR("Failed to parse `%s` as an integer.", - fire_every_str); - goto error; - } - if (interval == 0) { - ERR("Every N policy interval cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_every_n_create(interval); - if (!policy) { - ERR("Failed to create policy every `%s`.", - fire_every_str); - goto error; - } - } - action = lttng_action_notify_create(); if (!action) { ERR("Failed to create notify action"); @@ -1481,9 +1497,9 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv) if (policy) { enum lttng_action_status status; - status = lttng_action_notify_set_firing_policy(action, policy); + status = lttng_action_notify_set_rate_policy(action, policy); if (status != LTTNG_ACTION_STATUS_OK) { - ERR("Failed to set firing policy"); + ERR("Failed to set rate policy"); goto error; } } @@ -1493,11 +1509,9 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv) error: lttng_action_destroy(action); action = NULL; - free(error); end: - free(fire_once_after_str); - free(fire_every_str); - lttng_firing_policy_destroy(policy); + free(error); + lttng_rate_policy_destroy(policy); argpar_state_destroy(state); argpar_item_destroy(item); return action; @@ -1505,7 +1519,7 @@ end: /* * Generic handler for a kind of action that takes a session name and an - * optional firing policy. + * optional rate policy. */ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, @@ -1513,31 +1527,28 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, struct lttng_action *(*create_action_cb)(void), enum lttng_action_status (*set_session_name_cb)( struct lttng_action *, const char *), - enum lttng_action_status (*set_firing_policy_cb)( + enum lttng_action_status (*set_rate_policy_cb)( struct lttng_action *, - const struct lttng_firing_policy *), + const struct lttng_rate_policy *), const char *action_name) { struct lttng_action *action = NULL; struct argpar_state *state = NULL; struct argpar_item *item = NULL; const char *session_name_arg = NULL; - char *fire_once_after_str = NULL; - char *fire_every_str = NULL; char *error = NULL; enum lttng_action_status action_status; - struct lttng_firing_policy *policy = NULL; + struct lttng_rate_policy *policy = NULL; assert(set_session_name_cb); - assert(set_firing_policy_cb); + assert(set_rate_policy_cb); - const struct argpar_opt_descr firing_policy_opt_descrs[] = { - { OPT_FIRE_ONCE_AFTER, '\0', "fire-once-after", true }, - { OPT_FIRE_EVERY, '\0', "fire-every", true }, + const struct argpar_opt_descr rate_policy_opt_descrs[] = { + { OPT_RATE_POLICY, '\0', "rate-policy", true }, ARGPAR_OPT_DESCR_SENTINEL }; - state = argpar_state_create(*argc, *argv, firing_policy_opt_descrs); + state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs); if (!state) { ERR("Failed to allocate an argpar state."); goto error; @@ -1565,27 +1576,14 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, (const struct argpar_item_opt *) item; switch (item_opt->descr->id) { - case OPT_FIRE_ONCE_AFTER: + case OPT_RATE_POLICY: { - if (!assign_string(&fire_once_after_str, - item_opt->arg, - "--fire-once-after")) { + policy = parse_rate_policy(item_opt->arg); + if (!policy) { goto error; } - - break; - } - case OPT_FIRE_EVERY: - { - if (!assign_string(&fire_every_str, - item_opt->arg, - "--fire-every")) { - goto error; - } - break; } - default: abort(); } @@ -1613,55 +1611,6 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, goto error; } - if (fire_once_after_str && fire_every_str) { - ERR("--fire-once and --fire-every are mutually exclusive."); - goto error; - } - - if (fire_once_after_str) { - unsigned long long threshold; - - if (utils_parse_unsigned_long_long( - fire_once_after_str, &threshold) != 0) { - ERR("Failed to parse `%s` as an integer.", - fire_once_after_str); - goto error; - } - - if (threshold == 0) { - ERR("Once after N policy threshold cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_once_after_n_create(threshold); - if (!policy) { - ERR("Failed to create policy once after `%s`.", - fire_once_after_str); - goto error; - } - } - - if (fire_every_str) { - unsigned long long interval; - if (utils_parse_unsigned_long_long(fire_every_str, &interval) != - 0) { - ERR("Failed to parse `%s` as an integer.", - fire_every_str); - goto error; - } - if (interval == 0) { - ERR("Every N policy interval cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_every_n_create(interval); - if (!policy) { - ERR("Failed to create policy every `%s`.", - fire_every_str); - goto error; - } - } - action = create_action_cb(); if (!action) { ERR("Failed to allocate %s session action.", action_name); @@ -1676,9 +1625,9 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, } if (policy) { - action_status = set_firing_policy_cb(action, policy); + action_status = set_rate_policy_cb(action, policy); if (action_status != LTTNG_ACTION_STATUS_OK) { - ERR("Failed to set firing policy"); + ERR("Failed to set rate policy"); goto error; } } @@ -1690,7 +1639,7 @@ error: action = NULL; argpar_item_destroy(item); end: - lttng_firing_policy_destroy(policy); + lttng_rate_policy_destroy(policy); free(error); argpar_state_destroy(state); return action; @@ -1703,7 +1652,7 @@ struct lttng_action *handle_action_start_session(int *argc, return handle_action_simple_session_with_policy(argc, argv, lttng_action_start_session_create, lttng_action_start_session_set_session_name, - lttng_action_start_session_set_firing_policy, "start"); + lttng_action_start_session_set_rate_policy, "start"); } static @@ -1713,7 +1662,7 @@ struct lttng_action *handle_action_stop_session(int *argc, return handle_action_simple_session_with_policy(argc, argv, lttng_action_stop_session_create, lttng_action_stop_session_set_session_name, - lttng_action_stop_session_set_firing_policy, "stop"); + lttng_action_stop_session_set_rate_policy, "stop"); } static @@ -1723,7 +1672,7 @@ struct lttng_action *handle_action_rotate_session(int *argc, return handle_action_simple_session_with_policy(argc, argv, lttng_action_rotate_session_create, lttng_action_rotate_session_set_session_name, - lttng_action_rotate_session_set_firing_policy, + lttng_action_rotate_session_set_rate_policy, "rotate"); } @@ -1734,8 +1683,7 @@ static const struct argpar_opt_descr snapshot_action_opt_descrs[] = { { OPT_DATA_URL, '\0', "data-url", true }, { OPT_URL, '\0', "url", true }, { OPT_PATH, '\0', "path", true }, - { OPT_FIRE_ONCE_AFTER, '\0', "fire-once-after", true }, - { OPT_FIRE_EVERY, '\0', "fire-every", true }, + { OPT_RATE_POLICY, '\0', "rate-policy", true }, ARGPAR_OPT_DESCR_SENTINEL }; @@ -1754,11 +1702,9 @@ struct lttng_action *handle_action_snapshot_session(int *argc, char *url_arg = NULL; char *path_arg = NULL; char *error = NULL; - char *fire_once_after_str = NULL; - char *fire_every_str = NULL; enum lttng_action_status action_status; struct lttng_snapshot_output *snapshot_output = NULL; - struct lttng_firing_policy *policy = NULL; + struct lttng_rate_policy *policy = NULL; int ret; unsigned int locations_specified = 0; @@ -1826,27 +1772,14 @@ struct lttng_action *handle_action_snapshot_session(int *argc, } break; - case OPT_FIRE_ONCE_AFTER: + case OPT_RATE_POLICY: { - if (!assign_string(&fire_once_after_str, - item_opt->arg, - "--fire-once-after")) { + policy = parse_rate_policy(item_opt->arg); + if (!policy) { goto error; } - - break; - } - case OPT_FIRE_EVERY: - { - if (!assign_string(&fire_every_str, - item_opt->arg, - "--fire-every")) { - goto error; - } - break; } - default: abort(); } @@ -1910,56 +1843,6 @@ struct lttng_action *handle_action_snapshot_session(int *argc, } } - /* Any firing policy ? */ - if (fire_once_after_str && fire_every_str) { - ERR("--fire-once and --fire-every are mutually exclusive."); - goto error; - } - - if (fire_once_after_str) { - unsigned long long threshold; - - if (utils_parse_unsigned_long_long( - fire_once_after_str, &threshold) != 0) { - ERR("Failed to parse `%s` as an integer.", - fire_once_after_str); - goto error; - } - - if (threshold == 0) { - ERR("Once after N policy threshold cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_once_after_n_create(threshold); - if (!policy) { - ERR("Failed to create policy once after `%s`.", - fire_once_after_str); - goto error; - } - } - - if (fire_every_str) { - unsigned long long interval; - if (utils_parse_unsigned_long_long(fire_every_str, &interval) != - 0) { - ERR("Failed to parse `%s` as an integer.", - fire_every_str); - goto error; - } - if (interval == 0) { - ERR("Every N policy interval cannot be `0`."); - goto error; - } - - policy = lttng_firing_policy_every_n_create(interval); - if (!policy) { - ERR("Failed to create policy every `%s`.", - fire_every_str); - goto error; - } - } - action = lttng_action_snapshot_session_create(); if (!action) { ERR("Failed to allocate snapshot session action."); @@ -2083,10 +1966,10 @@ struct lttng_action *handle_action_snapshot_session(int *argc, if (policy) { enum lttng_action_status status; - status = lttng_action_snapshot_session_set_firing_policy( + status = lttng_action_snapshot_session_set_rate_policy( action, policy); if (status != LTTNG_ACTION_STATUS_OK) { - ERR("Failed to set firing policy"); + ERR("Failed to set rate policy"); goto error; } } @@ -2105,7 +1988,7 @@ end: free(data_url_arg); free(snapshot_output); free(max_size_arg); - lttng_firing_policy_destroy(policy); + lttng_rate_policy_destroy(policy); argpar_state_destroy(state); argpar_item_destroy(item); return action; @@ -2126,23 +2009,12 @@ struct action_descr action_descrs[] = { }; static -struct lttng_action *parse_action(int *argc, const char ***argv) +struct lttng_action *parse_action(const char *action_name, int *argc, const char ***argv) { int i; struct lttng_action *action; - const char *action_name; const struct action_descr *descr = NULL; - if (*argc == 0) { - ERR("Missing action name."); - goto error; - } - - action_name = (*argv)[0]; - - (*argc)--; - (*argv)++; - for (i = 0; i < ARRAY_SIZE(action_descrs); i++) { if (strcmp(action_name, action_descrs[i].name) == 0) { descr = &action_descrs[i]; @@ -2172,9 +2044,9 @@ static const struct argpar_opt_descr add_trigger_options[] = { { OPT_HELP, 'h', "help", false }, { OPT_LIST_OPTIONS, '\0', "list-options", false }, - { OPT_CONDITION, '\0', "condition", false }, - { OPT_ACTION, '\0', "action", false }, - { OPT_ID, '\0', "id", true }, + { OPT_CONDITION, '\0', "condition", true }, + { OPT_ACTION, '\0', "action", true }, + { OPT_NAME, '\0', "name", true }, { OPT_USER_ID, '\0', "user-id", true }, ARGPAR_OPT_DESCR_SENTINEL, }; @@ -2200,7 +2072,7 @@ int cmd_add_trigger(int argc, const char **argv) struct lttng_action *action = NULL; struct lttng_trigger *trigger = NULL; char *error = NULL; - char *id = NULL; + char *name = NULL; int i; char *user_id = NULL; @@ -2266,7 +2138,7 @@ int cmd_add_trigger(int argc, const char **argv) goto error; } - condition = parse_condition(&my_argc, &my_argv); + condition = parse_condition(item_opt->arg, &my_argc, &my_argv); if (!condition) { /* * An error message was already printed by @@ -2279,7 +2151,7 @@ int cmd_add_trigger(int argc, const char **argv) } case OPT_ACTION: { - action = parse_action(&my_argc, &my_argv); + action = parse_action(item_opt->arg, &my_argc, &my_argv); if (!action) { /* * An error message was already printed by @@ -2300,9 +2172,9 @@ int cmd_add_trigger(int argc, const char **argv) break; } - case OPT_ID: + case OPT_NAME: { - if (!assign_string(&id, item_opt->arg, "--id")) { + if (!assign_string(&name, item_opt->arg, "--name")) { goto error; } @@ -2360,12 +2232,12 @@ int cmd_add_trigger(int argc, const char **argv) goto error; } - if (id) { + if (name) { enum lttng_trigger_status trigger_status = - lttng_trigger_set_name(trigger, id); + lttng_trigger_set_name(trigger, name); if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { - ERR("Failed to set trigger id."); + ERR("Failed to set trigger name."); goto error; } } @@ -2410,7 +2282,7 @@ end: lttng_action_destroy(action); lttng_trigger_destroy(trigger); free(error); - free(id); + free(name); free(user_id); return ret; }