Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1532564

[PATCH v2 5/6] perf kmem: Add option to specify time window of interest

From David Ahern <dsa@cumulusnetworks.com>
Newsgroups linux.kernel
Subject [PATCH v2 5/6] perf kmem: Add option to specify time window of interest
Date 2016-11-29 18:20 +0100
Message-ID <sIUeu-2Xs-55@gated-at.bofh.it> (permalink)
References <sIUeu-2Xs-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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)

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/6] perf: Add option to specify time window of interest David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
  [PATCH v2 6/6] perf report: Add option to specify time window of interest David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
    [tip:perf/core] perf report: Add option to specify time window of  interest tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  [PATCH v2 5/6] perf kmem: Add option to specify time window of interest David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
    [tip:perf/core] perf kmem: Add option to specify time window of  interest tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  [PATCH v2 4/6] perf sched timehist: Add option to specify time window of interest David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
    Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time  window of interest Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-11-29 20:00 +0100
      Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time  window of interest David Ahern <dsahern@gmail.com> - 2016-11-29 20:00 +0100
        Re: [PATCH v2 4/6] perf sched timehist: Add option to specify time  window of interest Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-11-29 20:30 +0100
    [tip:perf/core] perf sched timehist: Add option to specify time  window of interest tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  [PATCH v2 3/6] perf script: Add option to specify time window of interest David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
    [tip:perf/core] perf script: Add option to specify time window of  interest tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  [PATCH v2 2/6] perf tool: Move parse_nsec_time to time-utils.c David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:20 +0100
    [tip:perf/core] perf tools: Move parse_nsec_time to time-utils.c tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  [PATCH v2 1/6] perf tool: Add time-based utility functions David Ahern <dsa@cumulusnetworks.com> - 2016-11-29 18:30 +0100
    [tip:perf/core] perf tools: Add time-based utility functions tip-bot for David Ahern <tipbot@zytor.com> - 2016-12-02 11:50 +0100
  Re: [PATCH v2 0/6] perf: Add option to specify time window of  interest Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-11-29 20:20 +0100
    Re: [PATCH v2 0/6] perf: Add option to specify time window of interest Namhyung Kim <namhyung@kernel.org> - 2016-11-30 06:30 +0100
      Re: [PATCH v2 0/6] perf: Add option to specify time window of  interest Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-11-30 15:30 +0100

csiph-web