end:
return cond;
}
+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 },
+ ARGPAR_OPT_DESCR_SENTINEL
+};
static
struct lttng_action *handle_action_notify(int *argc, const char ***argv)
{
- return lttng_action_notify_create();
-}
+ struct lttng_action *action = NULL;
+ 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;
-static const struct argpar_opt_descr no_opt_descrs[] = {
- ARGPAR_OPT_DESCR_SENTINEL
-};
+ state = argpar_state_create(*argc, *argv, notify_action_opt_descrs);
+ if (!state) {
+ ERR("Failed to allocate an argpar state.");
+ goto error;
+ }
+
+ while (true) {
+ enum argpar_state_parse_next_status status;
+
+ ARGPAR_ITEM_DESTROY_AND_RESET(item);
+ status = argpar_state_parse_next(state, &item, &error);
+ if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
+ ERR("%s", error);
+ goto error;
+ } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
+ /* Just stop parsing here. */
+ break;
+ } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ break;
+ }
+
+ assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
+
+ if (item->type == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_item_opt *item_opt =
+ (const struct argpar_item_opt *) item;
+
+ switch (item_opt->descr->id) {
+ case OPT_FIRE_ONCE_AFTER:
+ {
+ if (!assign_string(&fire_once_after_str,
+ item_opt->arg,
+ "--fire-once-after")) {
+ goto error;
+ }
+
+ break;
+ }
+ case OPT_FIRE_EVERY:
+ {
+ if (!assign_string(&fire_every_str,
+ item_opt->arg,
+ "--fire-every")) {
+ goto error;
+ }
+
+ break;
+ }
+
+ default:
+ abort();
+ }
+ } else {
+ const struct argpar_item_non_opt *item_non_opt;
+
+ assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
+
+ item_non_opt = (const struct argpar_item_non_opt *) item;
+
+ switch (item_non_opt->non_opt_index) {
+ default:
+ ERR("Unexpected argument `%s`.",
+ item_non_opt->arg);
+ goto error;
+ }
+ }
+ }
+
+ *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");
+ goto error;
+ }
+
+ if (policy) {
+ enum lttng_action_status status;
+ status = lttng_action_notify_set_firing_policy(action, policy);
+ if (status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to set firing policy");
+ goto error;
+ }
+ }
+
+ goto end;
+
+error:
+ lttng_action_destroy(action);
+ action = NULL;
+ free(error);
+end:
+ free(fire_once_after_str);
+ free(fire_every_str);
+ lttng_firing_policy_destroy(policy);
+ argpar_state_destroy(state);
+ argpar_item_destroy(item);
+ return action;
+}
/*
- * Generic handler for a kind of action that takes a session name as its sole
- * argument.
+ * Generic handler for a kind of action that takes a session name and an
+ * optional firing policy.
*/
-static
-struct lttng_action *handle_action_simple_session(
- int *argc, const char ***argv,
+static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
+ const char ***argv,
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_session_name_cb)(
+ struct lttng_action *, const char *),
+ enum lttng_action_status (*set_firing_policy_cb)(
+ struct lttng_action *,
+ const struct lttng_firing_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;
-
- state = argpar_state_create(*argc, *argv, no_opt_descrs);
+ struct lttng_firing_policy *policy = NULL;
+
+ assert(set_session_name_cb);
+ assert(set_firing_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 },
+ ARGPAR_OPT_DESCR_SENTINEL
+ };
+
+ state = argpar_state_create(*argc, *argv, firing_policy_opt_descrs);
if (!state) {
ERR("Failed to allocate an argpar state.");
goto error;
while (true) {
enum argpar_state_parse_next_status status;
- const struct argpar_item_non_opt *item_non_opt;
ARGPAR_ITEM_DESTROY_AND_RESET(item);
status = argpar_state_parse_next(state, &item, &error);
if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
ERR("%s", error);
goto error;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
+ } else if (status ==
+ ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
/* Just stop parsing here. */
break;
} else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
}
assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
- assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
+ if (item->type == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_item_opt *item_opt =
+ (const struct argpar_item_opt *) item;
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ switch (item_opt->descr->id) {
+ case OPT_FIRE_ONCE_AFTER:
+ {
+ if (!assign_string(&fire_once_after_str,
+ item_opt->arg,
+ "--fire-once-after")) {
+ goto error;
+ }
- switch (item_non_opt->non_opt_index) {
- case 0:
- session_name_arg = item_non_opt->arg;
- break;
- default:
- ERR("Unexpected argument `%s`.", item_non_opt->arg);
- goto error;
+ break;
+ }
+ case OPT_FIRE_EVERY:
+ {
+ if (!assign_string(&fire_every_str,
+ item_opt->arg,
+ "--fire-every")) {
+ goto error;
+ }
+
+ break;
+ }
+
+ default:
+ abort();
+ }
+ } else {
+ const struct argpar_item_non_opt *item_non_opt;
+ item_non_opt = (const struct argpar_item_non_opt *) item;
+
+ switch (item_non_opt->non_opt_index) {
+ case 0:
+ session_name_arg = item_non_opt->arg;
+ break;
+ default:
+ ERR("Unexpected argument `%s`.",
+ item_non_opt->arg);
+ goto error;
+ }
}
}
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);
goto error;
}
+ if (policy) {
+ action_status = set_firing_policy_cb(action, policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to set firing policy");
+ goto error;
+ }
+ }
+
goto end;
error:
action = NULL;
argpar_item_destroy(item);
end:
+ lttng_firing_policy_destroy(policy);
free(error);
argpar_state_destroy(state);
return action;
struct lttng_action *handle_action_start_session(int *argc,
const char ***argv)
{
- return handle_action_simple_session(argc, argv,
- lttng_action_start_session_create,
- lttng_action_start_session_set_session_name,
- "start");
+ 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");
}
static
struct lttng_action *handle_action_stop_session(int *argc,
const char ***argv)
{
- return handle_action_simple_session(argc, argv,
- lttng_action_stop_session_create,
- lttng_action_stop_session_set_session_name,
- "stop");
+ 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");
}
static
struct lttng_action *handle_action_rotate_session(int *argc,
const char ***argv)
{
- return handle_action_simple_session(argc, argv,
+ 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,
"rotate");
}
{ 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 },
ARGPAR_OPT_DESCR_SENTINEL
};
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;
int ret;
unsigned int locations_specified = 0;
}
break;
+ case OPT_FIRE_ONCE_AFTER:
+ {
+ if (!assign_string(&fire_once_after_str,
+ item_opt->arg,
+ "--fire-once-after")) {
+ goto error;
+ }
+
+ break;
+ }
+ case OPT_FIRE_EVERY:
+ {
+ if (!assign_string(&fire_every_str,
+ item_opt->arg,
+ "--fire-every")) {
+ goto error;
+ }
+
+ break;
+ }
+
default:
abort();
}
}
}
+ /* 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.");
snapshot_output = NULL;
}
+ if (policy) {
+ enum lttng_action_status status;
+ status = lttng_action_snapshot_session_set_firing_policy(
+ action, policy);
+ if (status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to set firing policy");
+ goto error;
+ }
+ }
+
goto end;
error:
free(data_url_arg);
free(snapshot_output);
free(max_size_arg);
+ lttng_firing_policy_destroy(policy);
argpar_state_destroy(state);
argpar_item_destroy(item);
return action;
{ OPT_CONDITION, '\0', "condition", false },
{ OPT_ACTION, '\0', "action", false },
{ OPT_ID, '\0', "id", true },
- { OPT_FIRE_ONCE_AFTER, '\0', "fire-once-after", true },
- { OPT_FIRE_EVERY, '\0', "fire-every", true },
{ OPT_USER_ID, '\0', "user-id", true },
ARGPAR_OPT_DESCR_SENTINEL,
};
char *error = NULL;
char *id = NULL;
int i;
- char *fire_once_after_str = NULL;
- char *fire_every_str = NULL;
char *user_id = NULL;
lttng_dynamic_pointer_array_init(&actions, lttng_actions_destructor);
break;
}
- case OPT_FIRE_ONCE_AFTER:
- {
- if (!assign_string(&fire_once_after_str, item_opt->arg,
- "--fire-once-after")) {
- goto error;
- }
-
- break;
- }
- case OPT_FIRE_EVERY:
- {
- if (!assign_string(&fire_every_str, item_opt->arg,
- "--fire-every")) {
- goto error;
- }
-
- break;
- }
case OPT_USER_ID:
{
if (!assign_string(&user_id, item_opt->arg,
goto error;
}
- if (fire_every_str && fire_once_after_str) {
- ERR("Can't specify both --fire-once-after and --fire-every.");
- goto error;
- }
-
action_group = lttng_action_group_create();
if (!action_group) {
goto error;
}
}
- if (fire_once_after_str) {
- unsigned long long threshold;
- enum lttng_trigger_status trigger_status;
-
- 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;
- }
-
- trigger_status = lttng_trigger_set_firing_policy(trigger,
- LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N,
- threshold);
- if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
- ERR("Failed to set trigger's policy to `fire once after N`.");
- goto error;
- }
- }
-
- if (fire_every_str) {
- unsigned long long threshold;
- enum lttng_trigger_status trigger_status;
-
- if (utils_parse_unsigned_long_long(fire_every_str, &threshold) != 0) {
- ERR("Failed to parse `%s` as an integer.", fire_every_str);
- goto error;
- }
-
- trigger_status = lttng_trigger_set_firing_policy(trigger,
- LTTNG_TRIGGER_FIRING_POLICY_EVERY_N, threshold);
- if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
- ERR("Failed to set trigger's policy to `fire every N`.");
- goto error;
- }
- }
-
if (user_id) {
enum lttng_trigger_status trigger_status;
char *end;
lttng_trigger_destroy(trigger);
free(error);
free(id);
- free(fire_once_after_str);
- free(fire_every_str);
free(user_id);
return ret;
}
{
enum lttng_action_type action_type;
enum lttng_action_status action_status;
+ const struct lttng_firing_policy *policy = NULL;
const char *value;
action_type = lttng_action_get_type(action);
switch (action_type) {
case LTTNG_ACTION_TYPE_NOTIFY:
- MSG("notify");
+ _MSG("notify");
+
+ action_status = lttng_action_notify_get_firing_policy(
+ action, &policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to retrieve firing policy.");
+ goto end;
+ }
break;
case LTTNG_ACTION_TYPE_START_SESSION:
action_status = lttng_action_start_session_get_session_name(
action, &value);
assert(action_status == LTTNG_ACTION_STATUS_OK);
- MSG("start session `%s`", value);
+ _MSG("start session `%s`", value);
+
+ action_status = lttng_action_start_session_get_firing_policy(
+ action, &policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to retrieve firing policy.");
+ goto end;
+ }
break;
case LTTNG_ACTION_TYPE_STOP_SESSION:
action_status = lttng_action_stop_session_get_session_name(
action, &value);
assert(action_status == LTTNG_ACTION_STATUS_OK);
- MSG("stop session `%s`", value);
+ _MSG("stop session `%s`", value);
+
+ action_status = lttng_action_stop_session_get_firing_policy(
+ action, &policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to retrieve firing policy.");
+ goto end;
+ }
break;
case LTTNG_ACTION_TYPE_ROTATE_SESSION:
action_status = lttng_action_rotate_session_get_session_name(
action, &value);
assert(action_status == LTTNG_ACTION_STATUS_OK);
- MSG("rotate session `%s`", value);
+ _MSG("rotate session `%s`", value);
+
+ action_status = lttng_action_rotate_session_get_firing_policy(
+ action, &policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to retrieve firing policy.");
+ goto end;
+ }
break;
case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION:
{
}
}
- MSG("");
+ action_status = lttng_action_snapshot_session_get_firing_policy(
+ action, &policy);
+ if (action_status != LTTNG_ACTION_STATUS_OK) {
+ ERR("Failed to retrieve firing policy.");
+ goto end;
+ }
break;
}
-
default:
abort();
}
+
+ if (policy) {
+ enum lttng_firing_policy_type policy_type;
+ enum lttng_firing_policy_status policy_status;
+ uint64_t policy_value = 0;
+
+ policy_type = lttng_firing_policy_get_type(policy);
+
+ switch (policy_type) {
+ case LTTNG_FIRING_POLICY_TYPE_EVERY_N:
+ policy_status = lttng_firing_policy_every_n_get_interval(
+ policy, &policy_value);
+ if (policy_status != LTTNG_FIRING_POLICY_STATUS_OK) {
+ ERR("Failed to get action firing policy interval");
+ goto end;
+ }
+ if (policy_value > 1) {
+ /* The default is 1 so print only when it is a
+ * special case.
+ */
+ _MSG(", firing policy: after every %" PRIu64
+ " occurrences",
+ policy_value);
+ }
+ break;
+ case LTTNG_FIRING_POLICY_TYPE_ONCE_AFTER_N:
+ policy_status = lttng_firing_policy_once_after_n_get_threshold(
+ policy, &policy_value);
+ if (policy_status != LTTNG_FIRING_POLICY_STATUS_OK) {
+ ERR("Failed to get action firing policy interval");
+ goto end;
+ }
+ _MSG(", firing policy: once after %" PRIu64
+ " occurrences",
+ policy_value);
+ break;
+ default:
+ abort();
+ }
+ }
+
+ MSG("");
+end:
+ return;
}
static
enum lttng_action_type action_type;
enum lttng_trigger_status trigger_status;
const char *name;
- enum lttng_trigger_firing_policy firing_policy_type;
- uint64_t threshold;
uid_t trigger_uid;
trigger_status = lttng_trigger_get_name(trigger, &name);
MSG("- id: %s", name);
MSG(" user id: %d", trigger_uid);
- trigger_status = lttng_trigger_get_firing_policy(
- trigger, &firing_policy_type, &threshold);
- if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
- ERR("Failed to get trigger's policy.");
- goto end;
- }
-
- switch (firing_policy_type) {
- case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N:
- if (threshold > 1) {
- MSG(" firing policy: after every %" PRIu64 " occurences", threshold);
- }
- break;
- case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N:
- MSG(" firing policy: once after %" PRIu64 " occurences", threshold);
- break;
- default:
- abort();
- }
-
condition = lttng_trigger_get_const_condition(trigger);
condition_type = lttng_condition_get_type(condition);
MSG(" condition: %s", lttng_condition_type_str(condition_type));
print_one_action(action);
}
-end:
- return;
}
static
urcu_ref_init(&trigger->ref);
- trigger->firing_policy.type = LTTNG_TRIGGER_FIRING_POLICY_EVERY_N;
- trigger->firing_policy.threshold = 1;
-
lttng_condition_get(condition);
trigger->condition = condition;
lttng_trigger_put(trigger);
}
-static bool is_firing_policy_valid(enum lttng_trigger_firing_policy policy)
-{
- bool valid = false;
-
- switch (policy) {
- case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N:
- case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N:
- valid = true;
- break;
- default:
- valid = false;
- break;
- }
-
- return valid;
-}
-
LTTNG_HIDDEN
ssize_t lttng_trigger_create_from_payload(
struct lttng_payload_view *src_view,
struct lttng_action *action = NULL;
const struct lttng_trigger_comm *trigger_comm;
const char *name = NULL;
- uint64_t firing_policy_threshold;
- enum lttng_trigger_firing_policy firing_policy;
struct lttng_credentials creds = {
.uid = LTTNG_OPTIONAL_INIT_UNSET,
.gid = LTTNG_OPTIONAL_INIT_UNSET,
offset += sizeof(*trigger_comm);
- firing_policy = trigger_comm->firing_policy_type;
- if (!is_firing_policy_valid(firing_policy)) {
- ret =-1;
- goto end;
- }
-
- firing_policy_threshold = trigger_comm->firing_policy_threshold;
if (trigger_comm->name_length != 0) {
/* Name. */
const struct lttng_payload_view name_view =
}
}
- /* Set the policy. */
- {
- const enum lttng_trigger_status status =
- lttng_trigger_set_firing_policy(trigger,
- firing_policy,
- firing_policy_threshold);
-
- if (status != LTTNG_TRIGGER_STATUS_OK) {
- ret = -1;
- goto end;
- }
- }
-
ret = offset;
error:
}
trigger_comm.name_length = size_name;
- trigger_comm.firing_policy_type = (uint8_t) trigger->firing_policy.type;
- trigger_comm.firing_policy_threshold = (uint64_t) trigger->firing_policy.threshold;
header_offset = payload->buffer.size;
ret = lttng_dynamic_buffer_append(&payload->buffer, &trigger_comm,
bool lttng_trigger_is_equal(
const struct lttng_trigger *a, const struct lttng_trigger *b)
{
- if (a->firing_policy.type != b->firing_policy.type) {
- return false;
- }
-
- if (a->firing_policy.threshold != b->firing_policy.threshold) {
- return false;
- }
-
if (strcmp(a->name, b->name) != 0) {
return false;
}
return ret;
}
-enum lttng_trigger_status lttng_trigger_set_firing_policy(
- struct lttng_trigger *trigger,
- enum lttng_trigger_firing_policy policy_type,
- uint64_t threshold)
-{
- enum lttng_trigger_status ret = LTTNG_TRIGGER_STATUS_OK;
- assert(trigger);
-
- if (threshold < 1) {
- ret = LTTNG_TRIGGER_STATUS_INVALID;
- goto end;
- }
-
- trigger->firing_policy.type = policy_type;
- trigger->firing_policy.threshold = threshold;
-
-end:
- return ret;
-}
-
-enum lttng_trigger_status lttng_trigger_get_firing_policy(
- const struct lttng_trigger *trigger,
- enum lttng_trigger_firing_policy *policy_type,
- uint64_t *threshold)
-{
- enum lttng_trigger_status status = LTTNG_TRIGGER_STATUS_OK;
-
- if (!trigger || !policy_type || !threshold) {
- status = LTTNG_TRIGGER_STATUS_INVALID;
- goto end;
- }
-
- *policy_type = trigger->firing_policy.type;
- *threshold = trigger->firing_policy.threshold;
-
-end:
- return status;
-}
-
-LTTNG_HIDDEN
-bool lttng_trigger_should_fire(const struct lttng_trigger *trigger)
-{
- bool ready_to_fire = false;
-
- assert(trigger);
-
- switch (trigger->firing_policy.type) {
- case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N:
- if (trigger->firing_policy.current_count < trigger->firing_policy.threshold) {
- ready_to_fire = true;
- }
- break;
- case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N:
- if (trigger->firing_policy.current_count < trigger->firing_policy.threshold) {
- ready_to_fire = true;
- }
- break;
- default:
- abort();
- };
-
- return ready_to_fire;
-}
-
-LTTNG_HIDDEN
-void lttng_trigger_fire(struct lttng_trigger *trigger)
-{
- assert(trigger);
-
- trigger->firing_policy.current_count++;
-
- switch (trigger->firing_policy.type) {
- case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N:
- if (trigger->firing_policy.current_count == trigger->firing_policy.threshold) {
- trigger->firing_policy.current_count = 0;
- }
-
- break;
- case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N:
- /*
- * TODO:
- * As an optimisation, deactivate the trigger condition and
- * remove any checks in the traced application or kernel since
- * the trigger will never fire again.
- */
- break;
- default:
- abort();
- };
-}
-
LTTNG_HIDDEN
enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
const struct lttng_trigger *trigger)