Skip to contentSkip to conversation

perf trace: Add option to show full timestamp

PATCH New David Ahern 2 participants 5 messages Sep 4, 2013 – Oct 15, 2013 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 perf trace: Add option to show full timestamp

Current timestamp shown for output is time relative to firt sample. This patch adds an option to show the absolute perf_clock timestamp which is useful when comparing output across commands (e.g., perf-trace to perf-script).

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Documentation/perf-trace.txt |    4 ++++
 tools/perf/builtin-trace.c              |    7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-trace.txt +4 -0
index daccd2c..a93e91a 100644
@@ -78,6 +78,10 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
 --input
 	Process events from a given perf data file.
 
+-T
+--time
+	Print full timestamp rather time relative to first sample.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script[1]
tools/perf/builtin-trace.c +5 -2
index 6730862..9ef489c 100644
@@ -605,6 +605,7 @@ struct trace {
 	struct perf_record_opts opts;
 	struct machine		host;
 	u64			base_time;
+	bool			full_time;
 	FILE			*output;
 	unsigned long		nr_events;
 	struct strlist		*ev_qualifier;
@@ -1047,7 +1048,7 @@ static int trace__process_sample(struct perf_tool *tool,
 	if (skip_sample(trace, sample))
 		return 0;
 
-	if (trace->base_time == 0)
+	if (!trace->full_time && trace->base_time == 0)
 		trace->base_time = sample->time;
 
 	if (handler)
@@ -1176,7 +1177,7 @@ again:
 				continue;
 			}
 
-			if (trace->base_time == 0)
+			if (!trace->full_time && trace->base_time == 0)
 				trace->base_time = sample.time;
 
 			if (type != PERF_RECORD_SAMPLE) {
@@ -1413,6 +1414,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		     trace__set_duration),
 	OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('T', "time", &trace.full_time,
+		    "Show full timestamp, not time relative to first start"),
 	OPT_END()
 	};
 	int err;
Signature · 1 line
1.7.10.1
#1 lore raw

PATCH 2/3 perf trace: Remove duplicate mmap entry in syscall_fmts array

Entries in syscall_fmts need to be in alphabetical order, and the duplicate entry breaks bsearch on new entries around this duplicate entry.

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-trace.c |    1 -
 1 file changed, 1 deletion(-)
tools/perf/builtin-trace.c +0 -1
index 9ef489c..b245102 100644
@@ -442,7 +442,6 @@ static struct syscall_fmt {
 	{ .name	    = "arch_prctl", .errmsg = true, .alias = "prctl", },
 	{ .name	    = "brk",	    .hexret = true,
 	  .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, },
-	{ .name	    = "mmap",	    .hexret = true, },
 	{ .name	    = "connect",    .errmsg = true, },
 	{ .name	    = "fcntl",	    .errmsg = true,
 	  .arg_scnprintf = { [1] = SCA_STRARRAY, /* cmd */ },
Signature · 1 line
1.7.10.1
#2 lore raw

[tip:perf/core] perf trace: Remove duplicate mmap entry in syscall_fmts array

perf trace: Remove duplicate mmap entry in syscall_fmts array
Commit-ID:  770480592084d2c114adedfbe6740e345aaf2279
Gitweb:     http://git.kernel.org/tip/770480592084d2c114adedfbe6740e345aaf2279
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 4 Sep 2013 12:37:44 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:10:56 -0300

perf trace: Remove duplicate mmap entry in syscall_fmts array

Entries in syscall_fmts need to be in alphabetical order, and the duplicate entry breaks bsearch on new entries around this duplicate entry.

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-trace.c | 1 -
 1 file changed, 1 deletion(-)
tools/perf/builtin-trace.c +0 -1
index bc21140..903416c 100644
@@ -461,7 +461,6 @@ static struct syscall_fmt {
 	{ .name	    = "arch_prctl", .errmsg = true, .alias = "prctl", },
 	{ .name	    = "brk",	    .hexret = true,
 	  .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, },
-	{ .name	    = "mmap",	    .hexret = true, },
 	{ .name	    = "connect",    .errmsg = true, },
 	{ .name	    = "fcntl",	    .errmsg = true,
 	  .arg_scnprintf = { [1] = SCA_STRARRAY, /* cmd */ },
#3 lore raw

PATCH 3/3 perf trace: Add beautifier for clock_gettime's clk_id argument

In reply to David Ahern

Before:
0.030 ( 0.002 ms): 2571 clock_gettime(which_clock: 1, tp: 0x7f3b45729cd0 ) = 0

After:
0.030 ( 0.002 ms): 2571 clock_gettime(which_clock: MONOTONIC, tp: 0x7f3b45729cd0 ) = 0

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-trace.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
tools/perf/builtin-trace.c +33 -0
index b245102..f943960 100644
@@ -428,6 +428,37 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
 
 #define SCA_SIGNUM syscall_arg__scnprintf_signum
 
+static size_t
+syscall_arg__scnprintf_clk_gettime(char *bf, size_t size,
+				   struct syscall_arg *arg)
+{
+	size_t printed = 0;
+	clockid_t clk_id = arg->val;
+
+	switch (clk_id) {
+#define	P_CLOCK_ID(n) case CLOCK_##n: printed = scnprintf(bf, size, #n);
+	P_CLOCK_ID(REALTIME);		break;
+#ifdef CLOCK_REALTIME_COARSE
+	P_CLOCK_ID(REALTIME_COARSE);	break;
+#endif
+	P_CLOCK_ID(MONOTONIC);		break;
+#ifdef CLOCK_MONOTONIC_RAW
+	P_CLOCK_ID(MONOTONIC_RAW);	break;
+#endif
+#ifdef CLOCK_MONOTONIC_COARSE
+	P_CLOCK_ID(MONOTONIC_COARSE);	break;
+#endif
+	P_CLOCK_ID(PROCESS_CPUTIME_ID);	break;
+	P_CLOCK_ID(THREAD_CPUTIME_ID);	break;
+#undef P_CLOCK_ID
+	default: printed = scnprintf(bf, size, "%#x", arg); break;
+	}
+
+	return printed;
+}
+
+#define SCA_CLOCK_ID syscall_arg__scnprintf_clk_gettime
+
 static struct syscall_fmt {
 	const char *name;
 	const char *alias;
@@ -442,6 +473,8 @@ static struct syscall_fmt {
 	{ .name	    = "arch_prctl", .errmsg = true, .alias = "prctl", },
 	{ .name	    = "brk",	    .hexret = true,
 	  .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, },
+	{ .name	    = "clock_gettime", .errmsg = true,
+	  .arg_scnprintf = { [0] = SCA_CLOCK_ID, /* clk_id */ }, },
 	{ .name	    = "connect",    .errmsg = true, },
 	{ .name	    = "fcntl",	    .errmsg = true,
 	  .arg_scnprintf = { [1] = SCA_STRARRAY, /* cmd */ },
Signature · 1 line
1.7.10.1
#4 lore raw
In reply to David Ahern
perf trace: Add option to show full timestamp
Commit-ID:  4bb09192d38ef08f0619667527cabb26354fff89
Gitweb:     http://git.kernel.org/tip/4bb09192d38ef08f0619667527cabb26354fff89
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 4 Sep 2013 12:37:43 -0600
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:10:49 -0300

perf trace: Add option to show full timestamp

Current timestamp shown for output is time relative to firt sample. This patch adds an option to show the absolute perf_clock timestamp which is useful when comparing output across commands (e.g., perf-trace to perf-script).

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Documentation/perf-trace.txt | 4 ++++
 tools/perf/builtin-trace.c              | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-trace.txt +4 -0
index daccd2c..a93e91a 100644
@@ -78,6 +78,10 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
 --input
 	Process events from a given perf data file.
 
+-T
+--time
+	Print full timestamp rather time relative to first sample.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script[1]
tools/perf/builtin-trace.c +5 -2
index 7ce036e..bc21140 100644
@@ -624,6 +624,7 @@ struct trace {
 	struct perf_record_opts opts;
 	struct machine		host;
 	u64			base_time;
+	bool			full_time;
 	FILE			*output;
 	unsigned long		nr_events;
 	struct strlist		*ev_qualifier;
@@ -1066,7 +1067,7 @@ static int trace__process_sample(struct perf_tool *tool,
 	if (skip_sample(trace, sample))
 		return 0;
 
-	if (trace->base_time == 0)
+	if (!trace->full_time && trace->base_time == 0)
 		trace->base_time = sample->time;
 
 	if (handler)
@@ -1195,7 +1196,7 @@ again:
 				continue;
 			}
 
-			if (trace->base_time == 0)
+			if (!trace->full_time && trace->base_time == 0)
 				trace->base_time = sample.time;
 
 			if (type != PERF_RECORD_SAMPLE) {
@@ -1433,6 +1434,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		     trace__set_duration),
 	OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
 	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+	OPT_BOOLEAN('T', "time", &trace.full_time,
+		    "Show full timestamp, not time relative to first start"),
 	OPT_END()
 	};
 	int err;