linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 3/9] trace-cmd: Add --ts-check option to report
Date: Wed, 09 Dec 2020 21:29:09 -0500	[thread overview]
Message-ID: <20201210022943.172449411@goodmis.org> (raw)
In-Reply-To: 20201210022906.112066412@goodmis.org

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add a --ts-check option to trace-cmd report that will make sure that the
timestamps do not go backwards, and will print out an error message if they
do.

Link: https://lore.kernel.org/linux-trace-devel/20201201183656.012642117@goodmis.org

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/trace-cmd-report.1.txt |  4 ++++
 tracecmd/trace-read.c                | 29 +++++++++++++++++++++++++++-
 tracecmd/trace-usage.c               |  1 +
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/Documentation/trace-cmd-report.1.txt b/Documentation/trace-cmd-report.1.txt
index 864eb2d71f6a..de616cf4b47a 100644
--- a/Documentation/trace-cmd-report.1.txt
+++ b/Documentation/trace-cmd-report.1.txt
@@ -305,6 +305,10 @@ OPTIONS
      Show the time differences between events. The difference will appear in
      parenthesis just after the timestamp.
 
+*--ts-check*::
+     Make sure no timestamp goes backwards, and if it does, print out a warning
+     message of the fact.
+
 EXAMPLES
 --------
 
diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index e18110745d37..0b3eb1bc1cd9 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -99,6 +99,7 @@ static int no_irqs;
 static int no_softirqs;
 
 static int tsdiff;
+static int tscheck;
 
 static int latency_format;
 static bool raw_format;
@@ -1192,6 +1193,7 @@ enum output_type {
 static void read_data_info(struct list_head *handle_list, enum output_type otype,
 			   int global)
 {
+	unsigned long long *last_timestamp;
 	struct handle_list *handles;
 	struct handle_list *last_handle;
 	struct tep_record *record;
@@ -1216,6 +1218,10 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 		print_handle_file(handles);
 		printf("cpus=%d\n", cpus);
 
+		last_timestamp = calloc(cpus, sizeof(*last_timestamp));
+		if (!last_timestamp)
+			die("allocating timestamps");
+
 		/* Latency trace is just all ASCII */
 		if (ret > 0) {
 			if (multi_inputs)
@@ -1286,6 +1292,8 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 
 		list_for_each_entry(handles, handle_list, list) {
 			record = get_next_record(handles);
+			if (!record)
+				continue;
 			if (!last_record ||
 			    (record && record->ts < last_record->ts)) {
 				last_record = record;
@@ -1293,12 +1301,26 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 			}
 		}
 		if (last_record) {
+			int cpu = last_record->cpu;
+			if (cpu >= cpus)
+				die("cpu %d creater than %d\n", cpu, cpus);
+			if (tscheck &&
+			    last_timestamp[cpu] > last_record->ts) {
+				errno = 0;
+				warning("WARNING: Record on cpu %d went backwards: %lld to %lld delta: -%lld\n",
+					cpu, last_timestamp[cpu],
+					last_record->ts,
+					last_timestamp[cpu] - last_record->ts);
+			}
+			last_timestamp[cpu] = last_record->ts;
 			print_handle_file(last_handle);
 			trace_show_data(last_handle->handle, last_record);
 			free_handle_record(last_handle);
 		}
 	} while (last_record);
 
+	free(last_timestamp);
+
 	if (profile)
 		do_trace_profile();
 
@@ -1463,7 +1485,8 @@ static void add_hook(const char *arg)
 }
 
 enum {
-	OPT_version	= 238,
+	OPT_version	= 237,
+	OPT_tscheck	= 238,
 	OPT_tsdiff	= 239,
 	OPT_ts2secs	= 240,
 	OPT_tsoffset	= 241,
@@ -1550,6 +1573,7 @@ void trace_report (int argc, char **argv)
 			{"ts-offset", required_argument, NULL, OPT_tsoffset},
 			{"ts2secs", required_argument, NULL, OPT_ts2secs},
 			{"ts-diff", no_argument, NULL, OPT_tsdiff},
+			{"ts-check", no_argument, NULL, OPT_tscheck},
 			{"help", no_argument, NULL, '?'},
 			{NULL, 0, NULL, 0}
 		};
@@ -1719,6 +1743,9 @@ void trace_report (int argc, char **argv)
 		case OPT_tsdiff:
 			tsdiff = 1;
 			break;
+		case OPT_tscheck:
+			tscheck = 1;
+			break;
 		default:
 			usage(argv);
 		}
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 5d73c5982984..0a338ed7d19c 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -229,6 +229,7 @@ static struct usage_help usage_help[] = {
 		"                     Affects the previous data file, unless there was no\n"
 		"                     previous data file, in which case it becomes default\n"
 		"          --ts-diff Show the delta timestamp between events.\n"
+		"          --ts-check Check to make sure no time stamp on any CPU goes backwards.\n"
 	},
 	{
 		"stream",
-- 
2.29.2



  parent reply	other threads:[~2020-12-10  2:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10  2:29 [PATCH 0/9] trace-cmd: Clean ups and fixes for installing libraries Steven Rostedt
2020-12-10  2:29 ` [PATCH 1/9] trace-cmd: Fix whitespace in usage message of trace-cmd report --ts-diff Steven Rostedt
2020-12-10  2:29 ` [PATCH 2/9] trace-cmd: Add reference to trace-cmd.org in README Steven Rostedt
2020-12-10  2:29 ` Steven Rostedt [this message]
2020-12-10  2:29 ` [PATCH 4/9] trace-cmd: Update .gitignore Steven Rostedt
2020-12-10  2:29 ` [PATCH 5/9] libtracefs: Extend tracefs_iterate_raw_events() to iterate per CPU Steven Rostedt
2020-12-10  2:29 ` [PATCH 6/9] libtracefs: Unit test for tracefs_iterate_raw_events() " Steven Rostedt
2020-12-10  2:29 ` [PATCH 7/9] trace-cmd: Use system trace libraries, if available Steven Rostedt
2020-12-10  2:29 ` [PATCH 8/9] trace-cmd: Have "make test" use system libraries if present Steven Rostedt
2020-12-10  2:29 ` [PATCH 9/9] trace-cmd: Only install libtraceevent and libtracefs if not in system 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=20201210022943.172449411@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.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).