linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 03/26] perf map: Move comparision of map's dso_id to a separate function
Date: Fri, 22 Nov 2019 11:56:48 -0300	[thread overview]
Message-ID: <20191122145711.3171-4-acme@kernel.org> (raw)
In-Reply-To: <20191122145711.3171-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

We'll use it when doing DSO lookups using dso_ids.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-u2nr1oq03o0i29w2ay9jx03s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/dsos.c | 25 +++++++++++++++++++++++++
 tools/perf/util/map.h  |  2 ++
 tools/perf/util/sort.c | 16 ++++------------
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c
index 3ea80d203587..ecf8d7346685 100644
--- a/tools/perf/util/dsos.c
+++ b/tools/perf/util/dsos.c
@@ -2,6 +2,7 @@
 #include "debug.h"
 #include "dsos.h"
 #include "dso.h"
+#include "map.h"
 #include "vdso.h"
 #include "namespaces.h"
 #include <libgen.h>
@@ -9,6 +10,30 @@
 #include <string.h>
 #include <symbol.h> // filename__read_build_id
 
+int dso_id__cmp(struct dso_id *a, struct dso_id *b)
+{
+	/*
+	 * The second is always dso->id, so zeroes if not set, assume passing
+	 * NULL for a means a zeroed id
+	 */
+	if (a == NULL)
+		return 0;
+
+	if (a->maj > b->maj) return -1;
+	if (a->maj < b->maj) return 1;
+
+	if (a->min > b->min) return -1;
+	if (a->min < b->min) return 1;
+
+	if (a->ino > b->ino) return -1;
+	if (a->ino < b->ino) return 1;
+
+	if (a->ino_generation > b->ino_generation) return -1;
+	if (a->ino_generation < b->ino_generation) return 1;
+
+	return 0;
+}
+
 bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
 {
 	bool have_build_id = false;
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index f962eb9035c7..e1e573a28a55 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -28,6 +28,8 @@ struct dso_id {
 	u64	ino_generation;
 };
 
+int dso_id__cmp(struct dso_id *a, struct dso_id *b);
+
 struct map {
 	union {
 		struct rb_node	rb_node;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index bc589438cd12..f1481002fafb 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1194,6 +1194,7 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 {
 	u64 l, r;
 	struct map *l_map, *r_map;
+	int rc;
 
 	if (!left->mem_info)  return -1;
 	if (!right->mem_info) return 1;
@@ -1212,18 +1213,9 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)
 	if (!l_map) return -1;
 	if (!r_map) return 1;
 
-	if (l_map->dso_id.maj > r_map->dso_id.maj) return -1;
-	if (l_map->dso_id.maj < r_map->dso_id.maj) return 1;
-
-	if (l_map->dso_id.min > r_map->dso_id.min) return -1;
-	if (l_map->dso_id.min < r_map->dso_id.min) return 1;
-
-	if (l_map->dso_id.ino > r_map->dso_id.ino) return -1;
-	if (l_map->dso_id.ino < r_map->dso_id.ino) return 1;
-
-	if (l_map->dso_id.ino_generation > r_map->dso_id.ino_generation) return -1;
-	if (l_map->dso_id.ino_generation < r_map->dso_id.ino_generation) return 1;
-
+	rc = dso_id__cmp(&l_map->dso_id, &r_map->dso_id);
+	if (rc)
+		return rc;
 	/*
 	 * Addresses with no major/minor numbers are assumed to be
 	 * anonymous in userspace.  Sort those on pid then address.
-- 
2.21.0

  parent reply	other threads:[~2019-11-22 14:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 14:56 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 01/26] perf map: Move maj/min/ino/ino_generation to separate struct Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 02/26] perf map: Pass a dso_id to map__new() Arnaldo Carvalho de Melo
2019-11-22 14:56 ` Arnaldo Carvalho de Melo [this message]
2019-11-22 14:56 ` [PATCH 04/26] perf dsos: Remove unused dsos__find() method Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 05/26] perf dso: Move dso_id from 'struct map' to 'struct dso' Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 06/26] perf session: Fix decompression of PERF_RECORD_COMPRESSED records Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 07/26] perf util: Move block TUI function to ui browsers Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 08/26] perf report: Jump to symbol source view from total cycles view Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 09/26] perf tools: Add kernel AUX area sampling definitions Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 10/26] perf record: Add a function to test for kernel support for AUX area sampling Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 11/26] perf auxtrace: Move perf_evsel__find_pmu() Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 12/26] perf auxtrace: Add support for AUX area sample recording Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 13/26] perf record: Add support for AUX area sampling Arnaldo Carvalho de Melo
2019-11-22 14:56 ` [PATCH 14/26] perf record: Add aux-sample-size config term Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 15/26] perf inject: Cut AUX area samples Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 16/26] perf auxtrace: Add support for dumping " Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 17/26] perf session: Add facility to peek at all events Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 18/26] perf auxtrace: Add support for queuing AUX area samples Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 19/26] perf pmu: When using default config, record which bits of config were changed by the user Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 20/26] perf intel-pt: Add support for recording AUX area samples Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 21/26] perf intel-pt: Add support for decoding " Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 22/26] perf intel-bts: Does not support AUX area sampling Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 23/26] libtraceevent: Fix header installation Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 24/26] libtraceevent: Fix memory leakage in copy_filter_type Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 25/26] perf probe: Fix spelling mistake "addrees" -> "address" Arnaldo Carvalho de Melo
2019-11-22 14:57 ` [PATCH 26/26] perf parse: Fix potential memory leak when handling tracepoint errors Arnaldo Carvalho de Melo
2019-11-23  8:07 ` [GIT PULL] 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=20191122145711.3171-4-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.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).