linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 5/5] trace-cmd report: New option --align-ts
Date: Wed, 28 Apr 2021 15:28:39 +0300	[thread overview]
Message-ID: <20210428122839.805296-6-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com>

A new option is added:
 trace-cmd report --align-ts
It shows timestamps aligned to the first recorded event.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 tracecmd/trace-read.c  | 25 ++++++++++++++++++++++---
 tracecmd/trace-usage.c |  1 +
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index d962b671..4a7bdb9c 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -1192,14 +1192,16 @@ enum output_type {
 };
 
 static void read_data_info(struct list_head *handle_list, enum output_type otype,
-			   int global)
+			   int global, int align_ts)
 {
+	unsigned long long ts, first_ts;
 	struct handle_list *handles;
 	struct handle_list *last_handle;
 	struct tep_record *record;
 	struct tep_record *last_record;
 	struct tep_handle *pevent;
 	struct tep_event *event;
+	int first = 1;
 	int ret;
 
 	list_for_each_entry(handles, handle_list, list) {
@@ -1218,7 +1220,12 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 		ret = tracecmd_init_data(handles->handle);
 		if (ret < 0)
 			die("failed to init data");
-
+		if (align_ts) {
+			ts = tracecmd_get_first_ts(handles->handle);
+			if (first || first_ts > ts)
+				first_ts = ts;
+			first = 0;
+		}
 		print_handle_file(handles);
 		printf("cpus=%d\n", cpus);
 
@@ -1286,6 +1293,12 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 	if (otype != OUTPUT_NORMAL)
 		return;
 
+	if (align_ts) {
+		list_for_each_entry(handles, handle_list, list) {
+			tracecmd_add_ts_offset(handles->handle, -first_ts);
+		}
+	}
+
 	do {
 		last_handle = NULL;
 		last_record = NULL;
@@ -1485,6 +1498,7 @@ static void add_hook(const char *arg)
 }
 
 enum {
+	OPT_align_ts	= 235,
 	OPT_raw_ts	= 236,
 	OPT_version	= 237,
 	OPT_tscheck	= 238,
@@ -1536,6 +1550,7 @@ void trace_report (int argc, char **argv)
 	int nanosec = 0;
 	int no_date = 0;
 	int raw_ts = 0;
+	int align_ts = 0;
 	int global = 0;
 	int neg = 0;
 	int ret = 0;
@@ -1578,6 +1593,7 @@ void trace_report (int argc, char **argv)
 			{"ts-diff", no_argument, NULL, OPT_tsdiff},
 			{"ts-check", no_argument, NULL, OPT_tscheck},
 			{"raw-ts", no_argument, NULL, OPT_raw_ts},
+			{"align-ts", no_argument, NULL, OPT_align_ts},
 			{"help", no_argument, NULL, '?'},
 			{NULL, 0, NULL, 0}
 		};
@@ -1753,6 +1769,9 @@ void trace_report (int argc, char **argv)
 		case OPT_raw_ts:
 			raw_ts = 1;
 			break;
+		case OPT_align_ts:
+			align_ts = 1;
+			break;
 		default:
 			usage(argv);
 		}
@@ -1883,7 +1902,7 @@ void trace_report (int argc, char **argv)
 	/* and version overrides uname! */
 	if (show_version)
 		otype = OUTPUT_VERSION_ONLY;
-	read_data_info(&handle_list, otype, global);
+	read_data_info(&handle_list, otype, global, align_ts);
 
 	list_for_each_entry(handles, &handle_list, list) {
 		tracecmd_close(handles->handle);
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 98247074..97b3aec0 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -234,6 +234,7 @@ static struct usage_help usage_help[] = {
 		"          --ts-diff Show the delta timestamp between events.\n"
 		"          --ts-check Check to make sure no time stamp on any CPU goes backwards.\n"
 		"          --raw-ts Display raw timestamps, without any corrections.\n"
+		"          --align-ts Display timestamps aligned to the first event.\n"
 	},
 	{
 		"stream",
-- 
2.30.2


      parent reply	other threads:[~2021-04-28 12:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 12:28 RFC [PATCH 0/5] tsc2nsec fixes Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 1/5] trace-cmd: Remove ts offset from tsc2nsec conversion Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 2/5] trace-cmd library: Remove useless check before applying ts offset Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 3/5] trace-cmd library: Store the timestamp of the first event when reading a trace file Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` [PATCH 4/5] trace-cmd library: New API for modifyning the timestamp offset Tzvetomir Stoyanov (VMware)
2021-04-28 12:28 ` Tzvetomir Stoyanov (VMware) [this message]

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=20210428122839.805296-6-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).