From patchwork Fri Aug 13 02:16:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 496849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66519C432BE for ; Fri, 13 Aug 2021 02:17:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CECC61103 for ; Fri, 13 Aug 2021 02:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237936AbhHMCRz (ORCPT ); Thu, 12 Aug 2021 22:17:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:44544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237397AbhHMCRw (ORCPT ); Thu, 12 Aug 2021 22:17:52 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34704610A8; Fri, 13 Aug 2021 02:17:26 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mEMlA-003wVu-Re; Thu, 12 Aug 2021 22:17:24 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , Namhyung Kim , linux-rt-users , Clark Williams , "Steven Rostedt (VMware)" Subject: [PATCH 2/7] libtracefs: Add logic to apply actions to synthetic events Date: Thu, 12 Aug 2021 22:16:50 -0400 Message-Id: <20210813021655.939819-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813021655.939819-1-rostedt@goodmis.org> References: <20210813021655.939819-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org From: "Steven Rostedt (VMware)" Add an actions list to tracefs_synth, that if it is not empty then it will be used to apply the handlers and actions to be taken. Otherwise the default of "onmatch" and "trace" is used. Currently nothing adds any actions and only the default is supported, but this will allow for new handlers (onmax and onchange) as well as new actions (snapshot and save). Signed-off-by: Steven Rostedt (VMware) --- include/tracefs.h | 7 +++++ src/tracefs-hist.c | 76 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/include/tracefs.h b/include/tracefs.h index 90994de97dda..d83c4e33c69a 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -435,6 +435,13 @@ int tracefs_event_verify_filter(struct tep_event *event, const char *filter, #define TRACEFS_TIMESTAMP "common_timestamp" #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs" +enum tracefs_synth_handler { + TRACEFS_SYNTH_HANDLE_NONE = 0, + TRACEFS_SYNTH_HANDLE_MATCH, + TRACEFS_SYNTH_HANDLE_MAX, + TRACEFS_SYNTH_HANDLE_CHANGE, +}; + struct tracefs_synth *tracefs_synth_init(struct tep_handle *tep, const char *name, const char *start_system, diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 7fffa6cc653d..262db7fbb925 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -521,12 +521,25 @@ int tracefs_hist_append_filter(struct tracefs_hist *hist, type, field, compare, val); } +enum action_type { + ACTION_NONE, + ACTION_TRACE, +}; + +struct action { + struct action *next; + enum action_type type; + enum tracefs_synth_handler handler; + char *handle_field; +}; + /* * @name: name of the synthetic event * @start_system: system of the starting event * @start_event: the starting event * @end_system: system of the ending event * @end_event: the ending event + * @actions: List of actions to take * @match_names: If a match set is to be a synthetic field, it has a name * @start_match: list of keys in the start event that matches end event * @end_match: list of keys in the end event that matches the start event @@ -545,6 +558,8 @@ struct tracefs_synth { struct tep_handle *tep; struct tep_event *start_event; struct tep_event *end_event; + struct action *actions; + struct action **next_action; char *name; char **synthetic_fields; char **synthetic_args; @@ -575,6 +590,8 @@ struct tracefs_synth { */ void tracefs_synth_free(struct tracefs_synth *synth) { + struct action *action; + if (!synth) return; @@ -590,6 +607,12 @@ void tracefs_synth_free(struct tracefs_synth *synth) tep_unref(synth->tep); + while ((action = synth->actions)) { + synth->actions = action->next; + free(action->handle_field); + free(action); + } + free(synth); } @@ -750,6 +773,7 @@ synth_init_from(struct tep_handle *tep, const char *start_system, return NULL; synth->start_event = start_event; + synth->next_action = &synth->actions; /* Hold onto a reference to this handler */ tep_ref(tep); @@ -1405,13 +1429,61 @@ static char *create_trace(char *hist, struct tracefs_synth *synth) return append_string(hist, NULL, ")"); } +static char *create_max(char *hist, struct tracefs_synth *synth, char *field) +{ + hist = append_string(hist, NULL, ":onmax("); + hist = append_string(hist, NULL, field); + return append_string(hist, NULL, ")"); +} + +static char *create_change(char *hist, struct tracefs_synth *synth, char *field) +{ + hist = append_string(hist, NULL, ":onchange("); + hist = append_string(hist, NULL, field); + return append_string(hist, NULL, ")"); +} + +static char *create_actions(char *hist, struct tracefs_synth *synth) +{ + struct action *action; + + if (!synth->actions) { + /* Default is "onmatch" and "trace" */ + hist = create_onmatch(hist, synth); + return create_trace(hist, synth); + } + + for (action = synth->actions; action; action = action->next) { + switch (action->handler) { + case TRACEFS_SYNTH_HANDLE_MATCH: + hist = create_onmatch(hist, synth); + break; + case TRACEFS_SYNTH_HANDLE_MAX: + hist = create_max(hist, synth, action->handle_field); + break; + case TRACEFS_SYNTH_HANDLE_CHANGE: + hist = create_change(hist, synth, action->handle_field); + break; + default: + continue; + } + switch (action->type) { + case ACTION_TRACE: + hist = create_trace(hist, synth); + break; + default: + continue; + } + } + return hist; +} + static char *create_end_hist(struct tracefs_synth *synth) { char *end_hist; end_hist = create_hist(synth->end_keys, synth->end_vars); - end_hist = create_onmatch(end_hist, synth); - return create_trace(end_hist, synth); + return create_actions(end_hist, synth); } static char *append_filter(char *hist, char *filter, unsigned int parens) From patchwork Fri Aug 13 02:16:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 496848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66F6FC4338F for ; Fri, 13 Aug 2021 02:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B66561102 for ; Fri, 13 Aug 2021 02:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238116AbhHMCR5 (ORCPT ); Thu, 12 Aug 2021 22:17:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237331AbhHMCRw (ORCPT ); Thu, 12 Aug 2021 22:17:52 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3093B60F35; Fri, 13 Aug 2021 02:17:26 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mEMlA-003wVw-Sa; Thu, 12 Aug 2021 22:17:24 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , Namhyung Kim , linux-rt-users , Clark Williams , "Steven Rostedt (VMware)" Subject: [PATCH 3/7] libtracefs: Add API tracefs_synth_trace() Date: Thu, 12 Aug 2021 22:16:51 -0400 Message-Id: <20210813021655.939819-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813021655.939819-1-rostedt@goodmis.org> References: <20210813021655.939819-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org From: "Steven Rostedt (VMware)" Add the API tracefs_synth_trace() that adds a "trace" action that can be attached to the onmax or the onchange handler. Note, this still can be used for onmatch, but that's the default anyway. Signed-off-by: Steven Rostedt (VMware) --- Documentation/libtracefs-synth2.txt | 17 +++++- include/tracefs.h | 2 + src/tracefs-hist.c | 91 +++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt index 44693b394f29..a74e88ec0eda 100644 --- a/Documentation/libtracefs-synth2.txt +++ b/Documentation/libtracefs-synth2.txt @@ -3,7 +3,8 @@ libtracefs(3) NAME ---- -tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_show - Creation of synthetic events +tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_show,tracefs_synth_complete, +tracefs_synth_get_start_hist,tracefs_synth_trace - Creation of synthetic events SYNOPSIS -------- @@ -20,6 +21,8 @@ int tracefs_synth_show(struct trace_seq pass:[*]seq, struct tracefs_instance pas bool tracefs_synth_complete(struct tracefs_synth pass:[*]synth); struct tracefs_hist pass:[*]tracefs_synth_get_start_hist(struct tracefs_synth pass:[*]synth); +int tracefs_synth_trace(struct tracefs_synth pass:[*]synth, + enum tracefs_synth_handler type, const char pass:[*]var); -- DESCRIPTION @@ -60,6 +63,18 @@ a starting and ending event. *tracefs_synth_get_start_hist*() returns a struct tracefs_hist descriptor describing the histogram used to create the synthetic event. +enum tracefs_synth_handler { + TRACEFS_SYNTH_HANDLE_MATCH, + TRACEFS_SYNTH_HANDLE_MAX, + TRACEFS_SYNTH_HANDLE_CHANGE, +}; + +*tracefs_synth_trace*() Instead of doing just a trace on matching of the start and +end events, do the _type_ handler where *TRACEFS_SYNTH_HANDLE_MAX* will do a trace +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). + RETURN VALUE ------------ Returns zero on success or -1 on error. diff --git a/include/tracefs.h b/include/tracefs.h index d83c4e33c69a..2faa564a860f 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -476,6 +476,8 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth, const char *field, enum tracefs_compare compare, const char *val); +int tracefs_synth_trace(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, diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 262db7fbb925..562ec65088a9 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -1323,6 +1323,97 @@ int tracefs_synth_append_end_filter(struct tracefs_synth *synth, type, field, compare, val); } +static int test_max_var(struct tracefs_synth *synth, const char *var) +{ + char **vars = synth->end_vars; + char *p; + int len; + int i; + + len = strlen(var); + + /* Make sure the var is defined for the end event */ + for (i = 0; vars[i]; i++) { + p = strchr(vars[i], '='); + if (!p) + continue; + if (p - vars[i] != len) + continue; + if (!strncmp(var, vars[i], len)) + return 0; + } + errno = ENODEV; + return -1; +} + +static struct action *create_action(enum tracefs_synth_handler type, + struct tracefs_synth *synth, + const char *var) +{ + struct action *action; + int ret; + + switch (type) { + case TRACEFS_SYNTH_HANDLE_MAX: + case TRACEFS_SYNTH_HANDLE_CHANGE: + ret = test_max_var(synth, var); + if (ret < 0) + return NULL; + break; + default: + break; + } + + action = calloc(1, sizeof(*action)); + if (!action) + return NULL; + + if (var) { + ret = asprintf(&action->handle_field, "$%s", var); + if (!action->handle_field) { + free(action); + return NULL; + } + } + return action; +} + +static void add_action(struct tracefs_synth *synth, struct action *action) +{ + *synth->next_action = action; + synth->next_action = &action->next; +} + +/** + * tracefs_synth_trace - Execute the trace option + * @synth: The tracefs_synth descriptor + * @type: The type of handler to attach the trace action with + * @field: The field for handlers onmax and onchange (ignored otherwise) + * + * Add the action 'trace' for handlers onmatch, onmax and onchange. + * + * Returns 0 on succes, -1 on error. + */ +int tracefs_synth_trace(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_TRACE; + action->handler = type; + add_action(synth, action); + return 0; +} + static char *create_synthetic_event(struct tracefs_synth *synth) { char *synthetic_event; From patchwork Fri Aug 13 02:16:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 496846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 213C3C4338F for ; Fri, 13 Aug 2021 02:17:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0976A61101 for ; Fri, 13 Aug 2021 02:17:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238386AbhHMCSD (ORCPT ); Thu, 12 Aug 2021 22:18:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:44618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237705AbhHMCRx (ORCPT ); Thu, 12 Aug 2021 22:17:53 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3BA46610E9; Fri, 13 Aug 2021 02:17:26 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mEMlA-003wVy-TV; Thu, 12 Aug 2021 22:17:24 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , Namhyung Kim , linux-rt-users , Clark Williams , "Steven Rostedt (VMware)" Subject: [PATCH 4/7] libtracefs: Add API tracefs_synth_snapshot() Date: Thu, 12 Aug 2021 22:16:52 -0400 Message-Id: <20210813021655.939819-5-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813021655.939819-1-rostedt@goodmis.org> References: <20210813021655.939819-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org From: "Steven Rostedt (VMware)" Add new API tracefs_synth_snapshot() Where this will add "actions" to the synthetic event descriptor and also add other features besides "onmatch()" such that the output can be: onmax($lat).trace(latency,$lat):onmax($lat).snapshot That will trace the latency when it hits a maximum, and also take a snapshot of the buffer. Signed-off-by: Steven Rostedt (VMware) --- Documentation/libtracefs-synth2.txt | 11 +++++++++- include/tracefs.h | 2 ++ src/tracefs-hist.c | 34 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt index a74e88ec0eda..194a4e021f62 100644 --- a/Documentation/libtracefs-synth2.txt +++ b/Documentation/libtracefs-synth2.txt @@ -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. diff --git a/include/tracefs.h b/include/tracefs.h index 2faa564a860f..45a5bb2df2de 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -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, diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 562ec65088a9..2c9c37b8ec23 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -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; } From patchwork Fri Aug 13 02:16:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 496847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50209C4338F for ; Fri, 13 Aug 2021 02:17:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3520A61101 for ; Fri, 13 Aug 2021 02:17:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238245AbhHMCSA (ORCPT ); Thu, 12 Aug 2021 22:18:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:44550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237496AbhHMCRw (ORCPT ); Thu, 12 Aug 2021 22:17:52 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35B0D60FC0; Fri, 13 Aug 2021 02:17:26 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mEMlA-003wW2-VL; Thu, 12 Aug 2021 22:17:24 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Zanussi , Daniel Bristot de Oliveira , Masami Hiramatsu , Namhyung Kim , linux-rt-users , Clark Williams , "Steven Rostedt (VMware)" Subject: [PATCH 6/7] libtracefs: Update the libtracefs-sql man page for the new tracefs_synth APIs Date: Thu, 12 Aug 2021 22:16:54 -0400 Message-Id: <20210813021655.939819-7-rostedt@goodmis.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813021655.939819-1-rostedt@goodmis.org> References: <20210813021655.939819-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org From: "Steven Rostedt (VMware)" Update the libtracfes-sql man page to have the sqlhist program utilize the new APIs: tracefs_synth_trace() tracefs_synth_snapshot() tracefs_synth_save() Signed-off-by: Steven Rostedt (VMware) --- Documentation/libtracefs-sql.txt | 105 ++++++++++++++++++++++++++-- Documentation/libtracefs-synth2.txt | 2 + 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/Documentation/libtracefs-sql.txt b/Documentation/libtracefs-sql.txt index 35ccaf5cd1a5..95625157590e 100644 --- a/Documentation/libtracefs-sql.txt +++ b/Documentation/libtracefs-sql.txt @@ -305,23 +305,47 @@ EXAMPLE static void usage(char **argv) { - fprintf(stderr, "usage: %s [-ed][-n name][-t dir][-f file | sql-command-line]\n" + fprintf(stderr, "usage: %s [-ed][-n name][-s][-S fields][-m var][-c var][-T][-t dir][-f file | sql-command-line]\n" " -n name - name of synthetic event 'Anonymous' if left off\n" " -t dir - use dir instead of /sys/kernel/tracing\n" " -e - execute the commands to create the synthetic event\n" + " -m - trigger the action when var is a new max.\n" + " -c - trigger the action when var changes.\n" + " -s - used with -m or -c to do a snapshot of the tracing buffer\n" + " -S - used with -m or -c to save fields of the end event (comma deliminated)\n" + " -T - used with -m or -c to do both a snapshot and a trace\n" " -f file - read sql lines from file otherwise from the command line\n" " if file is '-' then read from standard input.\n", argv[0]); exit(-1); } -static int do_sql(const char *buffer, const char *name, - const char *trace_dir, bool execute) +enum action { + ACTION_DEFAULT = 0, + ACTION_SNAPSHOT = (1 << 0), + ACTION_TRACE = (1 << 1), + ACTION_SAVE = (1 << 2), + ACTION_MAX = (1 << 3), + ACTION_CHANGE = (1 << 4), +}; + +#define ACTIONS ((ACTION_MAX - 1)) + +static int do_sql(const char *buffer, const char *name, const char *var, + const char *trace_dir, bool execute, int action, + char **save_fields) { struct tracefs_synth *synth; struct tep_handle *tep; struct trace_seq seq; + enum tracefs_synth_handler handler; char *err; + int ret; + + if ((action & ACTIONS) && !var) { + fprintf(stderr, "Error: -s, -S and -T not supported without -m or -c"); + exit(-1); + } if (!name) name = "Anonymous"; @@ -345,6 +369,43 @@ static int do_sql(const char *buffer, const char *name, } if (tracefs_synth_complete(synth)) { + if (var) { + if (action & ACTION_MAX) + handler = TRACEFS_SYNTH_HANDLE_MAX; + else + handler = TRACEFS_SYNTH_HANDLE_CHANGE; + + if (action & ACTION_SAVE) { + ret = tracefs_synth_save(synth, handler, var, save_fields); + if (ret < 0) { + err = "adding save"; + goto failed_action; + } + } + if (action & ACTION_TRACE) { + /* + * By doing the trace before snapshot, it will be included + * in the snapshot. + */ + ret = tracefs_synth_trace(synth, handler, var); + if (ret < 0) { + err = "adding trace"; + goto failed_action; + } + } + if (action & ACTION_SNAPSHOT) { + ret = tracefs_synth_snapshot(synth, handler, var); + if (ret < 0) { + err = "adding snapshot"; + failed_action: + perror(err); + if (errno == ENODEV) + fprintf(stderr, "ERROR: '%s' is not a variable\n", + var); + exit(-1); + } + } + } tracefs_synth_show(&seq, NULL, synth); if (execute) tracefs_synth_create(NULL, synth); @@ -375,14 +436,18 @@ int main (int argc, char **argv) int buffer_size = 0; const char *file = NULL; bool execute = false; + char **save_fields = NULL; const char *name; + const char *var; + int action = 0; + char *tok; FILE *fp; size_t r; int c; int i; for (;;) { - c = getopt(argc, argv, "ht:f:en:"); + c = getopt(argc, argv, "ht:f:en:m:c:sS:T"); if (c == -1) break; @@ -398,12 +463,42 @@ int main (int argc, char **argv) case 'e': execute = true; break; + case 'm': + action |= ACTION_MAX; + var = optarg; + break; + case 'c': + action |= ACTION_CHANGE; + var = optarg; + break; + case 's': + action |= ACTION_SNAPSHOT; + break; + case 'S': + action |= ACTION_SAVE; + tok = strtok(optarg, ","); + while (tok) { + save_fields = tracefs_list_add(save_fields, tok); + tok = strtok(NULL, ","); + } + if (!save_fields) { + perror(optarg); + exit(-1); + } + break; + case 'T': + action |= ACTION_TRACE | ACTION_SNAPSHOT; + break; case 'n': name = optarg; break; } } + if ((action & (ACTION_MAX|ACTION_CHANGE)) == (ACTION_MAX|ACTION_CHANGE)) { + fprintf(stderr, "Can not use both -m and -c together\n"); + exit(-1); + } if (file) { if (!strcmp(file, "-")) fp = stdin; @@ -434,7 +529,7 @@ int main (int argc, char **argv) } } - do_sql(buffer, name, trace_dir, execute); + do_sql(buffer, name, var, trace_dir, execute, action, save_fields); free(buffer); return 0; diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt index cfcae7411f58..4c4425325393 100644 --- a/Documentation/libtracefs-synth2.txt +++ b/Documentation/libtracefs-synth2.txt @@ -117,6 +117,8 @@ And more errors may have happened from the system calls to the system. EXAMPLE ------- +See *tracefs_sql*(3) for a more indepth use of some of this code. + [source,c] -- #include