Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf buildid-cache: Support --list option

'perf buildid-cache' allows to add/remove files into cache but there is
no option to list all cached files. Add --list option to list all
_valid_ cached files.

Ex,
# perf buildid-cache --add /tmp/a.out
# perf buildid-cache -l
8a86ef73e44067bca52cc3f6cd3e5446c783391c /tmp/a.out

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Cc: Sihyeon Jang <uneedsihyeon@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20180417041346.5617-3-ravi.bangoria@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ravi Bangoria and committed by
Arnaldo Carvalho de Melo
8e1e0d74 d4652f61

+43 -4
+3 -1
tools/perf/Documentation/perf-buildid-cache.txt
··· 59 59 exactly same build-id, that is replaced by new one. It can be used 60 60 to update kallsyms and kernel dso to vmlinux in order to support 61 61 annotation. 62 - 62 + -l:: 63 + --list:: 64 + List all valid binaries from cache. 63 65 -v:: 64 66 --verbose:: 65 67 Be more verbose.
+40 -3
tools/perf/builtin-buildid-cache.c
··· 25 25 #include "util/session.h" 26 26 #include "util/symbol.h" 27 27 #include "util/time-utils.h" 28 + #include "util/probe-file.h" 28 29 29 30 static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid) 30 31 { ··· 298 297 return err; 299 298 } 300 299 300 + static int build_id_cache__show_all(void) 301 + { 302 + struct strlist *bidlist; 303 + struct str_node *nd; 304 + char *buf; 305 + 306 + bidlist = build_id_cache__list_all(true); 307 + if (!bidlist) { 308 + pr_debug("Failed to get buildids: -%d\n", errno); 309 + return -1; 310 + } 311 + strlist__for_each_entry(nd, bidlist) { 312 + buf = build_id_cache__origname(nd->s); 313 + fprintf(stdout, "%s %s\n", nd->s, buf); 314 + free(buf); 315 + } 316 + strlist__delete(bidlist); 317 + return 0; 318 + } 319 + 301 320 int cmd_buildid_cache(int argc, const char **argv) 302 321 { 303 322 struct strlist *list; ··· 325 304 int ret = 0; 326 305 int ns_id = -1; 327 306 bool force = false; 307 + bool list_files = false; 308 + bool opts_flag = false; 328 309 char const *add_name_list_str = NULL, 329 310 *remove_name_list_str = NULL, 330 311 *purge_name_list_str = NULL, ··· 350 327 "file(s) to remove"), 351 328 OPT_STRING('p', "purge", &purge_name_list_str, "file list", 352 329 "file(s) to remove (remove old caches too)"), 330 + OPT_BOOLEAN('l', "list", &list_files, "list all cached files"), 353 331 OPT_STRING('M', "missing", &missing_filename, "file", 354 332 "to find missing build ids in the cache"), 355 333 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), ··· 368 344 argc = parse_options(argc, argv, buildid_cache_options, 369 345 buildid_cache_usage, 0); 370 346 371 - if (argc || (!add_name_list_str && !kcore_filename && 372 - !remove_name_list_str && !purge_name_list_str && 373 - !missing_filename && !update_name_list_str)) 347 + opts_flag = add_name_list_str || kcore_filename || 348 + remove_name_list_str || purge_name_list_str || 349 + missing_filename || update_name_list_str; 350 + 351 + if (argc || !(list_files || opts_flag)) 374 352 usage_with_options(buildid_cache_usage, buildid_cache_options); 353 + 354 + /* -l is exclusive. It can not be used with other options. */ 355 + if (list_files && opts_flag) { 356 + usage_with_options_msg(buildid_cache_usage, 357 + buildid_cache_options, "-l is exclusive.\n"); 358 + } 375 359 376 360 if (ns_id > 0) 377 361 nsi = nsinfo__new(ns_id); ··· 397 365 goto out; 398 366 399 367 setup_pager(); 368 + 369 + if (list_files) { 370 + ret = build_id_cache__show_all(); 371 + goto out; 372 + } 400 373 401 374 if (add_name_list_str) { 402 375 list = strlist__new(add_name_list_str, NULL);