10 #include <sys/types.h> 22 #include <subcmd/parse-options.h> 35 strlcpy(root_dir, proc_dir,
sizeof(root_dir));
37 p = strrchr(root_dir,
'/');
54 u64 addr1 = 0, addr2 = 0;
57 scnprintf(from,
sizeof(from),
"%s/kallsyms", from_dir);
58 scnprintf(to,
sizeof(to),
"%s/kallsyms", to_dir);
72 return addr1 == addr2;
89 scnprintf(from,
sizeof(from),
"%s/modules", from_dir);
95 if (dent->d_type != DT_DIR)
97 scnprintf(to,
sizeof(to),
"%s/%s/modules", to_dir,
99 scnprintf(to_subdir,
sizeof(to_subdir),
"%s/%s",
100 to_dir, dent->d_name);
103 strlcpy(to_dir, to_subdir, to_dir_sz);
120 strlcpy(from_dir, filename,
sizeof(from_dir));
122 p = strrchr(from_dir,
'/');
123 if (!p || strcmp(p + 1,
"kcore"))
130 scnprintf(to_dir,
sizeof(to_dir),
"%s/%s/%s",
135 pr_debug(
"same kcore found in %s\n", to_dir);
142 scnprintf(to_dir,
sizeof(to_dir),
"%s/%s/%s/%s",
150 if (!rmdir(to_dir)) {
151 p = strrchr(to_dir,
'/');
155 if (!rmdir(to_dir)) {
156 p = strrchr(to_dir,
'/');
166 pr_debug(
"kcore added to build-id cache directory %s\n", to_dir);
182 pr_debug(
"Couldn't read a build-id in %s\n", filename);
189 pr_debug(
"Adding %s %s: %s\n", sbuild_id, filename,
190 err ?
"FAIL" :
"Ok");
206 pr_debug(
"Couldn't read a build-id in %s\n", filename);
212 pr_debug(
"Removing %s %s: %s\n", sbuild_id, filename,
213 err ?
"FAIL" :
"Ok");
230 pr_debug(
"Removing %s %s: %s\n", pos->
s, pathname,
231 err ?
"FAIL" :
"Ok");
238 pr_debug(
"Purging %s: %s\n", pathname, err ?
"FAIL" :
"Ok");
252 pr_debug(
"Failed to get buildids: -%d\n", errno);
259 pr_debug(
"Removing %s (%s): %s\n", buf, pos->
s,
260 err ?
"FAIL" :
"Ok");
267 pr_debug(
"Purged all: %s\n", err ?
"FAIL" :
"Ok");
278 sizeof(build_id)) !=
sizeof(build_id)) {
282 pr_warning(
"Problems with %s file, consider removing it from the cache\n",
285 pr_warning(
"Problems with %s file, consider removing it from the cache\n",
310 pr_debug(
"Couldn't read a build-id in %s\n", filename);
323 pr_debug(
"Updating %s %s: %s\n", sbuild_id, filename,
324 err ?
"FAIL" :
"Ok");
337 pr_debug(
"Failed to get buildids: -%d\n", errno);
342 fprintf(stdout,
"%s %s\n", nd->
s, buf);
356 bool list_files =
false;
357 bool opts_flag =
false;
358 bool purge_all =
false;
359 char const *add_name_list_str = NULL,
360 *remove_name_list_str = NULL,
361 *purge_name_list_str = NULL,
362 *missing_filename = NULL,
363 *update_name_list_str = NULL,
364 *kcore_filename = NULL;
373 const struct option buildid_cache_options[] = {
374 OPT_STRING(
'a',
"add", &add_name_list_str,
375 "file list",
"file(s) to add"),
376 OPT_STRING(
'k',
"kcore", &kcore_filename,
377 "file",
"kcore file to add"),
378 OPT_STRING(
'r',
"remove", &remove_name_list_str,
"file list",
379 "file(s) to remove"),
380 OPT_STRING(
'p',
"purge", &purge_name_list_str,
"file list",
381 "file(s) to remove (remove old caches too)"),
382 OPT_BOOLEAN(
'P',
"purge-all", &purge_all,
"purge all cached files"),
383 OPT_BOOLEAN(
'l',
"list", &list_files,
"list all cached files"),
384 OPT_STRING(
'M',
"missing", &missing_filename,
"file",
385 "to find missing build ids in the cache"),
386 OPT_BOOLEAN(
'f',
"force", &force,
"don't complain, do it"),
387 OPT_STRING(
'u',
"update", &update_name_list_str,
"file list",
388 "file(s) to update"),
389 OPT_INCR(
'v',
"verbose", &
verbose,
"be more verbose"),
390 OPT_INTEGER(0,
"target-ns", &ns_id,
"target pid for namespace context"),
393 const char *
const buildid_cache_usage[] = {
394 "perf buildid-cache [<options>]",
398 argc = parse_options(argc, argv, buildid_cache_options,
399 buildid_cache_usage, 0);
401 opts_flag = add_name_list_str || kcore_filename ||
402 remove_name_list_str || purge_name_list_str ||
403 missing_filename || update_name_list_str ||
406 if (argc || !(list_files || opts_flag))
407 usage_with_options(buildid_cache_usage, buildid_cache_options);
410 if (list_files && opts_flag) {
411 usage_with_options_msg(buildid_cache_usage,
412 buildid_cache_options,
"-l is exclusive.\n");
418 if (missing_filename) {
437 if (add_name_list_str) {
442 if (errno == EEXIST) {
443 pr_debug(
"%s already in the cache\n",
448 pos->
s, str_error_r(errno, sbuf,
sizeof(sbuf)));
455 if (remove_name_list_str) {
460 if (errno == ENOENT) {
461 pr_debug(
"%s wasn't in the cache\n",
466 pos->
s, str_error_r(errno, sbuf,
sizeof(sbuf)));
473 if (purge_name_list_str) {
478 if (errno == ENOENT) {
479 pr_debug(
"%s wasn't in the cache\n",
484 pos->
s, str_error_r(errno, sbuf,
sizeof(sbuf)));
493 pr_warning(
"Couldn't remove some caches. Error: %s.\n",
494 str_error_r(errno, sbuf,
sizeof(sbuf)));
498 if (missing_filename)
501 if (update_name_list_str) {
506 if (errno == ENOENT) {
507 pr_debug(
"%s wasn't in the cache\n",
512 pos->
s, str_error_r(errno, sbuf,
sizeof(sbuf)));
520 pr_warning(
"Couldn't add %s\n", kcore_filename);
char * build_id_cache__origname(const char *sbuild_id)
struct nsinfo * nsinfo__new(pid_t pid)
size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp, bool(skip)(struct dso *dso, int parm), int parm)
void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc)
int cmd_buildid_cache(int argc, const char **argv)
int build_id_cache__add_s(const char *sbuild_id, const char *name, struct nsinfo *nsi, bool is_kallsyms, bool is_vdso)
#define nsinfo__zput(nsi)
int filename__read_build_id(const char *filename, void *bf, size_t size)
struct perf_data_file file
static int build_id_cache__show_all(void)
int build_id_cache__remove_s(const char *sbuild_id)
static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
static int build_id_cache__add_kcore(const char *filename, bool force)
static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi)
void perf_session__delete(struct perf_session *session)
int compare_proc_modules(const char *from, const char *to)
static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
static int build_id_cache__purge_all(void)
void nsinfo__mountns_exit(struct nscookie *nc)
#define pr_debug(fmt,...)
static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
static struct perf_session * session
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
#define strlist__for_each_entry(pos, slist)
int fetch_current_timestamp(char *buf, size_t sz)
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
int build_id_cache__list_build_ids(const char *pathname, struct nsinfo *nsi, struct strlist **result)
static int build_id_cache__kcore_dir(char *dir, size_t sz)
const char * ref_reloc_sym_names[]
int mkdir_p(char *path, mode_t mode)
static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
struct perf_session * perf_session__new(struct perf_data *data, bool repipe, struct perf_tool *tool)
static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *fp)
u8 build_id[BUILD_ID_SIZE]
static bool same_kallsyms_reloc(const char *from_dir, char *to_dir)
bool build_id_cache__cached(const char *sbuild_id)
void strlist__delete(struct strlist *slist)
int build_id__sprintf(const u8 *build_id, int len, char *bf)
struct perf_header header
int kcore_copy(const char *from_dir, const char *to_dir)
static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir, size_t to_dir_sz)
int symbol__init(struct perf_env *env)
struct strlist * build_id_cache__list_all(bool validonly)
int kallsyms__get_function_start(const char *kallsyms_filename, const char *symbol_name, u64 *addr)
char * dso__build_id_filename(const struct dso *dso, char *bf, size_t size, bool is_debug)
#define pr_warning(fmt,...)
struct strlist * strlist__new(const char *list, const struct strlist_config *config)