From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
Andi Kleen <andi@firstfloor.org>, David Ahern <dsahern@gmail.com>,
Jiri Olsa <jolsa@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>,
Wang Nan <wangnan0@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 18/31] perf hists: Introduce hist_entry__filter()
Date: Wed, 24 Feb 2016 22:58:13 -0300 [thread overview]
Message-ID: <1456365506-5492-19-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1456365506-5492-1-git-send-email-acme@kernel.org>
From: Namhyung Kim <namhyung@kernel.org>
The hist_entry__filter() function is to filter hist entries using sort
key related info. This is needed to support hierarchy mode since each
hist entry will be associated with a hpp fmt which has a sort key. So
each entry should compare to only matching type of filters.
To do that, add the ->se_filter callback field to struct sort_entry.
This callback takes 'type' argument which determines whether it's
matching sort key or not. It returns -1 for non-matching type, 0 for
filtered entry and 1 for not filtered entries.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1456326830-30456-6-git-send-email-namhyung@kernel.org
[ 'socket' is reserved in sys/socket.h, so replace it with 'sk' ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/hist.h | 2 +
tools/perf/util/sort.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/sort.h | 1 +
3 files changed, 116 insertions(+)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 5690906c154c..480d2eb26001 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -305,6 +305,8 @@ bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt);
bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt);
bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt);
+int hist_entry__filter(struct hist_entry *he, int type, const void *arg);
+
static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format,
struct hists *hists)
{
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 358035c2c327..6bee8bdfb91b 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -90,10 +90,21 @@ static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf,
width, width, comm ?: "");
}
+static int hist_entry__thread_filter(struct hist_entry *he, int type, const void *arg)
+{
+ const struct thread *th = arg;
+
+ if (type != HIST_FILTER__THREAD)
+ return -1;
+
+ return th && he->thread != th;
+}
+
struct sort_entry sort_thread = {
.se_header = " Pid:Command",
.se_cmp = sort__thread_cmp,
.se_snprintf = hist_entry__thread_snprintf,
+ .se_filter = hist_entry__thread_filter,
.se_width_idx = HISTC_THREAD,
};
@@ -131,6 +142,7 @@ struct sort_entry sort_comm = {
.se_collapse = sort__comm_collapse,
.se_sort = sort__comm_sort,
.se_snprintf = hist_entry__comm_snprintf,
+ .se_filter = hist_entry__thread_filter,
.se_width_idx = HISTC_COMM,
};
@@ -180,10 +192,21 @@ static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf,
return _hist_entry__dso_snprintf(he->ms.map, bf, size, width);
}
+static int hist_entry__dso_filter(struct hist_entry *he, int type, const void *arg)
+{
+ const struct dso *dso = arg;
+
+ if (type != HIST_FILTER__DSO)
+ return -1;
+
+ return dso && (!he->ms.map || he->ms.map->dso != dso);
+}
+
struct sort_entry sort_dso = {
.se_header = "Shared Object",
.se_cmp = sort__dso_cmp,
.se_snprintf = hist_entry__dso_snprintf,
+ .se_filter = hist_entry__dso_filter,
.se_width_idx = HISTC_DSO,
};
@@ -277,11 +300,22 @@ static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf,
he->level, bf, size, width);
}
+static int hist_entry__sym_filter(struct hist_entry *he, int type, const void *arg)
+{
+ const char *sym = arg;
+
+ if (type != HIST_FILTER__SYMBOL)
+ return -1;
+
+ return sym && (!he->ms.sym || !strstr(he->ms.sym->name, sym));
+}
+
struct sort_entry sort_sym = {
.se_header = "Symbol",
.se_cmp = sort__sym_cmp,
.se_sort = sort__sym_sort,
.se_snprintf = hist_entry__sym_snprintf,
+ .se_filter = hist_entry__sym_filter,
.se_width_idx = HISTC_SYMBOL,
};
@@ -440,10 +474,21 @@ static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket);
}
+static int hist_entry__socket_filter(struct hist_entry *he, int type, const void *arg)
+{
+ int sk = *(const int *)arg;
+
+ if (type != HIST_FILTER__SOCKET)
+ return -1;
+
+ return sk >= 0 && he->socket != sk;
+}
+
struct sort_entry sort_socket = {
.se_header = "Socket",
.se_cmp = sort__socket_cmp,
.se_snprintf = hist_entry__socket_snprintf,
+ .se_filter = hist_entry__socket_filter,
.se_width_idx = HISTC_SOCKET,
};
@@ -530,6 +575,18 @@ static int hist_entry__dso_from_snprintf(struct hist_entry *he, char *bf,
return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A");
}
+static int hist_entry__dso_from_filter(struct hist_entry *he, int type,
+ const void *arg)
+{
+ const struct dso *dso = arg;
+
+ if (type != HIST_FILTER__DSO)
+ return -1;
+
+ return dso && (!he->branch_info || !he->branch_info->from.map ||
+ he->branch_info->from.map->dso != dso);
+}
+
static int64_t
sort__dso_to_cmp(struct hist_entry *left, struct hist_entry *right)
{
@@ -550,6 +607,18 @@ static int hist_entry__dso_to_snprintf(struct hist_entry *he, char *bf,
return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A");
}
+static int hist_entry__dso_to_filter(struct hist_entry *he, int type,
+ const void *arg)
+{
+ const struct dso *dso = arg;
+
+ if (type != HIST_FILTER__DSO)
+ return -1;
+
+ return dso && (!he->branch_info || !he->branch_info->to.map ||
+ he->branch_info->to.map->dso != dso);
+}
+
static int64_t
sort__sym_from_cmp(struct hist_entry *left, struct hist_entry *right)
{
@@ -611,10 +680,35 @@ static int hist_entry__sym_to_snprintf(struct hist_entry *he, char *bf,
return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A");
}
+static int hist_entry__sym_from_filter(struct hist_entry *he, int type,
+ const void *arg)
+{
+ const char *sym = arg;
+
+ if (type != HIST_FILTER__SYMBOL)
+ return -1;
+
+ return sym && !(he->branch_info && he->branch_info->from.sym &&
+ strstr(he->branch_info->from.sym->name, sym));
+}
+
+static int hist_entry__sym_to_filter(struct hist_entry *he, int type,
+ const void *arg)
+{
+ const char *sym = arg;
+
+ if (type != HIST_FILTER__SYMBOL)
+ return -1;
+
+ return sym && !(he->branch_info && he->branch_info->to.sym &&
+ strstr(he->branch_info->to.sym->name, sym));
+}
+
struct sort_entry sort_dso_from = {
.se_header = "Source Shared Object",
.se_cmp = sort__dso_from_cmp,
.se_snprintf = hist_entry__dso_from_snprintf,
+ .se_filter = hist_entry__dso_from_filter,
.se_width_idx = HISTC_DSO_FROM,
};
@@ -622,6 +716,7 @@ struct sort_entry sort_dso_to = {
.se_header = "Target Shared Object",
.se_cmp = sort__dso_to_cmp,
.se_snprintf = hist_entry__dso_to_snprintf,
+ .se_filter = hist_entry__dso_to_filter,
.se_width_idx = HISTC_DSO_TO,
};
@@ -629,6 +724,7 @@ struct sort_entry sort_sym_from = {
.se_header = "Source Symbol",
.se_cmp = sort__sym_from_cmp,
.se_snprintf = hist_entry__sym_from_snprintf,
+ .se_filter = hist_entry__sym_from_filter,
.se_width_idx = HISTC_SYMBOL_FROM,
};
@@ -636,6 +732,7 @@ struct sort_entry sort_sym_to = {
.se_header = "Target Symbol",
.se_cmp = sort__sym_to_cmp,
.se_snprintf = hist_entry__sym_to_snprintf,
+ .se_filter = hist_entry__sym_to_filter,
.se_width_idx = HISTC_SYMBOL_TO,
};
@@ -1498,6 +1595,22 @@ static struct perf_hpp_fmt *__hpp_dimension__alloc_hpp(struct hpp_dimension *hd)
return fmt;
}
+int hist_entry__filter(struct hist_entry *he, int type, const void *arg)
+{
+ struct perf_hpp_fmt *fmt;
+ struct hpp_sort_entry *hse;
+
+ fmt = he->fmt;
+ if (fmt == NULL || !perf_hpp__is_sort_entry(fmt))
+ return -1;
+
+ hse = container_of(fmt, struct hpp_sort_entry, hpp);
+ if (hse->se->se_filter == NULL)
+ return -1;
+
+ return hse->se->se_filter(he, type, arg);
+}
+
static int __sort_dimension__add_hpp_sort(struct sort_dimension *sd)
{
struct hpp_sort_entry *hse = __sort_dimension__alloc_hpp(sd);
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 10315e02adf5..a8d53ffe0916 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -245,6 +245,7 @@ struct sort_entry {
int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
unsigned int width);
+ int (*se_filter)(struct hist_entry *he, int type, const void *arg);
u8 se_width_idx;
};
--
2.5.0
next prev parent reply other threads:[~2016-02-25 1:58 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-25 1:57 [GIT PULL 00/31] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-02-25 1:57 ` [PATCH 01/31] perf mem record: Check for memory events support Arnaldo Carvalho de Melo
2016-02-25 1:57 ` [PATCH 02/31] perf mem: Introduce perf_mem_events__name function Arnaldo Carvalho de Melo
2016-02-25 1:57 ` [PATCH 03/31] perf tools: Introduce perf_mem__tlb_scnprintf function Arnaldo Carvalho de Melo
2016-02-25 1:57 ` [PATCH 04/31] perf tools: Introduce perf_mem__lvl_scnprintf function Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 05/31] perf tools: Introduce perf_mem__snp_scnprintf function Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 06/31] perf tools: Introduce perf_mem__lck_scnprintf function Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 07/31] perf tools: Change perf_mem__tlb_scnprintf to return nb of displayed bytes Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 08/31] perf tools: Change perf_mem__lvl_scnprintf " Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 09/31] perf tools: Change perf_mem__snp_scnprintf " Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 10/31] perf tools: Change perf_mem__lck_scnprintf " Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 11/31] perf script: Display data_src values Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 12/31] perf tools: Make binary data printer code in trace_event public available Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 13/31] perf script: Print bpf-output events in 'perf script' Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 14/31] perf tools: Add helper functions for some sort keys Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 15/31] perf hists: Basic support of hierarchical report view Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 16/31] perf hists: Resort hist entries with hierarchy Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 17/31] perf hists: Add helper functions for hierarchy mode Arnaldo Carvalho de Melo
2016-02-25 1:58 ` Arnaldo Carvalho de Melo [this message]
2016-02-25 1:58 ` [PATCH 19/31] perf hists: Support filtering in " Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 20/31] perf hists: Resort after filtering hierarchy Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 21/31] perf hists: Count number of sort keys Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 22/31] perf ui/stdio: Implement hierarchy output mode Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 23/31] perf ui/stdio: Align column header for hierarchy output Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 24/31] perf hists browser: Count number of hierarchy entries Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 25/31] perf hists browser: Support collapsing/expanding whole entries in hierarchy Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 26/31] perf hists browser: Implement hierarchy output Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 27/31] perf hists browser: Align column header in hierarchy mode Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 28/31] perf ui/gtk: Implement hierarchy output mode Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 29/31] perf report: Add --hierarchy option Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 30/31] perf hists: Support decaying in hierarchy mode Arnaldo Carvalho de Melo
2016-02-25 1:58 ` [PATCH 31/31] perf top: Add --hierarchy option Arnaldo Carvalho de Melo
2016-02-25 7:22 ` [GIT PULL 00/31] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456365506-5492-19-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).