@@ -4,7 +4,7 @@ libtracefs(3)
NAME
----
tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_show,tracefs_synth_complete,
-tracefs_synth_get_start_hist,tracefs_synth_trace - Creation of synthetic events
+tracefs_synth_get_start_hist,tracefs_synth_trace,tracefs_synth_snapshot - Creation of synthetic events
SYNOPSIS
--------
@@ -23,6 +23,8 @@ struct tracefs_hist pass:[*]tracefs_synth_get_start_hist(struct tracefs_synth pa
int tracefs_synth_trace(struct tracefs_synth pass:[*]synth,
enum tracefs_synth_handler type, const char pass:[*]var);
+int tracefs_synth_snapshot(struct tracefs_synth pass:[*]synth,
+ enum tracefs_synth_handler type, const char pass:[*]var);
--
DESCRIPTION
@@ -75,6 +77,13 @@ when the given variable _var_ hits a new max for the matching keys. Or
*TRACEFS_SYNTH_HANDLE_CHANGE* for when the _var_ changes. _var_ must be one of
the _name_ elements used in *tracefs_synth_add_end_field*(3).
+*tracefs_synth_snapshot*() When the given variable _var_ is either a new max if
+_handler_ is TRACEFS_SYNTH_HANDLE_MAX_ or simpy changed if TRACEFS_SYNTH_HANDLE_CHANGE_
+then take a "snapshot" of the buffer. The snapshot moves the normal "trace" buffer
+into a "snapshot" buffer, that can be accessed via the "snapshot" file in the
+top level tracefs directory, or one of the instances. _var_ changes. _var_ must be one of
+the _name_ elements used in *tracefs_synth_add_end_field*(3).
+
RETURN VALUE
------------
Returns zero on success or -1 on error.
@@ -478,6 +478,8 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth,
const char *val);
int tracefs_synth_trace(struct tracefs_synth *synth,
enum tracefs_synth_handler type, const char *field);
+int tracefs_synth_snapshot(struct tracefs_synth *synth,
+ enum tracefs_synth_handler type, const char *field);
bool tracefs_synth_complete(struct tracefs_synth *synth);
struct tracefs_hist *tracefs_synth_get_start_hist(struct tracefs_synth *synth);
int tracefs_synth_create(struct tracefs_instance *instance,
@@ -524,6 +524,7 @@ int tracefs_hist_append_filter(struct tracefs_hist *hist,
enum action_type {
ACTION_NONE,
ACTION_TRACE,
+ ACTION_SNAPSHOT,
};
struct action {
@@ -1414,6 +1415,36 @@ int tracefs_synth_trace(struct tracefs_synth *synth,
return 0;
}
+/**
+ * tracefs_synth_snapshot - create a snapshot command to the histogram
+ * @synth: The tracefs_synth descriptor
+ * @type: The type of handler to attach the snapshot action with
+ * @field: The field for handlers onmax and onchange
+ *
+ * Add the action to do a snapshot for handlers onmax and onchange.
+ *
+ * Returns 0 on succes, -1 on error.
+ */
+int tracefs_synth_snapshot(struct tracefs_synth *synth,
+ enum tracefs_synth_handler type, const char *field)
+{
+ struct action *action;
+
+ if (!synth || !field || (type == TRACEFS_SYNTH_HANDLE_MATCH)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ action = create_action(type, synth, field);
+ if (!action)
+ return -1;
+
+ action->type = ACTION_SNAPSHOT;
+ action->handler = type;
+ add_action(synth, action);
+ return 0;
+}
+
static char *create_synthetic_event(struct tracefs_synth *synth)
{
char *synthetic_event;
@@ -1562,6 +1593,9 @@ static char *create_actions(char *hist, struct tracefs_synth *synth)
case ACTION_TRACE:
hist = create_trace(hist, synth);
break;
+ case ACTION_SNAPSHOT:
+ hist = append_string(hist, NULL, ".snapshot()");
+ break;
default:
continue;
}