From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Tom Zanussi <zanussi@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH v2 3/4] libtracefs: Add TRACEFS_TIMESTAMP and TRACEFS_TIMESTAMP_USECS to synth
Date: Thu, 22 Jul 2021 09:36:09 -0400 [thread overview]
Message-ID: <20210722133610.379933-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20210722133610.379933-1-rostedt@goodmis.org>
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Add the fields of TRACEFS_TIMESTAMP and TRACEFS_TIMESTAMP_USECS that can
be used to calculate the timestamps between the events for the synthetic
event creation.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
include/tracefs.h | 3 +++
src/tracefs-hist.c | 50 ++++++++++++++++++++++++++++++++++------------
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/include/tracefs.h b/include/tracefs.h
index 77a1a37f5b06..9cfd2577da2e 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -324,6 +324,9 @@ enum tracefs_synth_compare {
TRACEFS_COMPARE_AND,
};
+#define TRACEFS_TIMESTAMP "common_timestamp"
+#define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
+
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 5ba865d95548..8b9078791ab2 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -563,6 +563,18 @@ struct tracefs_synth {
int arg_cnt;
};
+static const struct tep_format_field common_timestamp = {
+ .type = "u64",
+ .name = "common_timestamp",
+ .size = 8,
+};
+
+static const struct tep_format_field common_timestamp_usecs = {
+ .type = "u64",
+ .name = "common_timestamp.usecs",
+ .size = 8,
+};
+
void tracefs_synth_free(struct tracefs_synth *synth)
{
if (!synth)
@@ -583,21 +595,33 @@ void tracefs_synth_free(struct tracefs_synth *synth)
free(synth);
}
+static const struct tep_format_field *get_event_field(struct tep_event *event,
+ const char *field_name)
+{
+ if (!strcmp(field_name, TRACEFS_TIMESTAMP))
+ return &common_timestamp;
+
+ if (!strcmp(field_name, TRACEFS_TIMESTAMP_USECS))
+ return &common_timestamp_usecs;
+
+ return tep_find_any_field(event, field_name);
+}
+
static bool verify_event_fields(struct tep_event *start_event,
struct tep_event *end_event,
const char *start_field_name,
const char *end_field_name,
- struct tep_format_field **ptr_start_field)
+ const struct tep_format_field **ptr_start_field)
{
- struct tep_format_field *start_field;
- struct tep_format_field *end_field;
+ const struct tep_format_field *start_field;
+ const struct tep_format_field *end_field;
- start_field = tep_find_any_field(start_event, start_field_name);
+ start_field = get_event_field(start_event, start_field_name);
if (!start_field)
goto nodev;
if (end_event) {
- end_field = tep_find_any_field(end_event, end_field_name);
+ end_field = get_event_field(end_event, end_field_name);
if (!start_field)
goto nodev;
@@ -644,7 +668,7 @@ static char *append_string(char *str, const char *space, const char *add)
return str;
}
-static char *add_synth_field(struct tep_format_field *field,
+static char *add_synth_field(const struct tep_format_field *field,
const char *name)
{
const char *type;
@@ -828,7 +852,7 @@ struct tracefs_synth *tracefs_synth_init(struct tep_handle *tep,
}
static int add_synth_fields(struct tracefs_synth *synth,
- struct tep_format_field *field,
+ const struct tep_format_field *field,
const char *name)
{
char **list;
@@ -885,7 +909,7 @@ int tracefs_synth_add_match_field(struct tracefs_synth *synth,
const char *end_match_field,
const char *name)
{
- struct tep_format_field *key_field;
+ const struct tep_format_field *key_field;
char **list;
int ret;
@@ -975,7 +999,7 @@ int tracefs_synth_add_compare_field(struct tracefs_synth *synth,
enum tracefs_synth_calc calc,
const char *name)
{
- struct tep_format_field *start_field;
+ const struct tep_format_field *start_field;
char *start_arg;
char *compare;
int ret;
@@ -1060,7 +1084,7 @@ int tracefs_synth_add_start_field(struct tracefs_synth *synth,
const char *start_field,
const char *name)
{
- struct tep_format_field *field;
+ const struct tep_format_field *field;
char *start_arg;
int ret;
@@ -1114,7 +1138,7 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,
const char *end_field,
const char *name)
{
- struct tep_format_field *field;
+ const struct tep_format_field *field;
int ret;
if (!synth || !end_field) {
@@ -1235,7 +1259,7 @@ int tracefs_synth_add_start_filter(struct tracefs_synth *synth,
const char *val,
bool neg, bool or)
{
- struct tep_format_field *start_field;
+ const struct tep_format_field *start_field;
bool is_string;
if (!field || !val)
@@ -1264,7 +1288,7 @@ int tracefs_synth_add_end_filter(struct tracefs_synth *synth,
const char *val,
bool neg, bool or)
{
- struct tep_format_field *end_field;
+ const struct tep_format_field *end_field;
bool is_string;
if (!field || !val)
--
2.30.2
next prev parent reply other threads:[~2021-07-22 13:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-22 13:36 [PATCH v2 0/4] libtracefs: Creating synthetic events Steven Rostedt
2021-07-22 13:36 ` [PATCH v2 1/4] libtracefs: Add tracefs_list_pop() to remove the last item Steven Rostedt
2021-07-22 13:36 ` [PATCH v2 2/4] libtracefs: Create a way to create a synthetic event Steven Rostedt
2021-07-22 13:36 ` Steven Rostedt [this message]
2021-07-22 13:36 ` [PATCH v2 4/4] libtracefs: Add man pages for creating synthetic events Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210722133610.379933-4-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=bristot@redhat.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=zanussi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).