From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] trace-cmd: Add helper function to get the time stamp print format
Date: Mon, 6 Jul 2020 18:14:04 +0300 [thread overview]
Message-ID: <20200706151404.25603-1-tz.stoyanov@gmail.com> (raw)
Printing time stamps depends on:
- traced data - if we display latency tracing or normal events
- user defined time precision - up to nanoseconds or microseconds
In few places in the code there is logic to get the print
time stamp format based on these criteria. That code is replaced
with a helper function, to make the implementation more consistent.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
tracecmd/trace-read.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index c1f840d5..f1ba7835 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -141,13 +141,38 @@ static void print_event_name(struct trace_seq *s, struct tep_event *event)
trace_seq_printf(s, "%.*s", 20 - len, spaces);
}
+enum time_fmt {
+ TIME_FMT_LAT = 1,
+ TIME_FMT_NORMAL = 2,
+};
+
+static const char *time_format(struct tracecmd_input *handle, enum time_fmt tf)
+{
+ struct tep_handle *tep = tracecmd_get_pevent(handle);
+
+ switch (tf) {
+ case TIME_FMT_LAT:
+ if (latency_format)
+ return "%8.8s-%-5d %3d";
+ return "%16s-%-5d [%03d]";
+ default:
+ if (tracecmd_get_flags(handle) & TRACECMD_FL_IN_USECS) {
+ if (tep_test_flag(tep, TEP_NSEC_OUTPUT))
+ return " %9.1d";
+ else
+ return " %6.1000d";
+ } else
+ return "%12d:";
+ }
+}
+
static void print_event(struct trace_seq *s, struct tracecmd_input *handle,
struct tep_record *record)
{
struct tep_handle *tep = tracecmd_get_pevent(handle);
struct tep_event *event;
- const char *lfmt = latency_format ? "%8.8s-%-5d %3d" : "%16s-%-5d [%03d]";
- const char *tfmt = tracecmd_get_flags(handle) & TRACECMD_FL_IN_USECS ? " %6.1000d:" : "%12d:";
+ const char *lfmt = time_format(handle, TIME_FMT_LAT);
+ const char *tfmt = time_format(handle, TIME_FMT_NORMAL);
event = tep_find_event_by_record(tep, record);
tep_print_event(tep, s, record, lfmt, TEP_PRINT_COMM,
@@ -781,7 +806,7 @@ static void finish_wakeup(void)
void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)
{
tracecmd_show_data_func func = tracecmd_get_show_data_func(handle);
- const char *tfmt = tracecmd_get_flags(handle) & TRACECMD_FL_IN_USECS ? " %6.1000d:" : "%12d:";
+ const char *tfmt = time_format(handle, TIME_FMT_NORMAL);
struct tep_handle *pevent;
struct tep_event *event;
struct trace_seq s;
--
2.26.2
next reply other threads:[~2020-07-06 15:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 15:14 Tzvetomir Stoyanov (VMware) [this message]
2020-07-07 0:54 ` [PATCH] trace-cmd: Add helper function to get the time stamp print format 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=20200706151404.25603-1-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).