linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1] perf record: Correct address filters for duplicated symbols
@ 2023-01-06 20:37 Dmitrii Dolgov
  2023-01-09  7:02 ` Adrian Hunter
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitrii Dolgov @ 2023-01-06 20:37 UTC (permalink / raw)
  To: linux-perf-users
  Cc: acme, mingo, jolsa, irogers, adrian.hunter, Dmitrii Dolgov

It seems the logic to handle duplicated symbols is off. In case if the
symbol index is specified it will:

* find a match
* continue searching
* check that start is not null and idx is set on the next loop
* exit with the error code 1

My guess is the expectation was that at this point the second match is
found (because *start is not null), although the new symbol hasn't pass
dso_sym_match yet. Here is how it looks like:

    $ readelf -a postgres | grep simple_heap_update
        4716: 00000000004e23e5   352 FUNC    GLOBAL DEFAULT   13 simple_heap_update
        27829: 00000000004e23e5   352 FUNC    GLOBAL DEFAULT   13 simple_heap_update

    $ perf record -p <pid> -e intel_pt// \
        --filter 'filter simple_heap_update #1 @ postgres' -- sleep 60

        Failed to parse address filter: 'filter simple_heap_update #1 @ postgres'
        Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
        Where multiple filters are separated by space or comma.

Correct by returning error only after checking whether the symbol is
matching or not. After modifications the case above seems to be working
as expected:

    $ perf record -p <pid> -e intel_pt// \
        --filter 'filter simple_heap_update #1 @ postgres' -- sleep 60

    # update heap a couple of times

    $ perf script --itrace=c

        branches: 4e23fe simple_heap_update+0x19 => 54829c GetCurrentCommandId+0x0
        # [...]
        branches: 4e23fe simple_heap_update+0x19 => 54829c GetCurrentCommandId+0x0
        # [...]

Signed-off-by: Dmitrii Dolgov <9erthalion6@gmail.com>
---
 tools/perf/util/auxtrace.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index b59c278fe9ed..112cef56d6c2 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -2593,15 +2593,23 @@ static int find_dso_sym(struct dso *dso, const char *sym_name, u64 *start,
 
 	sym = dso__first_symbol(dso);
 	while (sym) {
+		/* Verify duplicates if one match was already found */
 		if (*start) {
 			if (!*size)
 				*size = sym->start - *start;
-			if (idx > 0) {
-				if (*size)
-					return 1;
-			} else if (dso_sym_match(sym, sym_name, &cnt, idx)) {
-				print_duplicate_syms(dso, sym_name);
-				return -EINVAL;
+
+			if (dso_sym_match(sym, sym_name, &cnt, idx)) {
+				if (idx > 0) {
+					/*
+					 * There is already one match with the specified index, now
+					 * we found the second one, something is wrong.
+					 */
+					if (*size)
+						return 1;
+				} else {
+					print_duplicate_syms(dso, sym_name);
+					return -EINVAL;
+				}
 			}
 		} else if (dso_sym_match(sym, sym_name, &cnt, idx)) {
 			*start = sym->start;
-- 
2.31.1


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

end of thread, other threads:[~2023-01-11 13:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-06 20:37 [RFC PATCH v1] perf record: Correct address filters for duplicated symbols Dmitrii Dolgov
2023-01-09  7:02 ` Adrian Hunter
2023-01-10 10:48   ` Dmitry Dolgov
2023-01-11 13:17     ` Arnaldo Carvalho de Melo
2023-01-11 13:34       ` Dmitry Dolgov

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).