Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-buildid-cache.c |
| 3 | * |
| 4 | * Builtin buildid-cache command: Manages build-id cache |
| 5 | * |
| 6 | * Copyright (C) 2010, Red Hat Inc. |
| 7 | * Copyright (C) 2010, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 8 | */ |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 9 | #include <sys/types.h> |
| 10 | #include <sys/time.h> |
| 11 | #include <time.h> |
| 12 | #include <dirent.h> |
| 13 | #include <unistd.h> |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 14 | #include "builtin.h" |
| 15 | #include "perf.h" |
| 16 | #include "util/cache.h" |
| 17 | #include "util/debug.h" |
| 18 | #include "util/header.h" |
| 19 | #include "util/parse-options.h" |
| 20 | #include "util/strlist.h" |
Jiri Olsa | ebb296c | 2012-10-27 23:18:28 +0200 | [diff] [blame] | 21 | #include "util/build-id.h" |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 22 | #include "util/session.h" |
Jiri Olsa | 4383db8 | 2012-10-27 23:18:29 +0200 | [diff] [blame] | 23 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 24 | |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 25 | static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) |
| 26 | { |
| 27 | char root_dir[PATH_MAX]; |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 28 | char *p; |
| 29 | |
| 30 | strlcpy(root_dir, proc_dir, sizeof(root_dir)); |
| 31 | |
| 32 | p = strrchr(root_dir, '/'); |
| 33 | if (!p) |
| 34 | return -1; |
| 35 | *p = '\0'; |
Masami Hiramatsu | 0b5a793 | 2015-08-15 20:42:59 +0900 | [diff] [blame] | 36 | return sysfs__sprintf_build_id(root_dir, sbuildid); |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static int build_id_cache__kcore_dir(char *dir, size_t sz) |
| 40 | { |
| 41 | struct timeval tv; |
| 42 | struct tm tm; |
| 43 | char dt[32]; |
| 44 | |
| 45 | if (gettimeofday(&tv, NULL) || !localtime_r(&tv.tv_sec, &tm)) |
| 46 | return -1; |
| 47 | |
| 48 | if (!strftime(dt, sizeof(dt), "%Y%m%d%H%M%S", &tm)) |
| 49 | return -1; |
| 50 | |
| 51 | scnprintf(dir, sz, "%s%02u", dt, (unsigned)tv.tv_usec / 10000); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
Adrian Hunter | d3b7022 | 2014-01-29 16:14:44 +0200 | [diff] [blame] | 56 | static bool same_kallsyms_reloc(const char *from_dir, char *to_dir) |
| 57 | { |
| 58 | char from[PATH_MAX]; |
| 59 | char to[PATH_MAX]; |
| 60 | const char *name; |
| 61 | u64 addr1 = 0, addr2 = 0; |
| 62 | int i; |
| 63 | |
| 64 | scnprintf(from, sizeof(from), "%s/kallsyms", from_dir); |
| 65 | scnprintf(to, sizeof(to), "%s/kallsyms", to_dir); |
| 66 | |
| 67 | for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) { |
| 68 | addr1 = kallsyms__get_function_start(from, name); |
| 69 | if (addr1) |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | if (name) |
| 74 | addr2 = kallsyms__get_function_start(to, name); |
| 75 | |
| 76 | return addr1 == addr2; |
| 77 | } |
| 78 | |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 79 | static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir, |
| 80 | size_t to_dir_sz) |
| 81 | { |
| 82 | char from[PATH_MAX]; |
| 83 | char to[PATH_MAX]; |
Adrian Hunter | d3b7022 | 2014-01-29 16:14:44 +0200 | [diff] [blame] | 84 | char to_subdir[PATH_MAX]; |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 85 | struct dirent *dent; |
| 86 | int ret = -1; |
| 87 | DIR *d; |
| 88 | |
| 89 | d = opendir(to_dir); |
| 90 | if (!d) |
| 91 | return -1; |
| 92 | |
| 93 | scnprintf(from, sizeof(from), "%s/modules", from_dir); |
| 94 | |
| 95 | while (1) { |
| 96 | dent = readdir(d); |
| 97 | if (!dent) |
| 98 | break; |
| 99 | if (dent->d_type != DT_DIR) |
| 100 | continue; |
| 101 | scnprintf(to, sizeof(to), "%s/%s/modules", to_dir, |
| 102 | dent->d_name); |
Adrian Hunter | d3b7022 | 2014-01-29 16:14:44 +0200 | [diff] [blame] | 103 | scnprintf(to_subdir, sizeof(to_subdir), "%s/%s", |
| 104 | to_dir, dent->d_name); |
| 105 | if (!compare_proc_modules(from, to) && |
| 106 | same_kallsyms_reloc(from_dir, to_subdir)) { |
| 107 | strlcpy(to_dir, to_subdir, to_dir_sz); |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 108 | ret = 0; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | closedir(d); |
| 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 118 | static int build_id_cache__add_kcore(const char *filename, bool force) |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 119 | { |
Masami Hiramatsu | d77fac7 | 2015-07-15 18:14:28 +0900 | [diff] [blame] | 120 | char dir[32], sbuildid[SBUILD_ID_SIZE]; |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 121 | char from_dir[PATH_MAX], to_dir[PATH_MAX]; |
| 122 | char *p; |
| 123 | |
| 124 | strlcpy(from_dir, filename, sizeof(from_dir)); |
| 125 | |
| 126 | p = strrchr(from_dir, '/'); |
| 127 | if (!p || strcmp(p + 1, "kcore")) |
| 128 | return -1; |
| 129 | *p = '\0'; |
| 130 | |
Masami Hiramatsu | 0b5a793 | 2015-08-15 20:42:59 +0900 | [diff] [blame] | 131 | if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0) |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 132 | return -1; |
| 133 | |
| 134 | scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s", |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 135 | buildid_dir, sbuildid); |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 136 | |
Adrian Hunter | 5173fbb | 2014-07-14 13:02:38 +0300 | [diff] [blame] | 137 | if (!force && |
| 138 | !build_id_cache__kcore_existing(from_dir, to_dir, sizeof(to_dir))) { |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 139 | pr_debug("same kcore found in %s\n", to_dir); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | if (build_id_cache__kcore_dir(dir, sizeof(dir))) |
| 144 | return -1; |
| 145 | |
| 146 | scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s/%s", |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 147 | buildid_dir, sbuildid, dir); |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 148 | |
| 149 | if (mkdir_p(to_dir, 0755)) |
| 150 | return -1; |
| 151 | |
| 152 | if (kcore_copy(from_dir, to_dir)) { |
| 153 | /* Remove YYYYmmddHHMMSShh directory */ |
| 154 | if (!rmdir(to_dir)) { |
| 155 | p = strrchr(to_dir, '/'); |
| 156 | if (p) |
| 157 | *p = '\0'; |
| 158 | /* Try to remove buildid directory */ |
| 159 | if (!rmdir(to_dir)) { |
| 160 | p = strrchr(to_dir, '/'); |
| 161 | if (p) |
| 162 | *p = '\0'; |
| 163 | /* Try to remove [kernel.kcore] directory */ |
| 164 | rmdir(to_dir); |
| 165 | } |
| 166 | } |
| 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | pr_debug("kcore added to build-id cache directory %s\n", to_dir); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 175 | static int build_id_cache__add_file(const char *filename) |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 176 | { |
Masami Hiramatsu | d77fac7 | 2015-07-15 18:14:28 +0900 | [diff] [blame] | 177 | char sbuild_id[SBUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 178 | u8 build_id[BUILD_ID_SIZE]; |
| 179 | int err; |
| 180 | |
| 181 | if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) { |
| 182 | pr_debug("Couldn't read a build-id in %s\n", filename); |
| 183 | return -1; |
| 184 | } |
| 185 | |
| 186 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 187 | err = build_id_cache__add_s(sbuild_id, filename, |
Jiri Olsa | 7dbf4dc | 2012-09-10 18:50:19 +0200 | [diff] [blame] | 188 | false, false); |
Masami Hiramatsu | cc169c7 | 2015-02-27 13:50:28 +0900 | [diff] [blame] | 189 | pr_debug("Adding %s %s: %s\n", sbuild_id, filename, |
| 190 | err ? "FAIL" : "Ok"); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 191 | return err; |
| 192 | } |
| 193 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 194 | static int build_id_cache__remove_file(const char *filename) |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 195 | { |
| 196 | u8 build_id[BUILD_ID_SIZE]; |
Masami Hiramatsu | d77fac7 | 2015-07-15 18:14:28 +0900 | [diff] [blame] | 197 | char sbuild_id[SBUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 198 | |
| 199 | int err; |
| 200 | |
| 201 | if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) { |
| 202 | pr_debug("Couldn't read a build-id in %s\n", filename); |
| 203 | return -1; |
| 204 | } |
| 205 | |
| 206 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 207 | err = build_id_cache__remove_s(sbuild_id); |
Masami Hiramatsu | cc169c7 | 2015-02-27 13:50:28 +0900 | [diff] [blame] | 208 | pr_debug("Removing %s %s: %s\n", sbuild_id, filename, |
| 209 | err ? "FAIL" : "Ok"); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 210 | |
| 211 | return err; |
| 212 | } |
| 213 | |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 214 | static int build_id_cache__purge_path(const char *pathname) |
| 215 | { |
| 216 | struct strlist *list; |
| 217 | struct str_node *pos; |
| 218 | int err; |
| 219 | |
| 220 | err = build_id_cache__list_build_ids(pathname, &list); |
| 221 | if (err) |
| 222 | goto out; |
| 223 | |
| 224 | strlist__for_each(pos, list) { |
| 225 | err = build_id_cache__remove_s(pos->s); |
Masami Hiramatsu | cc169c7 | 2015-02-27 13:50:28 +0900 | [diff] [blame] | 226 | pr_debug("Removing %s %s: %s\n", pos->s, pathname, |
| 227 | err ? "FAIL" : "Ok"); |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 228 | if (err) |
| 229 | break; |
| 230 | } |
| 231 | strlist__delete(list); |
| 232 | |
| 233 | out: |
Masami Hiramatsu | cc169c7 | 2015-02-27 13:50:28 +0900 | [diff] [blame] | 234 | pr_debug("Purging %s: %s\n", pathname, err ? "FAIL" : "Ok"); |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 235 | |
| 236 | return err; |
| 237 | } |
| 238 | |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 239 | static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) |
| 240 | { |
| 241 | char filename[PATH_MAX]; |
| 242 | u8 build_id[BUILD_ID_SIZE]; |
| 243 | |
| 244 | if (dso__build_id_filename(dso, filename, sizeof(filename)) && |
| 245 | filename__read_build_id(filename, build_id, |
| 246 | sizeof(build_id)) != sizeof(build_id)) { |
| 247 | if (errno == ENOENT) |
| 248 | return false; |
| 249 | |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 250 | pr_warning("Problems with %s file, consider removing it from the cache\n", |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 251 | filename); |
| 252 | } else if (memcmp(dso->build_id, build_id, sizeof(dso->build_id))) { |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 253 | pr_warning("Problems with %s file, consider removing it from the cache\n", |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 254 | filename); |
| 255 | } |
| 256 | |
| 257 | return true; |
| 258 | } |
| 259 | |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 260 | static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *fp) |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 261 | { |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 262 | perf_session__fprintf_dsos_buildid(session, fp, dso__missing_buildid_cache, 0); |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 266 | static int build_id_cache__update_file(const char *filename) |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 267 | { |
| 268 | u8 build_id[BUILD_ID_SIZE]; |
Masami Hiramatsu | d77fac7 | 2015-07-15 18:14:28 +0900 | [diff] [blame] | 269 | char sbuild_id[SBUILD_ID_SIZE]; |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 270 | |
Masami Hiramatsu | a50d11a | 2015-02-26 15:54:40 +0900 | [diff] [blame] | 271 | int err = 0; |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 272 | |
| 273 | if (filename__read_build_id(filename, &build_id, sizeof(build_id)) < 0) { |
| 274 | pr_debug("Couldn't read a build-id in %s\n", filename); |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | build_id__sprintf(build_id, sizeof(build_id), sbuild_id); |
Masami Hiramatsu | a50d11a | 2015-02-26 15:54:40 +0900 | [diff] [blame] | 279 | if (build_id_cache__cached(sbuild_id)) |
| 280 | err = build_id_cache__remove_s(sbuild_id); |
| 281 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 282 | if (!err) |
| 283 | err = build_id_cache__add_s(sbuild_id, filename, false, false); |
| 284 | |
Masami Hiramatsu | cc169c7 | 2015-02-27 13:50:28 +0900 | [diff] [blame] | 285 | pr_debug("Updating %s %s: %s\n", sbuild_id, filename, |
| 286 | err ? "FAIL" : "Ok"); |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 287 | |
| 288 | return err; |
| 289 | } |
| 290 | |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 291 | int cmd_buildid_cache(int argc, const char **argv, |
| 292 | const char *prefix __maybe_unused) |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 293 | { |
| 294 | struct strlist *list; |
| 295 | struct str_node *pos; |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 296 | int ret = 0; |
| 297 | bool force = false; |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 298 | char const *add_name_list_str = NULL, |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 299 | *remove_name_list_str = NULL, |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 300 | *purge_name_list_str = NULL, |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 301 | *missing_filename = NULL, |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 302 | *update_name_list_str = NULL, |
Jiri Olsa | eec5a68 | 2014-12-01 20:06:27 +0100 | [diff] [blame] | 303 | *kcore_filename = NULL; |
Masami Hiramatsu | 340481ad | 2014-08-14 02:22:49 +0000 | [diff] [blame] | 304 | char sbuf[STRERR_BUFSIZE]; |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 305 | |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 306 | struct perf_data_file file = { |
| 307 | .mode = PERF_DATA_MODE_READ, |
| 308 | }; |
| 309 | struct perf_session *session = NULL; |
| 310 | |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 311 | const struct option buildid_cache_options[] = { |
| 312 | OPT_STRING('a', "add", &add_name_list_str, |
| 313 | "file list", "file(s) to add"), |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 314 | OPT_STRING('k', "kcore", &kcore_filename, |
| 315 | "file", "kcore file to add"), |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 316 | OPT_STRING('r', "remove", &remove_name_list_str, "file list", |
| 317 | "file(s) to remove"), |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 318 | OPT_STRING('p', "purge", &purge_name_list_str, "path list", |
| 319 | "path(s) to remove (remove old caches too)"), |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 320 | OPT_STRING('M', "missing", &missing_filename, "file", |
| 321 | "to find missing build ids in the cache"), |
| 322 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 323 | OPT_STRING('u', "update", &update_name_list_str, "file list", |
| 324 | "file(s) to update"), |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 325 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
| 326 | OPT_END() |
| 327 | }; |
| 328 | const char * const buildid_cache_usage[] = { |
| 329 | "perf buildid-cache [<options>]", |
| 330 | NULL |
| 331 | }; |
| 332 | |
| 333 | argc = parse_options(argc, argv, buildid_cache_options, |
| 334 | buildid_cache_usage, 0); |
| 335 | |
Masami Hiramatsu | 0497d0a | 2015-02-27 13:50:31 +0900 | [diff] [blame] | 336 | if (argc || (!add_name_list_str && !kcore_filename && |
| 337 | !remove_name_list_str && !purge_name_list_str && |
| 338 | !missing_filename && !update_name_list_str)) |
| 339 | usage_with_options(buildid_cache_usage, buildid_cache_options); |
| 340 | |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 341 | if (missing_filename) { |
| 342 | file.path = missing_filename; |
| 343 | file.force = force; |
| 344 | |
| 345 | session = perf_session__new(&file, false, NULL); |
| 346 | if (session == NULL) |
| 347 | return -1; |
| 348 | } |
| 349 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 350 | if (symbol__init(session ? &session->header.env : NULL) < 0) |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 351 | goto out; |
Arnaldo Carvalho de Melo | 472cc83 | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 352 | |
| 353 | setup_pager(); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 354 | |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 355 | if (add_name_list_str) { |
Arnaldo Carvalho de Melo | 4a77e21 | 2015-07-20 12:13:34 -0300 | [diff] [blame] | 356 | list = strlist__new(add_name_list_str, NULL); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 357 | if (list) { |
| 358 | strlist__for_each(pos, list) |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 359 | if (build_id_cache__add_file(pos->s)) { |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 360 | if (errno == EEXIST) { |
| 361 | pr_debug("%s already in the cache\n", |
| 362 | pos->s); |
| 363 | continue; |
| 364 | } |
| 365 | pr_warning("Couldn't add %s: %s\n", |
Masami Hiramatsu | 340481ad | 2014-08-14 02:22:49 +0000 | [diff] [blame] | 366 | pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | strlist__delete(list); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (remove_name_list_str) { |
Arnaldo Carvalho de Melo | 4a77e21 | 2015-07-20 12:13:34 -0300 | [diff] [blame] | 374 | list = strlist__new(remove_name_list_str, NULL); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 375 | if (list) { |
| 376 | strlist__for_each(pos, list) |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 377 | if (build_id_cache__remove_file(pos->s)) { |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 378 | if (errno == ENOENT) { |
| 379 | pr_debug("%s wasn't in the cache\n", |
| 380 | pos->s); |
| 381 | continue; |
| 382 | } |
| 383 | pr_warning("Couldn't remove %s: %s\n", |
Masami Hiramatsu | 340481ad | 2014-08-14 02:22:49 +0000 | [diff] [blame] | 384 | pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | strlist__delete(list); |
| 388 | } |
| 389 | } |
| 390 | |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 391 | if (purge_name_list_str) { |
Arnaldo Carvalho de Melo | 4a77e21 | 2015-07-20 12:13:34 -0300 | [diff] [blame] | 392 | list = strlist__new(purge_name_list_str, NULL); |
Masami Hiramatsu | 8d8c8e4 | 2015-02-27 13:50:26 +0900 | [diff] [blame] | 393 | if (list) { |
| 394 | strlist__for_each(pos, list) |
| 395 | if (build_id_cache__purge_path(pos->s)) { |
| 396 | if (errno == ENOENT) { |
| 397 | pr_debug("%s wasn't in the cache\n", |
| 398 | pos->s); |
| 399 | continue; |
| 400 | } |
| 401 | pr_warning("Couldn't remove %s: %s\n", |
| 402 | pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); |
| 403 | } |
| 404 | |
| 405 | strlist__delete(list); |
| 406 | } |
| 407 | } |
| 408 | |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 409 | if (missing_filename) |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 410 | ret = build_id_cache__fprintf_missing(session, stdout); |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 411 | |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 412 | if (update_name_list_str) { |
Arnaldo Carvalho de Melo | 4a77e21 | 2015-07-20 12:13:34 -0300 | [diff] [blame] | 413 | list = strlist__new(update_name_list_str, NULL); |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 414 | if (list) { |
| 415 | strlist__for_each(pos, list) |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 416 | if (build_id_cache__update_file(pos->s)) { |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 417 | if (errno == ENOENT) { |
| 418 | pr_debug("%s wasn't in the cache\n", |
| 419 | pos->s); |
| 420 | continue; |
| 421 | } |
| 422 | pr_warning("Couldn't update %s: %s\n", |
Masami Hiramatsu | 340481ad | 2014-08-14 02:22:49 +0000 | [diff] [blame] | 423 | pos->s, strerror_r(errno, sbuf, sizeof(sbuf))); |
Namhyung Kim | eeb4984 | 2013-02-07 18:02:11 +0900 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | strlist__delete(list); |
| 427 | } |
| 428 | } |
| 429 | |
Masami Hiramatsu | e35f736 | 2015-02-10 18:18:51 +0900 | [diff] [blame] | 430 | if (kcore_filename && build_id_cache__add_kcore(kcore_filename, force)) |
Adrian Hunter | fc1b691 | 2013-10-14 16:57:29 +0300 | [diff] [blame] | 431 | pr_warning("Couldn't add %s\n", kcore_filename); |
| 432 | |
Namhyung Kim | e3ed75b | 2014-08-12 15:40:36 +0900 | [diff] [blame] | 433 | out: |
| 434 | if (session) |
| 435 | perf_session__delete(session); |
| 436 | |
Arnaldo Carvalho de Melo | fbb6976 | 2012-12-07 16:28:27 -0300 | [diff] [blame] | 437 | return ret; |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 438 | } |