All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Borislav Petkov <bp@suse.de>,
	Hemant Kumar <hemant@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 05/19] perf buildid-cache: Add new buildid cache if update target is not cached
Date: Fri, 27 Feb 2015 16:22:55 -0300	[thread overview]
Message-ID: <1425064989-26440-6-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1425064989-26440-1-git-send-email-acme@kernel.org>

From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Add new buildid cache if the update target file is not cached.

This can happen when an old binary is replaced by new one after caching
the old one. In this case, user sees his operation just failed.

But it does not look straight, since user just pass the binary "path",
not "build-id".

  ----
  # ./perf buildid-cache --add ./perf
  (update ./perf to new binary)
  # ./perf buildid-cache --update ./perf
  ./perf wasn't in the cache
  #
  ----

This patch adds given new binary to cache if the new binary is
not cached. So we'll not see the above error.

  ----
  # ./perf buildid-cache --add ./perf
  (update ./perf to new binary)
  # ./perf buildid-cache --update ./perf
  #
  ----

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20150226065440.23912.1494.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-buildid-cache.txt | 11 ++++++++---
 tools/perf/builtin-buildid-cache.c              |  6 ++++--
 tools/perf/util/build-id.c                      | 12 ++++++++++++
 tools/perf/util/build-id.h                      |  1 +
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
index 0294c57b1f5e..cec6b57e8be6 100644
--- a/tools/perf/Documentation/perf-buildid-cache.txt
+++ b/tools/perf/Documentation/perf-buildid-cache.txt
@@ -41,9 +41,14 @@ OPTIONS
 --missing=::
 	List missing build ids in the cache for the specified file.
 -u::
---update::
-	Update specified file of the cache. It can be used to update kallsyms
-	kernel dso to vmlinux in order to support annotation.
+--update=::
+	Update specified file of the cache. Note that this doesn't remove
+	older entires since those may be still needed for annotating old
+	(or remote) perf.data. Only if there is already a cache which has
+	exactly same build-id, that is replaced by new one. It can be used
+	to update kallsyms and kernel dso to vmlinux in order to support
+	annotation.
+
 -v::
 --verbose::
 	Be more verbose.
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index d929d9544664..e7568f5844ad 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -255,7 +255,7 @@ static int build_id_cache__update_file(const char *filename)
 	u8 build_id[BUILD_ID_SIZE];
 	char sbuild_id[BUILD_ID_SIZE * 2 + 1];
 
-	int err;
+	int err = 0;
 
 	if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) {
 		pr_debug("Couldn't read a build-id in %s\n", filename);
@@ -263,7 +263,9 @@ static int build_id_cache__update_file(const char *filename)
 	}
 
 	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
-	err = build_id_cache__remove_s(sbuild_id);
+	if (build_id_cache__cached(sbuild_id))
+		err = build_id_cache__remove_s(sbuild_id);
+
 	if (!err)
 		err = build_id_cache__add_s(sbuild_id, filename, false, false);
 
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index adbc36028636..0bc33be5a78c 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -352,6 +352,18 @@ static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
 	return build_id_cache__add_s(sbuild_id, name, is_kallsyms, is_vdso);
 }
 
+bool build_id_cache__cached(const char *sbuild_id)
+{
+	bool ret = false;
+	char *filename = build_id__filename(sbuild_id, NULL, 0);
+
+	if (filename && !access(filename, F_OK))
+		ret = true;
+	free(filename);
+
+	return ret;
+}
+
 int build_id_cache__remove_s(const char *sbuild_id)
 {
 	const size_t size = PATH_MAX;
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 31b3c6332a1a..2a094982f954 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -22,6 +22,7 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits);
 int perf_session__write_buildid_table(struct perf_session *session, int fd);
 int perf_session__cache_build_ids(struct perf_session *session);
 
+bool build_id_cache__cached(const char *sbuild_id);
 int build_id_cache__add_s(const char *sbuild_id,
 			  const char *name, bool is_kallsyms, bool is_vdso);
 int build_id_cache__remove_s(const char *sbuild_id);
-- 
1.9.3


  parent reply	other threads:[~2015-02-27 19:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 19:22 [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 01/19] perf trace: Fix SIGBUS failures due to misaligned accesses Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 02/19] perf probe: Check kprobes blacklist when adding new events Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 03/19] perf probe: Fix get_real_path to free allocated memory in error path Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 04/19] perf probe: Handle strdup() failure Arnaldo Carvalho de Melo
2015-02-27 19:22 ` Arnaldo Carvalho de Melo [this message]
2015-02-27 19:22 ` [PATCH 06/19] perf diff: Support for different binaries Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 07/19] perf probe: Fix a precedence bug Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 08/19] perf data: Fix sentinel setting for data_cmds array Arnaldo Carvalho de Melo
2015-02-27 19:22 ` [PATCH 09/19] perf list: Sort the output of 'perf list' to view more clearly Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 10/19] perf list: Allow listing events with 'tracepoint' prefix Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 11/19] perf list: Avoid confusion of perf output and the next command prompt Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 12/19] perf tools: Remove the '--(null)' long_name for --list-opts Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 13/19] perf list: Clean up the printing functions of hardware/software events Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 14/19] perf list: Extend raw-dump to certain kind of events Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 15/19] perf tools: Fix the bash completion problem of 'perf --*' Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 16/19] perf buildid-cache: Add --purge FILE to remove all caches of FILE Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 17/19] perf buildid-cache: Use pr_debug instead of verbose && pr_info Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 18/19] perf buildid-cache: Show usage with incorrect params Arnaldo Carvalho de Melo
2015-02-27 19:23 ` [PATCH 19/19] perf report: Fix branch stack mode cannot be set Arnaldo Carvalho de Melo
2015-02-28  7:49 ` [PATCH] perf tools: Fix pthread_attr_setaffinity_np() feature detection on Ubuntu systems Ingo Molnar
2015-02-28 22:57   ` Jiri Olsa
2015-03-01 16:11     ` Ingo Molnar
2015-02-28  8:12 ` [PATCH] perf tools: Add PERF-FEATURES to the .gitignore file Ingo Molnar
2015-02-28  8:17   ` [PATCH] perf tools: Remove annoying extra message from the features build Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:33   ` [PATCH] perf tools: Improve Python feature detection messages Ingo Molnar
2015-03-02 15:10     ` Arnaldo Carvalho de Melo
2015-03-03 13:01       ` Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:39   ` [PATCH] perf tools: Improve libperl detection message Ingo Molnar
2015-03-03  6:24     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  8:41   ` [PATCH] perf tools: Improve libbfd " Ingo Molnar
2015-02-28  8:46     ` [PATCH v2] " Ingo Molnar
2015-03-03  6:24       ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  9:16     ` [PATCH] perf tools: Improve feature test debuggability Ingo Molnar
2015-03-03  6:25       ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-02-28  9:18   ` [PATCH] perf tools: Improve 'libbabel' feature check failure message Ingo Molnar
2015-03-02 15:19     ` Arnaldo Carvalho de Melo
2015-03-03 13:02       ` Ingo Molnar
2015-03-03  6:25     ` [tip:perf/core] " tip-bot for Ingo Molnar
2015-03-03  6:23   ` [tip:perf/core] perf tools: Add PERF-FEATURES to the .gitignore file tip-bot for 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=1425064989-26440-6-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=bp@suse.de \
    --cc=hemant@linux.vnet.ibm.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /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 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.