From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v25 04/16] trace-cmd: Add new libtrasefs API to get the current trace clock
Date: Thu, 29 Oct 2020 13:18:04 +0200 [thread overview]
Message-ID: <20201029111816.247241-5-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20201029111816.247241-1-tz.stoyanov@gmail.com>
A new API is added to tracefs library:
tracefs_get_clock()
It reads the trace_clock file from the ftrace file system, parses it
and returns a string with the current trace clock. The returned string
must be freed by free().
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
include/tracefs/tracefs.h | 2 ++
lib/tracefs/tracefs-instance.c | 35 ++++++++++++++++++++++++++++++++++
tracecmd/trace-stat.c | 29 +++++++---------------------
3 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index 8ee7ba6e..fb33e6e8 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -55,4 +55,6 @@ struct tep_handle *tracefs_local_events_system(const char *tracing_dir,
int tracefs_fill_local_events(const char *tracing_dir,
struct tep_handle *tep, int *parsing_failures);
+char *tracefs_get_clock(struct tracefs_instance *instance);
+
#endif /* _TRACE_FS_H */
diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
index 50e88534..89d0b484 100644
--- a/lib/tracefs/tracefs-instance.c
+++ b/lib/tracefs/tracefs-instance.c
@@ -291,3 +291,38 @@ bool tracefs_dir_exists(struct tracefs_instance *instance, char *name)
{
return check_file_exists(instance, name, true);
}
+
+/**
+ * tracefs_get_clock - Get the current trace clock
+ * @instance: ftrace instance, can be NULL for the top instance
+ *
+ * Returns the current trace clock of the given instance, or NULL in
+ * case of an error.
+ * The return string must be freed by free()
+ */
+char *tracefs_get_clock(struct tracefs_instance *instance)
+{
+ char *all_clocks = NULL;
+ char *ret = NULL;
+ int bytes = 0;
+ char *clock;
+ char *cont;
+
+ all_clocks = tracefs_instance_file_read(instance, "trace_clock", &bytes);
+ if (!all_clocks || !bytes)
+ goto out;
+
+ clock = strstr(all_clocks, "[");
+ if (!clock)
+ goto out;
+ clock++;
+ cont = strstr(clock, "]");
+ if (!cont)
+ goto out;
+ *cont = '\0';
+
+ ret = strdup(clock);
+out:
+ free(all_clocks);
+ return ret;
+}
diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index 260d0c37..a29e0c34 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -736,33 +736,18 @@ static void report_buffers(struct buffer_instance *instance)
static void report_clock(struct buffer_instance *instance)
{
- char *str;
- char *cont;
char *clock;
- str = get_instance_file_content(instance, "trace_clock");
- if (!str)
- return;
-
- clock = strstr(str, "[");
- if (!clock)
- goto out;
- clock++;
-
- cont = strstr(clock, "]");
- if (!cont) /* should never happen */
- goto out;
-
- *cont = '\0';
+ if (instance)
+ clock = tracefs_get_clock(instance->tracefs);
+ else
+ clock = tracefs_get_clock(NULL);
/* Default clock is "local", only show others */
- if (strcmp(clock, "local") == 0)
- goto out;
+ if (clock && !strcmp(clock, "local") == 0)
+ printf("\nClock: %s\n", clock);
- printf("\nClock: %s\n", clock);
-
- out:
- free(str);
+ free(clock);
}
static void report_cpumask(struct buffer_instance *instance)
--
2.26.2
next prev parent reply other threads:[~2020-10-29 11:18 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 11:18 [PATCH v25 00/16] Timestamp synchronization of host - guest tracing session Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 01/16] trace-cmd: Replace time sync protocol ID with string Tzvetomir Stoyanov (VMware)
2020-11-05 14:52 ` Steven Rostedt
2020-12-02 22:43 ` Steven Rostedt
2020-10-29 11:18 ` [PATCH v25 02/16] trace-cmd: Add trace-cmd library APIs for ftrace clock name Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 03/16] trace-cmd: Move VM related logic in a separate file Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` Tzvetomir Stoyanov (VMware) [this message]
2020-10-29 11:18 ` [PATCH v25 05/16] trace-cmd: Add clock parameter to timestamp synchronization plugins Tzvetomir Stoyanov (VMware)
2020-12-02 22:48 ` Steven Rostedt
2020-12-03 13:09 ` Tzvetomir Stoyanov
2020-10-29 11:18 ` [PATCH v25 06/16] trace-cmd: Add role " Tzvetomir Stoyanov (VMware)
2020-12-02 23:04 ` Steven Rostedt
2020-10-29 11:18 ` [PATCH v25 07/16] trace-cmd: Add host / guest role in timestamp synchronization context Tzvetomir Stoyanov (VMware)
2020-12-02 23:07 ` Steven Rostedt
2020-10-29 11:18 ` [PATCH v25 08/16] trace-cmd: Add guest CPU count PID in tracecmd_time_sync struct Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 09/16] trace-cmd: Add scaling ratio for timestamp correction Tzvetomir Stoyanov (VMware)
2020-12-03 1:47 ` Steven Rostedt
2020-12-03 12:56 ` Tzvetomir Stoyanov
2020-10-29 11:18 ` [PATCH v25 10/16] trace-cmd: Add time sync protocol flags Tzvetomir Stoyanov (VMware)
2020-12-03 2:09 ` Steven Rostedt
2020-12-03 12:59 ` Tzvetomir Stoyanov
2020-10-29 11:18 ` [PATCH v25 11/16] trace-cmd: Add timestamp synchronization per vCPU Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 12/16] trace-cmd: Define a macro for packed structures Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 13/16] trace-cmd: Add dummy function to initialize timestamp sync logic Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 14/16] trace-cmd: [POC] PTP-like algorithm for host - guest timestamp synchronization Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 15/16] trace-cmd: Debug scripts for " Tzvetomir Stoyanov (VMware)
2020-10-29 11:18 ` [PATCH v25 16/16] trace-cmd [POC]: Add KVM timestamp synchronization plugin Tzvetomir Stoyanov (VMware)
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=20201029111816.247241-5-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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).