linux-kernel.vger.kernel.org archive mirror
 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>,
	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 06/10] perf buildid: Introduce sysfs/filename__sprintf_build_id
Date: Fri, 28 Aug 2015 15:06:32 -0300	[thread overview]
Message-ID: <1440785196-27476-7-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1440785196-27476-1-git-send-email-acme@kernel.org>

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

Introduce sysfs/filename__sprintf_build_id for consolidating similar
code.

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: 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/20150815114259.13642.34685.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-buildid-cache.c | 14 ++------------
 tools/perf/builtin-buildid-list.c  | 24 ++++++++++--------------
 tools/perf/util/build-id.c         | 32 ++++++++++++++++++++++++++++++++
 tools/perf/util/build-id.h         |  3 +++
 4 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 65b4835309c7..7b8450cd33c2 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -25,8 +25,6 @@
 static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
 {
 	char root_dir[PATH_MAX];
-	char notes[PATH_MAX];
-	u8 build_id[BUILD_ID_SIZE];
 	char *p;
 
 	strlcpy(root_dir, proc_dir, sizeof(root_dir));
@@ -35,15 +33,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
 	if (!p)
 		return -1;
 	*p = '\0';
-
-	scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
-
-	if (sysfs__read_build_id(notes, build_id, sizeof(build_id)))
-		return -1;
-
-	build_id__sprintf(build_id, sizeof(build_id), sbuildid);
-
-	return 0;
+	return sysfs__sprintf_build_id(root_dir, sbuildid);
 }
 
 static int build_id_cache__kcore_dir(char *dir, size_t sz)
@@ -138,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
 		return -1;
 	*p = '\0';
 
-	if (build_id_cache__kcore_buildid(from_dir, sbuildid))
+	if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0)
 		return -1;
 
 	scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s",
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index b5ca988ebfbe..918b4de29de4 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -19,29 +19,25 @@
 
 static int sysfs__fprintf_build_id(FILE *fp)
 {
-	u8 kallsyms_build_id[BUILD_ID_SIZE];
 	char sbuild_id[SBUILD_ID_SIZE];
+	int ret;
 
-	if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
-				 sizeof(kallsyms_build_id)) != 0)
-		return -1;
+	ret = sysfs__sprintf_build_id("/", sbuild_id);
+	if (ret != sizeof(sbuild_id))
+		return ret < 0 ? ret : -EINVAL;
 
-	build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id),
-			  sbuild_id);
-	fprintf(fp, "%s\n", sbuild_id);
-	return 0;
+	return fprintf(fp, "%s\n", sbuild_id);
 }
 
 static int filename__fprintf_build_id(const char *name, FILE *fp)
 {
-	u8 build_id[BUILD_ID_SIZE];
 	char sbuild_id[SBUILD_ID_SIZE];
+	int ret;
 
-	if (filename__read_build_id(name, build_id,
-				    sizeof(build_id)) != sizeof(build_id))
-		return 0;
+	ret = filename__sprintf_build_id(name, sbuild_id);
+	if (ret != sizeof(sbuild_id))
+		return ret < 0 ? ret : -EINVAL;
 
-	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
 	return fprintf(fp, "%s\n", sbuild_id);
 }
 
@@ -63,7 +59,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits)
 	/*
 	 * See if this is an ELF file first:
 	 */
-	if (filename__fprintf_build_id(input_name, stdout))
+	if (filename__fprintf_build_id(input_name, stdout) > 0)
 		goto out;
 
 	session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops);
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 4a2c2f0ead41..d909459fb54c 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -93,6 +93,38 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
 	return raw - build_id;
 }
 
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
+{
+	char notes[PATH_MAX];
+	u8 build_id[BUILD_ID_SIZE];
+	int ret;
+
+	if (!root_dir)
+		root_dir = "";
+
+	scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
+
+	ret = sysfs__read_build_id(notes, build_id, sizeof(build_id));
+	if (ret < 0)
+		return ret;
+
+	return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
+{
+	u8 build_id[BUILD_ID_SIZE];
+	int ret;
+
+	ret = filename__read_build_id(pathname, build_id, sizeof(build_id));
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(build_id))
+		return -EINVAL;
+
+	return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+}
+
 /* asnprintf consolidates asprintf and snprintf */
 static int asnprintf(char **strp, size_t size, const char *fmt, ...)
 {
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index ce2f493f057a..27a14a8a945b 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -12,6 +12,9 @@ extern struct perf_tool build_id__mark_dso_hit_ops;
 struct dso;
 
 int build_id__sprintf(const u8 *build_id, int len, char *bf);
+int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id);
+int filename__sprintf_build_id(const char *pathname, char *sbuild_id);
+
 char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
 
 int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
-- 
2.1.0


  parent reply	other threads:[~2015-08-28 18:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28 18:06 [GIT PULL 00/10] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 01/10] perf script: Add --[no-]-demangle/--[no-]-demangle-kernel Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 02/10] tools lib traceeveent: Allow for negative numbers in print format Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 03/10] perf scripts python: Add new compaction-times script Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 04/10] perf trace: Add header with copyright and background info Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 05/10] perf evsel: Add a backpointer to the evlist a evsel is in Arnaldo Carvalho de Melo
2015-08-28 18:06 ` Arnaldo Carvalho de Melo [this message]
2015-08-28 18:06 ` [PATCH 07/10] perf tools: Add tracing_path and remove unneeded functions Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 08/10] perf tools: Do not change lib/api/fs/debugfs directly Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 09/10] perf tools: Rename perf_session_env to perf_env Arnaldo Carvalho de Melo
2015-08-28 18:06 ` [PATCH 10/10] perf evlist: Add backpointer for perf_env to evlist Arnaldo Carvalho de Melo
2015-08-31  8:28 ` [GIT PULL 00/10] 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=1440785196-27476-7-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=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 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).