All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] perf: Add option to specify time window of interest
@ 2016-11-29 17:15 David Ahern
  2016-11-29 17:15 ` [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern
                   ` (6 more replies)
  0 siblings, 7 replies; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

This series allows users to collect data and analyze a time window of
interest within the file.

v2
- renamed perf_time to perf_time_interval
- changed ../perf.h to perf.h in patch 1

David Ahern (6):
  perf tool: Add time-based utility functions
  perf tool: Move parse_nsec_time to time-utils.c
  perf script: Add option to specify time window of interest
  perf sched timehist: Add option to specify time window of interest
  perf kmem: Add option to specify time window of interest
  perf report: Add option to specify time window of interest

 tools/perf/Documentation/perf-kmem.txt   |   7 ++
 tools/perf/Documentation/perf-report.txt |   7 ++
 tools/perf/Documentation/perf-sched.txt  |   8 +++
 tools/perf/Documentation/perf-script.txt |   7 ++
 tools/perf/builtin-kmem.c                |  24 +++++++
 tools/perf/builtin-report.c              |  14 +++-
 tools/perf/builtin-sched.c               |  51 +++++++++++--
 tools/perf/builtin-script.c              |  15 +++-
 tools/perf/util/Build                    |   1 +
 tools/perf/util/time-utils.c             | 118 +++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h             |  14 ++++
 tools/perf/util/util.c                   |  33 ---------
 tools/perf/util/util.h                   |   2 -
 13 files changed, 258 insertions(+), 43 deletions(-)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h

-- 
2.7.4 (Apple Git-66)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 1/6] perf tool: Add time-based utility functions
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-12-02 10:41   ` [tip:perf/core] perf tools: " tip-bot for David Ahern
  2016-11-29 17:15 ` [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Add function to parse a user time string of the form <start>,<stop>
where start and stop are time in sec.nsec format. Both start and stop
times are optional.

Add function to determine if a sample time is within a given time
time window of interest.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/time-utils.c
 create mode 100644 tools/perf/util/time-utils.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b2a47aac8d1c..bdad82a9812d 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
new file mode 100644
index 000000000000..0443b2afd0cf
--- /dev/null
+++ b/tools/perf/util/time-utils.c
@@ -0,0 +1,85 @@
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include "perf.h"
+#include "debug.h"
+#include "time-utils.h"
+#include "util.h"
+
+static int parse_timestr_sec_nsec(struct perf_time_interval *ptime,
+				  char *start_str, char *end_str)
+{
+	if (start_str && (*start_str != '\0') &&
+	    (parse_nsec_time(start_str, &ptime->start) != 0)) {
+		return -1;
+	}
+
+	if (end_str && (*end_str != '\0') &&
+	    (parse_nsec_time(end_str, &ptime->end) != 0)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
+{
+	char *start_str, *end_str;
+	char *d, *str;
+	int rc = 0;
+
+	if (ostr == NULL || *ostr == '\0')
+		return 0;
+
+	/* copy original string because we need to modify it */
+	str = strdup(ostr);
+	if (str == NULL)
+		return -ENOMEM;
+
+	ptime->start = 0;
+	ptime->end = 0;
+
+	/* str has the format: <start>,<stop>
+	 * variations: <start>,
+	 *             ,<stop>
+	 *             ,
+	 */
+	start_str = str;
+	d = strchr(start_str, ',');
+	if (d) {
+		*d = '\0';
+		++d;
+	}
+	end_str = d;
+
+	rc = parse_timestr_sec_nsec(ptime, start_str, end_str);
+
+	free(str);
+
+	/* make sure end time is after start time if it was given */
+	if (rc == 0 && ptime->end && ptime->end < ptime->start)
+		return -EINVAL;
+
+	pr_debug("start time %" PRIu64 ", ", ptime->start);
+	pr_debug("end time %" PRIu64 "\n", ptime->end);
+
+	return rc;
+}
+
+bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
+{
+	/* if time is not set don't drop sample */
+	if (timestamp == 0)
+		return false;
+
+	/* otherwise compare sample time to time window */
+	if ((ptime->start && timestamp < ptime->start) ||
+	    (ptime->end && timestamp > ptime->end)) {
+		return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
new file mode 100644
index 000000000000..8f3e0e370be8
--- /dev/null
+++ b/tools/perf/util/time-utils.h
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time_interval {
+	u64 start, end;
+};
+
+int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
+
+bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
+
+#endif
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
  2016-11-29 17:15 ` [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-12-02 10:41   ` [tip:perf/core] perf tools: " tip-bot for David Ahern
  2016-11-29 17:15 ` [PATCH v2 3/6] perf script: Add option to specify time window of interest David Ahern
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Code move only; no functional change intended.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/util/time-utils.c | 35 ++++++++++++++++++++++++++++++++++-
 tools/perf/util/time-utils.h |  2 ++
 tools/perf/util/util.c       | 33 ---------------------------------
 tools/perf/util/util.h       |  2 --
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 0443b2afd0cf..4ea7c4c80720 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <sys/time.h>
+#include <linux/time64.h>
 #include <time.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -7,7 +8,39 @@
 #include "perf.h"
 #include "debug.h"
 #include "time-utils.h"
-#include "util.h"
+
+int parse_nsec_time(const char *str, u64 *ptime)
+{
+	u64 time_sec, time_nsec;
+	char *end;
+
+	time_sec = strtoul(str, &end, 10);
+	if (*end != '.' && *end != '\0')
+		return -1;
+
+	if (*end == '.') {
+		int i;
+		char nsec_buf[10];
+
+		if (strlen(++end) > 9)
+			return -1;
+
+		strncpy(nsec_buf, end, 9);
+		nsec_buf[9] = '\0';
+
+		/* make it nsec precision */
+		for (i = strlen(nsec_buf); i < 9; i++)
+			nsec_buf[i] = '0';
+
+		time_nsec = strtoul(nsec_buf, &end, 10);
+		if (*end != '\0')
+			return -1;
+	} else
+		time_nsec = 0;
+
+	*ptime = time_sec * NSEC_PER_SEC + time_nsec;
+	return 0;
+}
 
 static int parse_timestr_sec_nsec(struct perf_time_interval *ptime,
 				  char *start_str, char *end_str)
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 8f3e0e370be8..c1f197c4af6c 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -5,6 +5,8 @@ struct perf_time_interval {
 	u64 start, end;
 };
 
+int parse_nsec_time(const char *str, u64 *ptime);
+
 int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
 
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 67ac765da27a..9ddd98827d12 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig)
 	raise(sig);
 }
 
-int parse_nsec_time(const char *str, u64 *ptime)
-{
-	u64 time_sec, time_nsec;
-	char *end;
-
-	time_sec = strtoul(str, &end, 10);
-	if (*end != '.' && *end != '\0')
-		return -1;
-
-	if (*end == '.') {
-		int i;
-		char nsec_buf[10];
-
-		if (strlen(++end) > 9)
-			return -1;
-
-		strncpy(nsec_buf, end, 9);
-		nsec_buf[9] = '\0';
-
-		/* make it nsec precision */
-		for (i = strlen(nsec_buf); i < 9; i++)
-			nsec_buf[i] = '0';
-
-		time_nsec = strtoul(nsec_buf, &end, 10);
-		if (*end != '\0')
-			return -1;
-	} else
-		time_nsec = 0;
-
-	*ptime = time_sec * NSEC_PER_SEC + time_nsec;
-	return 0;
-}
-
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
 	u64  sec = timestamp / NSEC_PER_SEC;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 79662d67891e..1d639e38aa82 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)
 #undef tolower
 #undef toupper
 
-int parse_nsec_time(const char *str, u64 *ptime);
-
 extern unsigned char sane_ctype[256];
 #define GIT_SPACE		0x01
 #define GIT_DIGIT		0x02
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 3/6] perf script: Add option to specify time window of interest
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
  2016-11-29 17:15 ` [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern
  2016-11-29 17:15 ` [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-12-02 10:42   ` [tip:perf/core] " tip-bot for David Ahern
  2016-11-29 17:15 ` [PATCH v2 4/6] perf sched timehist: " David Ahern
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Add option to allow user to control analysis window. e.g., collect data
for some amount of time and analyze a segment of interest within that
window.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-script.txt |  7 +++++++
 tools/perf/builtin-script.c              | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 0f6ee09f7256..5dc5c6a09ac4 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -292,6 +292,13 @@ include::itrace.txt[]
 --force::
 	Don't do ownership validation.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 066b4bf73780..2f3ff69fc4e7 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/thread-stack.h"
+#include "util/time-utils.h"
 #include <linux/bitmap.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
@@ -833,6 +834,8 @@ struct perf_script {
 	struct cpu_map		*cpus;
 	struct thread_map	*threads;
 	int			name_width;
+	const char              *time_str;
+	struct perf_time_interval ptime;
 };
 
 static int perf_evlist__max_name_len(struct perf_evlist *evlist)
@@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool,
 	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
+	if (perf_time__skip_sample(&scr->ptime, sample->time))
+		return 0;
+
 	if (debug_mode) {
 		if (sample->time < last_timestamp) {
 			pr_err("Samples misordered, previous: %" PRIu64
@@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			"Enable symbol demangling"),
 	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
 			"Enable kernel symbol demangling"),
-
+	OPT_STRING(0, "time", &script.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
@@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (err < 0)
 		goto out_delete;
 
+	/* needs to be parsed after looking up reference time */
+	if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	err = __cmd_script(&script);
 
 	flush_scripting();
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
                   ` (2 preceding siblings ...)
  2016-11-29 17:15 ` [PATCH v2 3/6] perf script: Add option to specify time window of interest David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-11-29 18:56   ` Arnaldo Carvalho de Melo
  2016-12-02 10:42   ` [tip:perf/core] " tip-bot for David Ahern
  2016-11-29 17:15 ` [PATCH v2 5/6] perf kmem: " David Ahern
                   ` (2 subsequent siblings)
  6 siblings, 2 replies; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-sched.txt |  8 ++++++
 tools/perf/builtin-sched.c              | 51 +++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 121c60da03e5..7775b1eb2bee 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist'
 --migrations::
 	Show migration events.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 4f9e7cba4ebf..870d94cd20ba 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -15,6 +15,7 @@
 #include "util/color.h"
 #include "util/stat.h"
 #include "util/callchain.h"
+#include "util/time-utils.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -205,6 +206,8 @@ struct perf_sched {
 	bool		show_wakeups;
 	bool		show_migrations;
 	u64		skipped_samples;
+	const char	*time_str;
+	struct perf_time_interval ptime;
 };
 
 /* per thread run time data */
@@ -1837,13 +1840,14 @@ static void timehist_header(struct perf_sched *sched)
 static void timehist_print_sample(struct perf_sched *sched,
 				  struct perf_sample *sample,
 				  struct addr_location *al,
-				  struct thread *thread)
+				  struct thread *thread,
+				  u64 t)
 {
 	struct thread_runtime *tr = thread__priv(thread);
 	u32 max_cpus = sched->max_cpu + 1;
 	char tstr[64];
 
-	timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr));
+	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
 	printf("%15s [%04d] ", tstr, sample->cpu);
 
 	if (sched->show_cpu_visual) {
@@ -2194,7 +2198,8 @@ static int timehist_sched_wakeup_event(struct perf_tool *tool,
 		tr->ready_to_run = sample->time;
 
 	/* show wakeups if requested */
-	if (sched->show_wakeups)
+	if (sched->show_wakeups &&
+	    !perf_time__skip_sample(&sched->ptime, sample->time))
 		timehist_print_wakeup_event(sched, sample, machine, thread);
 
 	return 0;
@@ -2288,10 +2293,11 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 				       struct machine *machine)
 {
 	struct perf_sched *sched = container_of(tool, struct perf_sched, tool);
+	struct perf_time_interval *ptime = &sched->ptime;
 	struct addr_location al;
 	struct thread *thread;
 	struct thread_runtime *tr = NULL;
-	u64 tprev;
+	u64 tprev, t = sample->time;
 	int rc = 0;
 
 	if (machine__resolve(machine, &al, sample) < 0) {
@@ -2318,9 +2324,35 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 
 	tprev = perf_evsel__get_time(evsel, sample->cpu);
 
-	timehist_update_runtime_stats(tr, sample->time, tprev);
+	/*
+	 * If start time given:
+	 * - sample time is under window user cares about - skip sample
+	 * - tprev is under window user cares about  - reset to start of window
+	 */
+	if (ptime->start && ptime->start > t)
+		goto out;
+
+	if (ptime->start > tprev)
+		tprev = ptime->start;
+
+	/*
+	 * If end time given:
+	 * - previous sched event is out of window - we are done
+	 * - sample time is beyond window user cares about - reset it
+	 *   to close out stats for time window interest
+	 */
+	if (ptime->end) {
+		if (tprev > ptime->end)
+			goto out;
+
+		if (t > ptime->end)
+			t = ptime->end;
+	}
+
+	timehist_update_runtime_stats(tr, t, tprev);
+
 	if (!sched->summary_only)
-		timehist_print_sample(sched, sample, &al, thread);
+		timehist_print_sample(sched, sample, &al, thread, t);
 
 out:
 	if (tr) {
@@ -2583,6 +2615,11 @@ static int perf_sched__timehist(struct perf_sched *sched)
 
 	symbol__init(&session->header.env);
 
+	if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	if (timehist_check_attr(sched, evlist) != 0)
 		goto out;
 
@@ -2997,6 +3034,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"),
 	OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"),
 	OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"),
+	OPT_STRING(0, "time", &sched.time_str, "str",
+		   "Time span for analysis (start,stop)"),
 	OPT_PARENT(sched_options)
 	};
 
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 5/6] perf kmem: Add option to specify time window of interest
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
                   ` (3 preceding siblings ...)
  2016-11-29 17:15 ` [PATCH v2 4/6] perf sched timehist: " David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-12-02 10:43   ` [tip:perf/core] " tip-bot for David Ahern
  2016-11-29 17:15 ` [PATCH v2 6/6] perf report: " David Ahern
  2016-11-29 19:15 ` [PATCH v2 0/6] perf: " Arnaldo Carvalho de Melo
  6 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-kmem.txt |  7 +++++++
 tools/perf/builtin-kmem.c              | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt
index ff0f433b3fce..479fc3261a50 100644
--- a/tools/perf/Documentation/perf-kmem.txt
+++ b/tools/perf/Documentation/perf-kmem.txt
@@ -61,6 +61,13 @@ OPTIONS
 	default, but this option shows live (currently allocated) pages
 	instead.  (This option works with --page option only)
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 7fd6f1e1e293..35a02f8e5a4a 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/callchain.h"
+#include "util/time-utils.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -66,6 +67,10 @@ static struct rb_root root_caller_sorted;
 static unsigned long total_requested, total_allocated, total_freed;
 static unsigned long nr_allocs, nr_cross_allocs;
 
+/* filters for controlling start and stop of time of analysis */
+static struct perf_time_interval ptime;
+const char *time_str;
+
 static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
 			     int bytes_req, int bytes_alloc, int cpu)
 {
@@ -912,6 +917,15 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
 	return 0;
 }
 
+static bool perf_kmem__skip_sample(struct perf_sample *sample)
+{
+	/* skip sample based on time? */
+	if (perf_time__skip_sample(&ptime, sample->time))
+		return true;
+
+	return false;
+}
+
 typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
 				  struct perf_sample *sample);
 
@@ -931,6 +945,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
+	if (perf_kmem__skip_sample(sample))
+		return 0;
+
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
 
 	if (evsel->handler != NULL) {
@@ -1894,6 +1911,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator",
 			   parse_page_opt),
 	OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"),
+	OPT_STRING(0, "time", &time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char *const kmem_subcommands[] = { "record", "stat", NULL };
@@ -1954,6 +1973,11 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	symbol__init(&session->header.env);
 
+	if (perf_time__parse_str(&ptime, time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	if (!strcmp(argv[0], "stat")) {
 		setlocale(LC_ALL, "");
 
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 6/6] perf report: Add option to specify time window of interest
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
                   ` (4 preceding siblings ...)
  2016-11-29 17:15 ` [PATCH v2 5/6] perf kmem: " David Ahern
@ 2016-11-29 17:15 ` David Ahern
  2016-12-02 10:43   ` [tip:perf/core] " tip-bot for David Ahern
  2016-11-29 19:15 ` [PATCH v2 0/6] perf: " Arnaldo Carvalho de Melo
  6 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 17:15 UTC (permalink / raw)
  To: acme; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-report.txt |  7 +++++++
 tools/perf/builtin-report.c              | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 2d1746295abf..3a166ae4a4d3 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -382,6 +382,13 @@ OPTIONS
 --header-only::
 	Show only perf.data header (forces --stdio).
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 --itrace::
 	Options for decoding instruction tracing data. The options are:
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3dfbfffe2ecd..d2afbe4a240d 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -36,7 +36,7 @@
 #include "util/hist.h"
 #include "util/data.h"
 #include "arch/common.h"
-
+#include "util/time-utils.h"
 #include "util/auxtrace.h"
 
 #include <dlfcn.h>
@@ -59,6 +59,8 @@ struct report {
 	const char		*pretty_printing_style;
 	const char		*cpu_list;
 	const char		*symbol_filter_str;
+	const char		*time_str;
+	struct perf_time_interval ptime;
 	float			min_percent;
 	u64			nr_entries;
 	u64			queue_size;
@@ -158,6 +160,9 @@ static int process_sample_event(struct perf_tool *tool,
 	};
 	int ret = 0;
 
+	if (perf_time__skip_sample(&rep->ptime, sample->time))
+		return 0;
+
 	if (machine__resolve(machine, &al, sample) < 0) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -830,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
 			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
 			     stdio__config_color, "always"),
+	OPT_STRING(0, "time", &report.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
@@ -1015,6 +1022,11 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (symbol__init(&session->header.env) < 0)
 		goto error;
 
+	if (perf_time__parse_str(&report.ptime, report.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	sort__setup_elide(stdout);
 
 	ret = __cmd_report(&report);
-- 
2.7.4 (Apple Git-66)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
  2016-11-29 17:15 ` [PATCH v2 4/6] perf sched timehist: " David Ahern
@ 2016-11-29 18:56   ` Arnaldo Carvalho de Melo
  2016-11-29 18:58     ` David Ahern
  2016-12-02 10:42   ` [tip:perf/core] " tip-bot for David Ahern
  1 sibling, 1 reply; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-11-29 18:56 UTC (permalink / raw)
  To: David Ahern; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
> Add option to allow user to control analysis window. e.g., collect data
> for time window and analyze a segment of interest within that window.

Trying to test this I got:

[root@jouet ~]# perf sched timehist
No trace sample to read. Did you call 'perf record -R'?
[root@jouet ~]#

Could you please provide a better error message?

The perf.data file had this:

[root@jouet ~]# perf evlist -v
cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
[root@jouet ~]# 

- Arnaldo
 
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
>  tools/perf/Documentation/perf-sched.txt |  8 ++++++
>  tools/perf/builtin-sched.c              | 51 +++++++++++++++++++++++++++++----
>  2 files changed, 53 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
> index 121c60da03e5..7775b1eb2bee 100644
> --- a/tools/perf/Documentation/perf-sched.txt
> +++ b/tools/perf/Documentation/perf-sched.txt
> @@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist'
>  --migrations::
>  	Show migration events.
>  
> +--time::
> +	Only analyze samples within given time window: <start>,<stop>. Times
> +	have the format seconds.microseconds. If start is not given (i.e., time
> +	string is ',x.y') then analysis starts at the beginning of the file. If
> +	stop time is not given (i.e, time string is 'x.y,') then analysis goes
> +	to end of file.
> +
> +
>  SEE ALSO
>  --------
>  linkperf:perf-record[1]
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 4f9e7cba4ebf..870d94cd20ba 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -15,6 +15,7 @@
>  #include "util/color.h"
>  #include "util/stat.h"
>  #include "util/callchain.h"
> +#include "util/time-utils.h"
>  
>  #include <subcmd/parse-options.h>
>  #include "util/trace-event.h"
> @@ -205,6 +206,8 @@ struct perf_sched {
>  	bool		show_wakeups;
>  	bool		show_migrations;
>  	u64		skipped_samples;
> +	const char	*time_str;
> +	struct perf_time_interval ptime;
>  };
>  
>  /* per thread run time data */
> @@ -1837,13 +1840,14 @@ static void timehist_header(struct perf_sched *sched)
>  static void timehist_print_sample(struct perf_sched *sched,
>  				  struct perf_sample *sample,
>  				  struct addr_location *al,
> -				  struct thread *thread)
> +				  struct thread *thread,
> +				  u64 t)
>  {
>  	struct thread_runtime *tr = thread__priv(thread);
>  	u32 max_cpus = sched->max_cpu + 1;
>  	char tstr[64];
>  
> -	timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr));
> +	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
>  	printf("%15s [%04d] ", tstr, sample->cpu);
>  
>  	if (sched->show_cpu_visual) {
> @@ -2194,7 +2198,8 @@ static int timehist_sched_wakeup_event(struct perf_tool *tool,
>  		tr->ready_to_run = sample->time;
>  
>  	/* show wakeups if requested */
> -	if (sched->show_wakeups)
> +	if (sched->show_wakeups &&
> +	    !perf_time__skip_sample(&sched->ptime, sample->time))
>  		timehist_print_wakeup_event(sched, sample, machine, thread);
>  
>  	return 0;
> @@ -2288,10 +2293,11 @@ static int timehist_sched_change_event(struct perf_tool *tool,
>  				       struct machine *machine)
>  {
>  	struct perf_sched *sched = container_of(tool, struct perf_sched, tool);
> +	struct perf_time_interval *ptime = &sched->ptime;
>  	struct addr_location al;
>  	struct thread *thread;
>  	struct thread_runtime *tr = NULL;
> -	u64 tprev;
> +	u64 tprev, t = sample->time;
>  	int rc = 0;
>  
>  	if (machine__resolve(machine, &al, sample) < 0) {
> @@ -2318,9 +2324,35 @@ static int timehist_sched_change_event(struct perf_tool *tool,
>  
>  	tprev = perf_evsel__get_time(evsel, sample->cpu);
>  
> -	timehist_update_runtime_stats(tr, sample->time, tprev);
> +	/*
> +	 * If start time given:
> +	 * - sample time is under window user cares about - skip sample
> +	 * - tprev is under window user cares about  - reset to start of window
> +	 */
> +	if (ptime->start && ptime->start > t)
> +		goto out;
> +
> +	if (ptime->start > tprev)
> +		tprev = ptime->start;
> +
> +	/*
> +	 * If end time given:
> +	 * - previous sched event is out of window - we are done
> +	 * - sample time is beyond window user cares about - reset it
> +	 *   to close out stats for time window interest
> +	 */
> +	if (ptime->end) {
> +		if (tprev > ptime->end)
> +			goto out;
> +
> +		if (t > ptime->end)
> +			t = ptime->end;
> +	}
> +
> +	timehist_update_runtime_stats(tr, t, tprev);
> +
>  	if (!sched->summary_only)
> -		timehist_print_sample(sched, sample, &al, thread);
> +		timehist_print_sample(sched, sample, &al, thread, t);
>  
>  out:
>  	if (tr) {
> @@ -2583,6 +2615,11 @@ static int perf_sched__timehist(struct perf_sched *sched)
>  
>  	symbol__init(&session->header.env);
>  
> +	if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) {
> +		pr_err("Invalid time string\n");
> +		return -EINVAL;
> +	}
> +
>  	if (timehist_check_attr(sched, evlist) != 0)
>  		goto out;
>  
> @@ -2997,6 +3034,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
>  	OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"),
>  	OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"),
>  	OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"),
> +	OPT_STRING(0, "time", &sched.time_str, "str",
> +		   "Time span for analysis (start,stop)"),
>  	OPT_PARENT(sched_options)
>  	};
>  
> -- 
> 2.7.4 (Apple Git-66)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
  2016-11-29 18:56   ` Arnaldo Carvalho de Melo
@ 2016-11-29 18:58     ` David Ahern
  2016-11-29 19:21       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 19+ messages in thread
From: David Ahern @ 2016-11-29 18:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, David Ahern
  Cc: mingo, peterz, namhyung, jolsa, linux-kernel

On 11/29/16 11:56 AM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
>> Add option to allow user to control analysis window. e.g., collect data
>> for time window and analyze a segment of interest within that window.
> Trying to test this I got:
> 
> [root@jouet ~]# perf sched timehist
> No trace sample to read. Did you call 'perf record -R'?
> [root@jouet ~]#
> 
> Could you please provide a better error message?

sure, but that error is unrelated to this patch set.

> 
> The perf.data file had this:
> 
> [root@jouet ~]# perf evlist -v
> cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
> [root@jouet ~]# 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/6] perf: Add option to specify time window of interest
  2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
                   ` (5 preceding siblings ...)
  2016-11-29 17:15 ` [PATCH v2 6/6] perf report: " David Ahern
@ 2016-11-29 19:15 ` Arnaldo Carvalho de Melo
  2016-11-30  5:26   ` Namhyung Kim
  6 siblings, 1 reply; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-11-29 19:15 UTC (permalink / raw)
  To: David Ahern; +Cc: mingo, peterz, namhyung, jolsa, linux-kernel, David Ahern

Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
> This series allows users to collect data and analyze a time window of
> interest within the file.
> 
> v2
> - renamed perf_time to perf_time_interval
> - changed ../perf.h to perf.h in patch 1

Thanks, applied and pushed out to acme/perf/core.

- Arnaldo
 
> David Ahern (6):
>   perf tool: Add time-based utility functions
>   perf tool: Move parse_nsec_time to time-utils.c
>   perf script: Add option to specify time window of interest
>   perf sched timehist: Add option to specify time window of interest
>   perf kmem: Add option to specify time window of interest
>   perf report: Add option to specify time window of interest
> 
>  tools/perf/Documentation/perf-kmem.txt   |   7 ++
>  tools/perf/Documentation/perf-report.txt |   7 ++
>  tools/perf/Documentation/perf-sched.txt  |   8 +++
>  tools/perf/Documentation/perf-script.txt |   7 ++
>  tools/perf/builtin-kmem.c                |  24 +++++++
>  tools/perf/builtin-report.c              |  14 +++-
>  tools/perf/builtin-sched.c               |  51 +++++++++++--
>  tools/perf/builtin-script.c              |  15 +++-
>  tools/perf/util/Build                    |   1 +
>  tools/perf/util/time-utils.c             | 118 +++++++++++++++++++++++++++++++
>  tools/perf/util/time-utils.h             |  14 ++++
>  tools/perf/util/util.c                   |  33 ---------
>  tools/perf/util/util.h                   |   2 -
>  13 files changed, 258 insertions(+), 43 deletions(-)
>  create mode 100644 tools/perf/util/time-utils.c
>  create mode 100644 tools/perf/util/time-utils.h
> 
> -- 
> 2.7.4 (Apple Git-66)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest
  2016-11-29 18:58     ` David Ahern
@ 2016-11-29 19:21       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-11-29 19:21 UTC (permalink / raw)
  To: David Ahern
  Cc: Arnaldo Carvalho de Melo, David Ahern, mingo, peterz, namhyung,
	jolsa, linux-kernel

Em Tue, Nov 29, 2016 at 11:58:03AM -0700, David Ahern escreveu:
> On 11/29/16 11:56 AM, Arnaldo Carvalho de Melo wrote:
> > Em Tue, Nov 29, 2016 at 10:15:44AM -0700, David Ahern escreveu:
> >> Add option to allow user to control analysis window. e.g., collect data
> >> for time window and analyze a segment of interest within that window.
> > Trying to test this I got:
> > 
> > [root@jouet ~]# perf sched timehist
> > No trace sample to read. Did you call 'perf record -R'?
> > [root@jouet ~]#
> > 
> > Could you please provide a better error message?
> 
> sure, but that error is unrelated to this patch set.

I haven't said it was... 8-) This patchset is processed and pushed out,
just doing a 'make -C tools/perf build-test' + perf test + build on lots
of containers pass before sending a pull req to Ingo,

- Arnaldo
 
> > 
> > The perf.data file had this:
> > 
> > [root@jouet ~]# perf evlist -v
> > cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
> > [root@jouet ~]# 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/6] perf: Add option to specify time window of interest
  2016-11-29 19:15 ` [PATCH v2 0/6] perf: " Arnaldo Carvalho de Melo
@ 2016-11-30  5:26   ` Namhyung Kim
  2016-11-30 14:23     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 19+ messages in thread
From: Namhyung Kim @ 2016-11-30  5:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: David Ahern, mingo, peterz, jolsa, linux-kernel, David Ahern

Hi David and Arnaldo,

On 11/30/16, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
>> This series allows users to collect data and analyze a time window of
>> interest within the file.
>>
>> v2
>> - renamed perf_time to perf_time_interval
>> - changed ../perf.h to perf.h in patch 1
>
> Thanks, applied and pushed out to acme/perf/core.

If it's not too late:

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks
Namhyung


>> David Ahern (6):
>>   perf tool: Add time-based utility functions
>>   perf tool: Move parse_nsec_time to time-utils.c
>>   perf script: Add option to specify time window of interest
>>   perf sched timehist: Add option to specify time window of interest
>>   perf kmem: Add option to specify time window of interest
>>   perf report: Add option to specify time window of interest
>>
>>  tools/perf/Documentation/perf-kmem.txt   |   7 ++
>>  tools/perf/Documentation/perf-report.txt |   7 ++
>>  tools/perf/Documentation/perf-sched.txt  |   8 +++
>>  tools/perf/Documentation/perf-script.txt |   7 ++
>>  tools/perf/builtin-kmem.c                |  24 +++++++
>>  tools/perf/builtin-report.c              |  14 +++-
>>  tools/perf/builtin-sched.c               |  51 +++++++++++--
>>  tools/perf/builtin-script.c              |  15 +++-
>>  tools/perf/util/Build                    |   1 +
>>  tools/perf/util/time-utils.c             | 118
>> +++++++++++++++++++++++++++++++
>>  tools/perf/util/time-utils.h             |  14 ++++
>>  tools/perf/util/util.c                   |  33 ---------
>>  tools/perf/util/util.h                   |   2 -
>>  13 files changed, 258 insertions(+), 43 deletions(-)
>>  create mode 100644 tools/perf/util/time-utils.c
>>  create mode 100644 tools/perf/util/time-utils.h
>>
>> --
>> 2.7.4 (Apple Git-66)
>


-- 
Thanks,
Namhyung Kim

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/6] perf: Add option to specify time window of interest
  2016-11-30  5:26   ` Namhyung Kim
@ 2016-11-30 14:23     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-11-30 14:23 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: David Ahern, mingo, peterz, jolsa, linux-kernel, David Ahern

Em Wed, Nov 30, 2016 at 02:26:48PM +0900, Namhyung Kim escreveu:
> Hi David and Arnaldo,
> 
> On 11/30/16, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > Em Tue, Nov 29, 2016 at 10:15:40AM -0700, David Ahern escreveu:
> >> This series allows users to collect data and analyze a time window of
> >> interest within the file.
> >>
> >> v2
> >> - renamed perf_time to perf_time_interval
> >> - changed ../perf.h to perf.h in patch 1
> >
> > Thanks, applied and pushed out to acme/perf/core.
> 
> If it's not too late:
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, will add them, appreciated, as always!

- Arnaldo
 
> Thanks
> Namhyung
> 
> 
> >> David Ahern (6):
> >>   perf tool: Add time-based utility functions
> >>   perf tool: Move parse_nsec_time to time-utils.c
> >>   perf script: Add option to specify time window of interest
> >>   perf sched timehist: Add option to specify time window of interest
> >>   perf kmem: Add option to specify time window of interest
> >>   perf report: Add option to specify time window of interest
> >>
> >>  tools/perf/Documentation/perf-kmem.txt   |   7 ++
> >>  tools/perf/Documentation/perf-report.txt |   7 ++
> >>  tools/perf/Documentation/perf-sched.txt  |   8 +++
> >>  tools/perf/Documentation/perf-script.txt |   7 ++
> >>  tools/perf/builtin-kmem.c                |  24 +++++++
> >>  tools/perf/builtin-report.c              |  14 +++-
> >>  tools/perf/builtin-sched.c               |  51 +++++++++++--
> >>  tools/perf/builtin-script.c              |  15 +++-
> >>  tools/perf/util/Build                    |   1 +
> >>  tools/perf/util/time-utils.c             | 118
> >> +++++++++++++++++++++++++++++++
> >>  tools/perf/util/time-utils.h             |  14 ++++
> >>  tools/perf/util/util.c                   |  33 ---------
> >>  tools/perf/util/util.h                   |   2 -
> >>  13 files changed, 258 insertions(+), 43 deletions(-)
> >>  create mode 100644 tools/perf/util/time-utils.c
> >>  create mode 100644 tools/perf/util/time-utils.h
> >>
> >> --
> >> 2.7.4 (Apple Git-66)
> >
> 
> 
> -- 
> Thanks,
> Namhyung Kim

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tools: Add time-based utility functions
  2016-11-29 17:15 ` [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern
@ 2016-12-02 10:41   ` tip-bot for David Ahern
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, acme, peterz, hpa, namhyung, jolsa, dsa, mingo, tglx,
	linux-kernel

Commit-ID:  fdf9dc4b34f5f40919370c4601eccfd0db726aa5
Gitweb:     http://git.kernel.org/tip/fdf9dc4b34f5f40919370c4601eccfd0db726aa5
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:41 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:02:32 -0300

perf tools: Add time-based utility functions

Add function to parse a user time string of the form <start>,<stop>
where start and stop are time in sec.nsec format. Both start and stop
times are optional.

Add function to determine if a sample time is within a given time
time window of interest.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-2-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build        |  1 +
 tools/perf/util/time-utils.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/time-utils.h | 12 +++++++
 3 files changed, 98 insertions(+)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b2a47aa..bdad82a 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -87,6 +87,7 @@ libperf-y += help-unknown-cmd.o
 libperf-y += mem-events.o
 libperf-y += vsprintf.o
 libperf-y += drv_configs.o
+libperf-y += time-utils.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
new file mode 100644
index 0000000..0443b2a
--- /dev/null
+++ b/tools/perf/util/time-utils.c
@@ -0,0 +1,85 @@
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <inttypes.h>
+
+#include "perf.h"
+#include "debug.h"
+#include "time-utils.h"
+#include "util.h"
+
+static int parse_timestr_sec_nsec(struct perf_time_interval *ptime,
+				  char *start_str, char *end_str)
+{
+	if (start_str && (*start_str != '\0') &&
+	    (parse_nsec_time(start_str, &ptime->start) != 0)) {
+		return -1;
+	}
+
+	if (end_str && (*end_str != '\0') &&
+	    (parse_nsec_time(end_str, &ptime->end) != 0)) {
+		return -1;
+	}
+
+	return 0;
+}
+
+int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
+{
+	char *start_str, *end_str;
+	char *d, *str;
+	int rc = 0;
+
+	if (ostr == NULL || *ostr == '\0')
+		return 0;
+
+	/* copy original string because we need to modify it */
+	str = strdup(ostr);
+	if (str == NULL)
+		return -ENOMEM;
+
+	ptime->start = 0;
+	ptime->end = 0;
+
+	/* str has the format: <start>,<stop>
+	 * variations: <start>,
+	 *             ,<stop>
+	 *             ,
+	 */
+	start_str = str;
+	d = strchr(start_str, ',');
+	if (d) {
+		*d = '\0';
+		++d;
+	}
+	end_str = d;
+
+	rc = parse_timestr_sec_nsec(ptime, start_str, end_str);
+
+	free(str);
+
+	/* make sure end time is after start time if it was given */
+	if (rc == 0 && ptime->end && ptime->end < ptime->start)
+		return -EINVAL;
+
+	pr_debug("start time %" PRIu64 ", ", ptime->start);
+	pr_debug("end time %" PRIu64 "\n", ptime->end);
+
+	return rc;
+}
+
+bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp)
+{
+	/* if time is not set don't drop sample */
+	if (timestamp == 0)
+		return false;
+
+	/* otherwise compare sample time to time window */
+	if ((ptime->start && timestamp < ptime->start) ||
+	    (ptime->end && timestamp > ptime->end)) {
+		return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
new file mode 100644
index 0000000..8f3e0e3
--- /dev/null
+++ b/tools/perf/util/time-utils.h
@@ -0,0 +1,12 @@
+#ifndef _TIME_UTILS_H_
+#define _TIME_UTILS_H_
+
+struct perf_time_interval {
+	u64 start, end;
+};
+
+int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
+
+bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
+
+#endif

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf tools: Move parse_nsec_time to time-utils.c
  2016-11-29 17:15 ` [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern
@ 2016-12-02 10:41   ` tip-bot for David Ahern
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, tglx, peterz, acme, linux-kernel, hpa, mingo, dsa,
	jolsa, namhyung

Commit-ID:  c284d669a20d408b70ce0dc9b2d995971f5fe0c7
Gitweb:     http://git.kernel.org/tip/c284d669a20d408b70ce0dc9b2d995971f5fe0c7
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:42 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:02:39 -0300

perf tools: Move parse_nsec_time to time-utils.c

Code move only; no functional change intended.

Committer notes:

Fix the build on Ubuntu 16.04 x86-64 cross-compiling to S/390, with this
set of auto-detected features:

  ...                         dwarf: [ on  ]
  ...            dwarf_getlocations: [ on  ]
  ...                         glibc: [ on  ]
  ...                          gtk2: [ OFF ]
  ...                      libaudit: [ OFF ]
  ...                        libbfd: [ OFF ]
  ...                        libelf: [ on  ]
  ...                       libnuma: [ OFF ]
  ...        numa_num_possible_cpus: [ OFF ]
  ...                       libperl: [ OFF ]
  ...                     libpython: [ OFF ]
  ...                      libslang: [ OFF ]
  ...                     libcrypto: [ OFF ]
  ...                     libunwind: [ OFF ]
  ...            libdw-dwarf-unwind: [ on  ]
  ...                          zlib: [ on  ]
  ...                          lzma: [ OFF ]
  ...                     get_cpuid: [ OFF ]
  ...                           bpf: [ on  ]

Where it was failing with:

    CC       /tmp/build/perf/util/time-utils.o
  util/time-utils.c: In function 'parse_nsec_time':
  util/time-utils.c:17:13: error: implicit declaration of function 'strtoul' [-Werror=implicit-function-declaration]
    time_sec = strtoul(str, &end, 10);
               ^
  util/time-utils.c:17:2: error: nested extern declaration of 'strtoul' [-Werror=nested-externs]
    time_sec = strtoul(str, &end, 10);
    ^
  util/time-utils.c: In function 'perf_time__parse_str':
  util/time-utils.c:93:2: error: implicit declaration of function 'free' [-Werror=implicit-function-declaration]
    free(str);
    ^
  util/time-utils.c:93:2: error: incompatible implicit declaration of built-in function 'free' [-Werror]
  util/time-utils.c:93:2: note: include '<stdlib.h>' or provide a declaration of 'free'

Do as suggested and add a '#include <stdlib.h>' to get the free() and strtoul()
declarations and fix the build.

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-3-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/time-utils.c | 36 +++++++++++++++++++++++++++++++++++-
 tools/perf/util/time-utils.h |  2 ++
 tools/perf/util/util.c       | 33 ---------------------------------
 tools/perf/util/util.h       |  2 --
 4 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 0443b2a..d1b21c7 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -1,5 +1,7 @@
+#include <stdlib.h>
 #include <string.h>
 #include <sys/time.h>
+#include <linux/time64.h>
 #include <time.h>
 #include <errno.h>
 #include <inttypes.h>
@@ -7,7 +9,39 @@
 #include "perf.h"
 #include "debug.h"
 #include "time-utils.h"
-#include "util.h"
+
+int parse_nsec_time(const char *str, u64 *ptime)
+{
+	u64 time_sec, time_nsec;
+	char *end;
+
+	time_sec = strtoul(str, &end, 10);
+	if (*end != '.' && *end != '\0')
+		return -1;
+
+	if (*end == '.') {
+		int i;
+		char nsec_buf[10];
+
+		if (strlen(++end) > 9)
+			return -1;
+
+		strncpy(nsec_buf, end, 9);
+		nsec_buf[9] = '\0';
+
+		/* make it nsec precision */
+		for (i = strlen(nsec_buf); i < 9; i++)
+			nsec_buf[i] = '0';
+
+		time_nsec = strtoul(nsec_buf, &end, 10);
+		if (*end != '\0')
+			return -1;
+	} else
+		time_nsec = 0;
+
+	*ptime = time_sec * NSEC_PER_SEC + time_nsec;
+	return 0;
+}
 
 static int parse_timestr_sec_nsec(struct perf_time_interval *ptime,
 				  char *start_str, char *end_str)
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index 8f3e0e3..c1f197c 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -5,6 +5,8 @@ struct perf_time_interval {
 	u64 start, end;
 };
 
+int parse_nsec_time(const char *str, u64 *ptime);
+
 int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
 
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 67ac765..9ddd988 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -400,39 +400,6 @@ void sighandler_dump_stack(int sig)
 	raise(sig);
 }
 
-int parse_nsec_time(const char *str, u64 *ptime)
-{
-	u64 time_sec, time_nsec;
-	char *end;
-
-	time_sec = strtoul(str, &end, 10);
-	if (*end != '.' && *end != '\0')
-		return -1;
-
-	if (*end == '.') {
-		int i;
-		char nsec_buf[10];
-
-		if (strlen(++end) > 9)
-			return -1;
-
-		strncpy(nsec_buf, end, 9);
-		nsec_buf[9] = '\0';
-
-		/* make it nsec precision */
-		for (i = strlen(nsec_buf); i < 9; i++)
-			nsec_buf[i] = '0';
-
-		time_nsec = strtoul(nsec_buf, &end, 10);
-		if (*end != '\0')
-			return -1;
-	} else
-		time_nsec = 0;
-
-	*ptime = time_sec * NSEC_PER_SEC + time_nsec;
-	return 0;
-}
-
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
 	u64  sec = timestamp / NSEC_PER_SEC;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 79662d6..1d639e3 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -179,8 +179,6 @@ static inline void *zalloc(size_t size)
 #undef tolower
 #undef toupper
 
-int parse_nsec_time(const char *str, u64 *ptime);
-
 extern unsigned char sane_ctype[256];
 #define GIT_SPACE		0x01
 #define GIT_DIGIT		0x02

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf script: Add option to specify time window of interest
  2016-11-29 17:15 ` [PATCH v2 3/6] perf script: Add option to specify time window of interest David Ahern
@ 2016-12-02 10:42   ` tip-bot for David Ahern
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:42 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, peterz, dsahern, dsa, mingo, jolsa, acme, namhyung, hpa,
	linux-kernel

Commit-ID:  a91f4c473fa1655a2a5f1ceba46f76a95eef35bb
Gitweb:     http://git.kernel.org/tip/a91f4c473fa1655a2a5f1ceba46f76a95eef35bb
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:43 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:02:45 -0300

perf script: Add option to specify time window of interest

Add option to allow user to control analysis window. e.g., collect data
for some amount of time and analyze a segment of interest within that
window.

Committer notes:

Testing it:

  # perf evlist -v
  cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
  #
  # perf script --hide-call-graph | head -15
    swapper    0 [0] 9693.370039:      1 cycles:ppp: ffffffffb90072ad x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370044:      1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370046:      7 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370048:    126 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370049:   2701 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370051:  58823 cycles:ppp: ffffffffb90cd2e0 idle_cpu (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370059:      1 cycles:ppp: ffffffffb91a713a ctx_resched (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370062:      1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370064:     13 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370065:    250 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370067:   5269 cycles:ppp: ffffffffb902fe79 sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370069: 114602 cycles:ppp: ffffffffb90c1c5a atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
       perf 5124 [2] 9693.370076:      1 cycles:ppp: ffffffffb91a76c1 __perf_event_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
       perf 5124 [2] 9693.370091:      1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
       perf 5124 [2] 9693.370095:      3 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  #
  # perf script --hide-call-graph --time ,9693.370048
    swapper    0 [0] 9693.370039:      1 cycles:ppp: ffffffffb90072ad x86_pmu_enable (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370044:      1 cycles:ppp: ffffffffb900ca1b intel_pmu_handle_irq (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [0] 9693.370046:      7 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
  # perf script --hide-call-graph --time 9693.370064,9693.370076
    swapper    0 [1] 9693.370064:     13 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370065:    250 cycles:ppp: ffffffffb902fd93 native_sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370067:   5269 cycles:ppp: ffffffffb902fe79 sched_clock (.../4.8.8-300.fc25.x86_64/vmlinux)
    swapper    0 [1] 9693.370069: 114602 cycles:ppp: ffffffffb90c1c5a atomic_notifier_call_chain (.../4.8.8-300.fc25.x86_64/vmlinux)
  #

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-4-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt |  7 +++++++
 tools/perf/builtin-script.c              | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 0f6ee09..5dc5c6a 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -292,6 +292,13 @@ include::itrace.txt[]
 --force::
 	Don't do ownership validation.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 066b4bf..2f3ff69 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/thread-stack.h"
+#include "util/time-utils.h"
 #include <linux/bitmap.h>
 #include <linux/stringify.h>
 #include <linux/time64.h>
@@ -833,6 +834,8 @@ struct perf_script {
 	struct cpu_map		*cpus;
 	struct thread_map	*threads;
 	int			name_width;
+	const char              *time_str;
+	struct perf_time_interval ptime;
 };
 
 static int perf_evlist__max_name_len(struct perf_evlist *evlist)
@@ -1014,6 +1017,9 @@ static int process_sample_event(struct perf_tool *tool,
 	struct perf_script *scr = container_of(tool, struct perf_script, tool);
 	struct addr_location al;
 
+	if (perf_time__skip_sample(&scr->ptime, sample->time))
+		return 0;
+
 	if (debug_mode) {
 		if (sample->time < last_timestamp) {
 			pr_err("Samples misordered, previous: %" PRIu64
@@ -2186,7 +2192,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			"Enable symbol demangling"),
 	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
 			"Enable kernel symbol demangling"),
-
+	OPT_STRING(0, "time", &script.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char * const script_subcommands[] = { "record", "report", NULL };
@@ -2465,6 +2472,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (err < 0)
 		goto out_delete;
 
+	/* needs to be parsed after looking up reference time */
+	if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	err = __cmd_script(&script);
 
 	flush_scripting();

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf sched timehist: Add option to specify time window of interest
  2016-11-29 17:15 ` [PATCH v2 4/6] perf sched timehist: " David Ahern
  2016-11-29 18:56   ` Arnaldo Carvalho de Melo
@ 2016-12-02 10:42   ` tip-bot for David Ahern
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:42 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, namhyung, dsa, mingo, jolsa, dsahern, linux-kernel, acme,
	tglx, peterz

Commit-ID:  853b74071110bed344bad1ca9d8de27731b1c574
Gitweb:     http://git.kernel.org/tip/853b74071110bed344bad1ca9d8de27731b1c574
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:44 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:02:52 -0300

perf sched timehist: Add option to specify time window of interest

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Committer notes:

Testing it:

  # perf sched record -a usleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.593 MB perf.data (25 samples) ]
  #
  # perf sched timehist | head -18
  Samples do not have callchains.
          time    cpu   task name       wait time  sch delay  run time
                        [tid/pid]          (msec)     (msec)    (msec)
  ------------- ------  --------------- ---------  ---------  --------
   19818.635579 [0002]  <idle>              0.000      0.000     0.000
   19818.635613 [0000]  perf[9116]          0.000      0.000     0.000
   19818.635676 [0000]  <idle>              0.000      0.000     0.063
   19818.635678 [0000]  rcuos/2[29]         0.000      0.002     0.001
   19818.635696 [0002]  perf[9117]          0.000      0.004     0.116
   19818.635702 [0000]  <idle>              0.001      0.000     0.024
   19818.635709 [0002]  migration/2[25]     0.000      0.003     0.012
   19818.636263 [0000]  usleep[9117]        0.005      0.000     0.560
   19818.636316 [0000]  <idle>              0.560      0.000     0.053
   19818.636358 [0002]  <idle>              0.129      0.000     0.649
   19818.636358 [0000]  usleep[9117]        0.053      0.002     0.042
  #

  # perf sched timehist --time 19818.635696,
  Samples do not have callchains.
           time    cpu  task name       wait time  sch delay  run time
                        [tid/pid]          (msec)     (msec)    (msec)
  ------------- ------  ---------------  --------  --------- ---------
   19818.635696 [0002]  perf[9117]          0.000      0.120     0.000
   19818.635702 [0000]  <idle>              0.019      0.000     0.006
   19818.635709 [0002]  migration/2[25]     0.000      0.003     0.012
   19818.636263 [0000]  usleep[9117]        0.005      0.000     0.560
   19818.636316 [0000]  <idle>              0.560      0.000     0.053
   19818.636358 [0002]  <idle>              0.129      0.000     0.649
   19818.636358 [0000]  usleep[9117]        0.053      0.002     0.042
  #
  # perf sched timehist --time 19818.635696,19818.635709
  Samples do not have callchains.
           time    cpu  task name       wait time  sch delay  run time
                        [tid/pid]          (msec)     (msec)    (msec)
  ------------- ------  --------------- ---------  --------- ---------
   19818.635696 [0002]  perf[9117]          0.000      0.120     0.000
   19818.635702 [0000]  <idle>              0.019      0.000     0.006
   19818.635709 [0002]  migration/2[25]     0.000      0.003     0.012
   19818.635709 [0000]  usleep[9117]        0.005      0.000     0.006
  #

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-5-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  8 ++++++
 tools/perf/builtin-sched.c              | 51 +++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 121c60d..7775b1e 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -132,6 +132,14 @@ OPTIONS for 'perf sched timehist'
 --migrations::
 	Show migration events.
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 4f9e7cb..870d94c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -15,6 +15,7 @@
 #include "util/color.h"
 #include "util/stat.h"
 #include "util/callchain.h"
+#include "util/time-utils.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -205,6 +206,8 @@ struct perf_sched {
 	bool		show_wakeups;
 	bool		show_migrations;
 	u64		skipped_samples;
+	const char	*time_str;
+	struct perf_time_interval ptime;
 };
 
 /* per thread run time data */
@@ -1837,13 +1840,14 @@ static void timehist_header(struct perf_sched *sched)
 static void timehist_print_sample(struct perf_sched *sched,
 				  struct perf_sample *sample,
 				  struct addr_location *al,
-				  struct thread *thread)
+				  struct thread *thread,
+				  u64 t)
 {
 	struct thread_runtime *tr = thread__priv(thread);
 	u32 max_cpus = sched->max_cpu + 1;
 	char tstr[64];
 
-	timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr));
+	timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
 	printf("%15s [%04d] ", tstr, sample->cpu);
 
 	if (sched->show_cpu_visual) {
@@ -2194,7 +2198,8 @@ static int timehist_sched_wakeup_event(struct perf_tool *tool,
 		tr->ready_to_run = sample->time;
 
 	/* show wakeups if requested */
-	if (sched->show_wakeups)
+	if (sched->show_wakeups &&
+	    !perf_time__skip_sample(&sched->ptime, sample->time))
 		timehist_print_wakeup_event(sched, sample, machine, thread);
 
 	return 0;
@@ -2288,10 +2293,11 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 				       struct machine *machine)
 {
 	struct perf_sched *sched = container_of(tool, struct perf_sched, tool);
+	struct perf_time_interval *ptime = &sched->ptime;
 	struct addr_location al;
 	struct thread *thread;
 	struct thread_runtime *tr = NULL;
-	u64 tprev;
+	u64 tprev, t = sample->time;
 	int rc = 0;
 
 	if (machine__resolve(machine, &al, sample) < 0) {
@@ -2318,9 +2324,35 @@ static int timehist_sched_change_event(struct perf_tool *tool,
 
 	tprev = perf_evsel__get_time(evsel, sample->cpu);
 
-	timehist_update_runtime_stats(tr, sample->time, tprev);
+	/*
+	 * If start time given:
+	 * - sample time is under window user cares about - skip sample
+	 * - tprev is under window user cares about  - reset to start of window
+	 */
+	if (ptime->start && ptime->start > t)
+		goto out;
+
+	if (ptime->start > tprev)
+		tprev = ptime->start;
+
+	/*
+	 * If end time given:
+	 * - previous sched event is out of window - we are done
+	 * - sample time is beyond window user cares about - reset it
+	 *   to close out stats for time window interest
+	 */
+	if (ptime->end) {
+		if (tprev > ptime->end)
+			goto out;
+
+		if (t > ptime->end)
+			t = ptime->end;
+	}
+
+	timehist_update_runtime_stats(tr, t, tprev);
+
 	if (!sched->summary_only)
-		timehist_print_sample(sched, sample, &al, thread);
+		timehist_print_sample(sched, sample, &al, thread, t);
 
 out:
 	if (tr) {
@@ -2583,6 +2615,11 @@ static int perf_sched__timehist(struct perf_sched *sched)
 
 	symbol__init(&session->header.env);
 
+	if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	if (timehist_check_attr(sched, evlist) != 0)
 		goto out;
 
@@ -2997,6 +3034,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"),
 	OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"),
 	OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"),
+	OPT_STRING(0, "time", &sched.time_str, "str",
+		   "Time span for analysis (start,stop)"),
 	OPT_PARENT(sched_options)
 	};
 

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf kmem: Add option to specify time window of interest
  2016-11-29 17:15 ` [PATCH v2 5/6] perf kmem: " David Ahern
@ 2016-12-02 10:43   ` tip-bot for David Ahern
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, namhyung, jolsa, mingo, acme, linux-kernel, hpa, dsa,
	tglx, dsahern

Commit-ID:  2a865bd8dddd44315c88bf922761e4fd3374d046
Gitweb:     http://git.kernel.org/tip/2a865bd8dddd44315c88bf922761e4fd3374d046
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:45 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:03:02 -0300

perf kmem: Add option to specify time window of interest

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Committer notes:

Testing it:

  # perf kmem record usleep 1
  [ perf record: Woken up 0 times to write data ]
  [ perf record: Captured and wrote 1.540 MB perf.data (2049 samples) ]
  # perf evlist
  kmem:kmalloc
  kmem:kmalloc_node
  kmem:kfree
  kmem:kmem_cache_alloc
  kmem:kmem_cache_alloc_node
  kmem:kmem_cache_free
  # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events
  #
  # # Use 'perf script' to get a first approach, select a chunk for then using
  # # with 'perf kmem stat --time'
  #
  # perf script | tail -15
    usleep 9889 [0] 20119.782088:  kmem:kmem_cache_free: (selinux_file_free_security+0x27) call_site=ffffffffb936aa07 ptr=0xffff888a1df49fc0
      perf 9888 [3] 20119.782088:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
      perf 9888 [3] 20119.782089: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
      perf 9888 [3] 20119.782090:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
      perf 9888 [3] 20119.782090: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
    usleep 9889 [0] 20119.782091: kmem:kmem_cache_alloc: (__sigqueue_alloc+0x4a) call_site=ffffffffb90ad33a ptr=0xffff8889f071f6e0 bytes_req=160 bytes_alloc=160 gfp_flags=GFP_ATOMIC|__GFP_NOTRACK
      perf 9888 [3] 20119.782091:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
      perf 9888 [3] 20119.782093:  kmem:kmem_cache_free: (__sigqueue_free.part.17+0x33) call_site=ffffffffb90ad3f3 ptr=0xffff8889f071f6e0
      perf 9888 [3] 20119.782098: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
      perf 9888 [3] 20119.782098:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
      perf 9888 [3] 20119.782099: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
      perf 9888 [3] 20119.782100: kmem:kmem_cache_alloc: (alloc_buffer_head+0x21) call_site=ffffffffb9287cc1 ptr=0xffff8889b12722d8 bytes_req=104 bytes_alloc=104 gfp_flags=GFP_NOFS|__GFP_ZERO
      perf 9888 [3] 20119.782101:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
      perf 9888 [3] 20119.782102: kmem:kmem_cache_alloc: (jbd2__journal_start+0x72) call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
      perf 9888 [3] 20119.782103:  kmem:kmem_cache_free: (jbd2_journal_stop+0x1a1) call_site=ffffffffb9334581 ptr=0xffff888bdf1a39c0
  #
  # # stats for the whole perf.data file, i.e. no interval specified
  #
  # perf kmem stat

  SUMMARY (SLAB allocator)
  ========================
  Total bytes requested: 172,628
  Total bytes allocated: 173,088
  Total bytes freed:     161,280
  Net total bytes allocated: 11,808
  Total bytes wasted on internal fragmentation: 460
  Internal fragmentation: 0.265761%
  Cross CPU allocations: 0/851
  #
  # # stats for an end open interval, after a certain time:
  #
  # perf kmem stat --time 20119.782088,

  SUMMARY (SLAB allocator)
  ========================
  Total bytes requested: 552
  Total bytes allocated: 552
  Total bytes freed:     448
  Net total bytes allocated: 104
  Total bytes wasted on internal fragmentation: 0
  Internal fragmentation: 0.000000%
  Cross CPU allocations: 0/8
  #

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-6-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-kmem.txt |  7 +++++++
 tools/perf/builtin-kmem.c              | 24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt
index ff0f433..479fc32 100644
--- a/tools/perf/Documentation/perf-kmem.txt
+++ b/tools/perf/Documentation/perf-kmem.txt
@@ -61,6 +61,13 @@ OPTIONS
 	default, but this option shows live (currently allocated) pages
 	instead.  (This option works with --page option only)
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 7fd6f1e..35a02f8 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/callchain.h"
+#include "util/time-utils.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -66,6 +67,10 @@ static struct rb_root root_caller_sorted;
 static unsigned long total_requested, total_allocated, total_freed;
 static unsigned long nr_allocs, nr_cross_allocs;
 
+/* filters for controlling start and stop of time of analysis */
+static struct perf_time_interval ptime;
+const char *time_str;
+
 static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
 			     int bytes_req, int bytes_alloc, int cpu)
 {
@@ -912,6 +917,15 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel,
 	return 0;
 }
 
+static bool perf_kmem__skip_sample(struct perf_sample *sample)
+{
+	/* skip sample based on time? */
+	if (perf_time__skip_sample(&ptime, sample->time))
+		return true;
+
+	return false;
+}
+
 typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
 				  struct perf_sample *sample);
 
@@ -931,6 +945,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
+	if (perf_kmem__skip_sample(sample))
+		return 0;
+
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
 
 	if (evsel->handler != NULL) {
@@ -1894,6 +1911,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator",
 			   parse_page_opt),
 	OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"),
+	OPT_STRING(0, "time", &time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	const char *const kmem_subcommands[] = { "record", "stat", NULL };
@@ -1954,6 +1973,11 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	symbol__init(&session->header.env);
 
+	if (perf_time__parse_str(&ptime, time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	if (!strcmp(argv[0], "stat")) {
 		setlocale(LC_ALL, "");
 

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [tip:perf/core] perf report: Add option to specify time window of interest
  2016-11-29 17:15 ` [PATCH v2 6/6] perf report: " David Ahern
@ 2016-12-02 10:43   ` tip-bot for David Ahern
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot for David Ahern @ 2016-12-02 10:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, acme, hpa, dsahern, dsa, peterz, tglx, jolsa,
	linux-kernel, namhyung

Commit-ID:  46690a8051e4b5901a49080443a17a270e0bd8a2
Gitweb:     http://git.kernel.org/tip/46690a8051e4b5901a49080443a17a270e0bd8a2
Author:     David Ahern <dsa@cumulusnetworks.com>
AuthorDate: Tue, 29 Nov 2016 10:15:46 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 1 Dec 2016 13:03:10 -0300

perf report: Add option to specify time window of interest

Add option to allow user to control analysis window. e.g., collect data
for time window and analyze a segment of interest within that window.

Committer notes:

Testing it:

Using the perf.data file captured via 'perf kmem record':

  # perf report --header-only
  # ========
  # captured on: Tue Nov 29 16:01:53 2016
  # hostname : jouet
  # os release : 4.8.8-300.fc25.x86_64
  # perf version : 4.9.rc6.g5a6aca
  # arch : x86_64
  # nrcpus online : 4
  # nrcpus avail : 4
  # cpudesc : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
  # cpuid : GenuineIntel,6,61,4
  # total memory : 20254660 kB
  # cmdline : /home/acme/bin/perf kmem record usleep 1
  # event : name = kmem:kmalloc, , id = { 931980, 931981, 931982, 931983 }, type = 2, size = 112, config = 0x1b9, { sample_period, sample_freq } = 1, sample_typ
  # event : name = kmem:kmalloc_node, , id = { 931984, 931985, 931986, 931987 }, type = 2, size = 112, config = 0x1b7, { sample_period, sample_freq } = 1, sampl
  # event : name = kmem:kfree, , id = { 931988, 931989, 931990, 931991 }, type = 2, size = 112, config = 0x1b5, { sample_period, sample_freq } = 1, sample_type
  # event : name = kmem:kmem_cache_alloc, , id = { 931992, 931993, 931994, 931995 }, type = 2, size = 112, config = 0x1b8, { sample_period, sample_freq } = 1, s
  # event : name = kmem:kmem_cache_alloc_node, , id = { 931996, 931997, 931998, 931999 }, type = 2, size = 112, config = 0x1b6, { sample_period, sample_freq } =
  # event : name = kmem:kmem_cache_free, , id = { 932000, 932001, 932002, 932003 }, type = 2, size = 112, config = 0x1b4, { sample_period, sample_freq } = 1, sa
  # HEADER_CPU_TOPOLOGY info available, use -I to display
  # HEADER_NUMA_TOPOLOGY info available, use -I to display
  # pmu mappings: cpu = 4, intel_pt = 7, intel_bts = 6, uncore_arb = 13, cstate_pkg = 15, breakpoint = 5, uncore_cbox_1 = 12, power = 9, software = 1, uncore_im
  # HEADER_CACHE info available, use -I to display
  # missing features: HEADER_BRANCH_STACK HEADER_GROUP_DESC HEADER_AUXTRACE HEADER_STAT
  # ========
  #
  # # Looking at just the histogram entries for the first event:
  #
  # perf report  | head -33
  # To display the perf.data header info, please use --header/--header-only options.
  #
  #
  # Total Lost Samples: 0
  #
  # Samples: 40  of event 'kmem:kmalloc'
  # Event count (approx.): 40
  #
  # Overhead  Trace output
  # ........  ...............................................................................................................
  #
    37.50%  call_site=ffffffffb91ad3c7 ptr=0xffff88895fc05000 bytes_req=4096 bytes_alloc=4096 gfp_flags=GFP_KERNEL
    10.00%  call_site=ffffffffb9258416 ptr=0xffff888a1dc61f00 bytes_req=240 bytes_alloc=256 gfp_flags=GFP_KERNEL|__GFP_ZERO
     7.50%  call_site=ffffffffb9258416 ptr=0xffff888a2640ac00 bytes_req=240 bytes_alloc=256 gfp_flags=GFP_KERNEL|__GFP_ZERO
     2.50%  call_site=ffffffffb92759ba ptr=0xffff888a26776000 bytes_req=4096 bytes_alloc=4096 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb9276864 ptr=0xffff8886f6b82600 bytes_req=136 bytes_alloc=192 gfp_flags=GFP_KERNEL|__GFP_ZERO
     2.50%  call_site=ffffffffb9276903 ptr=0xffff888aefcf0460 bytes_req=32 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb92ad0ce ptr=0xffff888756c98a00 bytes_req=392 bytes_alloc=512 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb92ad0ce ptr=0xffff888756c9ba00 bytes_req=504 bytes_alloc=512 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb92ad301 ptr=0xffff888a31747600 bytes_req=128 bytes_alloc=128 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb92ad511 ptr=0xffff888a9d26a2a0 bytes_req=28 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c11a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c12c0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c1540 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c15a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c15e0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c16e0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff88873e8c1c20 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb936a7fb ptr=0xffff888a9d26a2a0 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL
     2.50%  call_site=ffffffffb9373e66 ptr=0xffff8889f1931240 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO
     2.50%  call_site=ffffffffb9373e66 ptr=0xffff8889f1931980 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO
     2.50%  call_site=ffffffffb9373e66 ptr=0xffff8889f1931a00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO

  #
  # # And then limiting using the example for 'perf kmem stat --time' used
  # # in the previous changeset committer note we see that there were no
  # # kmem:kmalloc in that last part of the file, but there were some
  # # kmem:kmem_cache_alloc ones:
  #
  # perf report --time 20119.782088, --stdio
  #
  # Total Lost Samples: 0
  #
  # Samples: 0  of event 'kmem:kmalloc'
  # Event count (approx.): 0
  #
  # Overhead  Trace output
  # ........  ............
  #

  # Samples: 0  of event 'kmem:kmalloc_node'
  # Event count (approx.): 0
  #
  # Overhead  Trace output
  # ........  ............
  #

  # Samples: 0  of event 'kmem:kfree'
  # Event count (approx.): 0
  #
  # Overhead  Trace output
  # ........  ............
  #

  # Samples: 8  of event 'kmem:kmem_cache_alloc'
  # Event count (approx.): 8
  #
  # Overhead  Trace output
  # ........  ..................................................................................................................
  #
    75.00%  call_site=ffffffffb9333b42 ptr=0xffff888bdf1a39c0 bytes_req=48 bytes_alloc=48 gfp_flags=GFP_NOFS|__GFP_ZERO
    12.50%  call_site=ffffffffb90ad33a ptr=0xffff8889f071f6e0 bytes_req=160 bytes_alloc=160 gfp_flags=GFP_ATOMIC|__GFP_NOTRACK
    12.50%  call_site=ffffffffb9287cc1 ptr=0xffff8889b12722d8 bytes_req=104 bytes_alloc=104 gfp_flags=GFP_NOFS|__GFP_ZERO
  #

Signed-off-by: David Ahern <dsahern@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1480439746-42695-7-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt |  7 +++++++
 tools/perf/builtin-report.c              | 14 +++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 2d17462..3a166ae 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -382,6 +382,13 @@ OPTIONS
 --header-only::
 	Show only perf.data header (forces --stdio).
 
+--time::
+	Only analyze samples within given time window: <start>,<stop>. Times
+	have the format seconds.microseconds. If start is not given (i.e., time
+	string is ',x.y') then analysis starts at the beginning of the file. If
+	stop time is not given (i.e, time string is 'x.y,') then analysis goes
+	to end of file.
+
 --itrace::
 	Options for decoding instruction tracing data. The options are:
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3dfbfff..d2afbe4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -36,7 +36,7 @@
 #include "util/hist.h"
 #include "util/data.h"
 #include "arch/common.h"
-
+#include "util/time-utils.h"
 #include "util/auxtrace.h"
 
 #include <dlfcn.h>
@@ -59,6 +59,8 @@ struct report {
 	const char		*pretty_printing_style;
 	const char		*cpu_list;
 	const char		*symbol_filter_str;
+	const char		*time_str;
+	struct perf_time_interval ptime;
 	float			min_percent;
 	u64			nr_entries;
 	u64			queue_size;
@@ -158,6 +160,9 @@ static int process_sample_event(struct perf_tool *tool,
 	};
 	int ret = 0;
 
+	if (perf_time__skip_sample(&rep->ptime, sample->time))
+		return 0;
+
 	if (machine__resolve(machine, &al, sample) < 0) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -830,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
 			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
 			     stdio__config_color, "always"),
+	OPT_STRING(0, "time", &report.time_str, "str",
+		   "Time span of interest (start,stop)"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
@@ -1015,6 +1022,11 @@ repeat:
 	if (symbol__init(&session->header.env) < 0)
 		goto error;
 
+	if (perf_time__parse_str(&report.ptime, report.time_str) != 0) {
+		pr_err("Invalid time string\n");
+		return -EINVAL;
+	}
+
 	sort__setup_elide(stdout);
 
 	ret = __cmd_report(&report);

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2016-12-02 10:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29 17:15 [PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern
2016-11-29 17:15 ` [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern
2016-12-02 10:41   ` [tip:perf/core] perf tools: " tip-bot for David Ahern
2016-11-29 17:15 ` [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern
2016-12-02 10:41   ` [tip:perf/core] perf tools: " tip-bot for David Ahern
2016-11-29 17:15 ` [PATCH v2 3/6] perf script: Add option to specify time window of interest David Ahern
2016-12-02 10:42   ` [tip:perf/core] " tip-bot for David Ahern
2016-11-29 17:15 ` [PATCH v2 4/6] perf sched timehist: " David Ahern
2016-11-29 18:56   ` Arnaldo Carvalho de Melo
2016-11-29 18:58     ` David Ahern
2016-11-29 19:21       ` Arnaldo Carvalho de Melo
2016-12-02 10:42   ` [tip:perf/core] " tip-bot for David Ahern
2016-11-29 17:15 ` [PATCH v2 5/6] perf kmem: " David Ahern
2016-12-02 10:43   ` [tip:perf/core] " tip-bot for David Ahern
2016-11-29 17:15 ` [PATCH v2 6/6] perf report: " David Ahern
2016-12-02 10:43   ` [tip:perf/core] " tip-bot for David Ahern
2016-11-29 19:15 ` [PATCH v2 0/6] perf: " Arnaldo Carvalho de Melo
2016-11-30  5:26   ` Namhyung Kim
2016-11-30 14:23     ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.