diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2015-08-15 07:42:59 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-08-28 13:53:50 -0400 |
commit | 0b5a7935f3b5b7d40293b02c3e552f3d67af208b (patch) | |
tree | f7ebe5bf2f85a7605cf0991a68daf0aaf24b886e /tools | |
parent | d49e4695077278ee3016cd242967de23072ec331 (diff) |
perf buildid: Introduce sysfs/filename__sprintf_build_id
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-buildid-cache.c | 14 | ||||
-rw-r--r-- | tools/perf/builtin-buildid-list.c | 24 | ||||
-rw-r--r-- | tools/perf/util/build-id.c | 32 | ||||
-rw-r--r-- | 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 @@ | |||
25 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) | 25 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) |
26 | { | 26 | { |
27 | char root_dir[PATH_MAX]; | 27 | char root_dir[PATH_MAX]; |
28 | char notes[PATH_MAX]; | ||
29 | u8 build_id[BUILD_ID_SIZE]; | ||
30 | char *p; | 28 | char *p; |
31 | 29 | ||
32 | strlcpy(root_dir, proc_dir, sizeof(root_dir)); | 30 | 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) | |||
35 | if (!p) | 33 | if (!p) |
36 | return -1; | 34 | return -1; |
37 | *p = '\0'; | 35 | *p = '\0'; |
38 | 36 | return sysfs__sprintf_build_id(root_dir, sbuildid); | |
39 | scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir); | ||
40 | |||
41 | if (sysfs__read_build_id(notes, build_id, sizeof(build_id))) | ||
42 | return -1; | ||
43 | |||
44 | build_id__sprintf(build_id, sizeof(build_id), sbuildid); | ||
45 | |||
46 | return 0; | ||
47 | } | 37 | } |
48 | 38 | ||
49 | static int build_id_cache__kcore_dir(char *dir, size_t sz) | 39 | 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) | |||
138 | return -1; | 128 | return -1; |
139 | *p = '\0'; | 129 | *p = '\0'; |
140 | 130 | ||
141 | if (build_id_cache__kcore_buildid(from_dir, sbuildid)) | 131 | if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0) |
142 | return -1; | 132 | return -1; |
143 | 133 | ||
144 | scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s", | 134 | 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 @@ | |||
19 | 19 | ||
20 | static int sysfs__fprintf_build_id(FILE *fp) | 20 | static int sysfs__fprintf_build_id(FILE *fp) |
21 | { | 21 | { |
22 | u8 kallsyms_build_id[BUILD_ID_SIZE]; | ||
23 | char sbuild_id[SBUILD_ID_SIZE]; | 22 | char sbuild_id[SBUILD_ID_SIZE]; |
23 | int ret; | ||
24 | 24 | ||
25 | if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, | 25 | ret = sysfs__sprintf_build_id("/", sbuild_id); |
26 | sizeof(kallsyms_build_id)) != 0) | 26 | if (ret != sizeof(sbuild_id)) |
27 | return -1; | 27 | return ret < 0 ? ret : -EINVAL; |
28 | 28 | ||
29 | build_id__sprintf(kallsyms_build_id, sizeof(kallsyms_build_id), | 29 | return fprintf(fp, "%s\n", sbuild_id); |
30 | sbuild_id); | ||
31 | fprintf(fp, "%s\n", sbuild_id); | ||
32 | return 0; | ||
33 | } | 30 | } |
34 | 31 | ||
35 | static int filename__fprintf_build_id(const char *name, FILE *fp) | 32 | static int filename__fprintf_build_id(const char *name, FILE *fp) |
36 | { | 33 | { |
37 | u8 build_id[BUILD_ID_SIZE]; | ||
38 | char sbuild_id[SBUILD_ID_SIZE]; | 34 | char sbuild_id[SBUILD_ID_SIZE]; |
35 | int ret; | ||
39 | 36 | ||
40 | if (filename__read_build_id(name, build_id, | 37 | ret = filename__sprintf_build_id(name, sbuild_id); |
41 | sizeof(build_id)) != sizeof(build_id)) | 38 | if (ret != sizeof(sbuild_id)) |
42 | return 0; | 39 | return ret < 0 ? ret : -EINVAL; |
43 | 40 | ||
44 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); | ||
45 | return fprintf(fp, "%s\n", sbuild_id); | 41 | return fprintf(fp, "%s\n", sbuild_id); |
46 | } | 42 | } |
47 | 43 | ||
@@ -63,7 +59,7 @@ static int perf_session__list_build_ids(bool force, bool with_hits) | |||
63 | /* | 59 | /* |
64 | * See if this is an ELF file first: | 60 | * See if this is an ELF file first: |
65 | */ | 61 | */ |
66 | if (filename__fprintf_build_id(input_name, stdout)) | 62 | if (filename__fprintf_build_id(input_name, stdout) > 0) |
67 | goto out; | 63 | goto out; |
68 | 64 | ||
69 | session = perf_session__new(&file, false, &build_id__mark_dso_hit_ops); | 65 | 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) | |||
93 | return raw - build_id; | 93 | return raw - build_id; |
94 | } | 94 | } |
95 | 95 | ||
96 | int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id) | ||
97 | { | ||
98 | char notes[PATH_MAX]; | ||
99 | u8 build_id[BUILD_ID_SIZE]; | ||
100 | int ret; | ||
101 | |||
102 | if (!root_dir) | ||
103 | root_dir = ""; | ||
104 | |||
105 | scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir); | ||
106 | |||
107 | ret = sysfs__read_build_id(notes, build_id, sizeof(build_id)); | ||
108 | if (ret < 0) | ||
109 | return ret; | ||
110 | |||
111 | return build_id__sprintf(build_id, sizeof(build_id), sbuild_id); | ||
112 | } | ||
113 | |||
114 | int filename__sprintf_build_id(const char *pathname, char *sbuild_id) | ||
115 | { | ||
116 | u8 build_id[BUILD_ID_SIZE]; | ||
117 | int ret; | ||
118 | |||
119 | ret = filename__read_build_id(pathname, build_id, sizeof(build_id)); | ||
120 | if (ret < 0) | ||
121 | return ret; | ||
122 | else if (ret != sizeof(build_id)) | ||
123 | return -EINVAL; | ||
124 | |||
125 | return build_id__sprintf(build_id, sizeof(build_id), sbuild_id); | ||
126 | } | ||
127 | |||
96 | /* asnprintf consolidates asprintf and snprintf */ | 128 | /* asnprintf consolidates asprintf and snprintf */ |
97 | static int asnprintf(char **strp, size_t size, const char *fmt, ...) | 129 | static int asnprintf(char **strp, size_t size, const char *fmt, ...) |
98 | { | 130 | { |
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; | |||
12 | struct dso; | 12 | struct dso; |
13 | 13 | ||
14 | int build_id__sprintf(const u8 *build_id, int len, char *bf); | 14 | int build_id__sprintf(const u8 *build_id, int len, char *bf); |
15 | int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id); | ||
16 | int filename__sprintf_build_id(const char *pathname, char *sbuild_id); | ||
17 | |||
15 | char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size); | 18 | char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size); |
16 | 19 | ||
17 | int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, | 20 | int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event, |