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

perf buildid-cache: Support --purge-all option

User can remove files from cache using --remove/--purge options but both
needs list of files as an argument. It's not convenient when you want to
flush out entire cache. Add an option to purge all files from cache.

Ex,
# perf buildid-cache -l
8a86ef73e44067bca52cc3f6cd3e5446c783391c /tmp/a.out
ebe71fdcf4b366518cc154d570a33cd461a51c36 /tmp/a.out.1
# perf buildid-cache -P -v
Removing /tmp/a.out (8a86ef73e44067bca52cc3f6cd3e5446c783391c): Ok
Removing /tmp/a.out.1 (ebe71fdcf4b366518cc154d570a33cd461a51c36): Ok
Purged all: Ok

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-4-ravi.bangoria@linux.vnet.ibm.com
[ Initialize 'err' in build_id_cache__purge_all(), to fix build on debian:7, as it can be used uninitialized ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ravi Bangoria and committed by
Arnaldo Carvalho de Melo
9a73c308 8e1e0d74

+38 -1
+3
tools/perf/Documentation/perf-buildid-cache.txt
··· 48 48 --purge=:: 49 49 Purge all cached binaries including older caches which have specified 50 50 path from the cache. 51 + -P:: 52 + --purge-all:: 53 + Purge all cached binaries. This will flush out entire cache. 51 54 -M:: 52 55 --missing=:: 53 56 List missing build ids in the cache for the specified file.
+35 -1
tools/perf/builtin-buildid-cache.c
··· 240 240 return err; 241 241 } 242 242 243 + static int build_id_cache__purge_all(void) 244 + { 245 + struct strlist *list; 246 + struct str_node *pos; 247 + int err = 0; 248 + char *buf; 249 + 250 + list = build_id_cache__list_all(false); 251 + if (!list) { 252 + pr_debug("Failed to get buildids: -%d\n", errno); 253 + return -EINVAL; 254 + } 255 + 256 + strlist__for_each_entry(pos, list) { 257 + buf = build_id_cache__origname(pos->s); 258 + err = build_id_cache__remove_s(pos->s); 259 + pr_debug("Removing %s (%s): %s\n", buf, pos->s, 260 + err ? "FAIL" : "Ok"); 261 + free(buf); 262 + if (err) 263 + break; 264 + } 265 + strlist__delete(list); 266 + 267 + pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok"); 268 + return err; 269 + } 270 + 243 271 static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) 244 272 { 245 273 char filename[PATH_MAX]; ··· 355 327 bool force = false; 356 328 bool list_files = false; 357 329 bool opts_flag = false; 330 + bool purge_all = false; 358 331 char const *add_name_list_str = NULL, 359 332 *remove_name_list_str = NULL, 360 333 *purge_name_list_str = NULL, ··· 379 350 "file(s) to remove"), 380 351 OPT_STRING('p', "purge", &purge_name_list_str, "file list", 381 352 "file(s) to remove (remove old caches too)"), 353 + OPT_BOOLEAN('P', "purge-all", &purge_all, "purge all cached files"), 382 354 OPT_BOOLEAN('l', "list", &list_files, "list all cached files"), 383 355 OPT_STRING('M', "missing", &missing_filename, "file", 384 356 "to find missing build ids in the cache"), ··· 400 370 401 371 opts_flag = add_name_list_str || kcore_filename || 402 372 remove_name_list_str || purge_name_list_str || 403 - missing_filename || update_name_list_str; 373 + missing_filename || update_name_list_str || 374 + purge_all; 404 375 405 376 if (argc || !(list_files || opts_flag)) 406 377 usage_with_options(buildid_cache_usage, buildid_cache_options); ··· 487 456 strlist__delete(list); 488 457 } 489 458 } 459 + 460 + if (purge_all) 461 + ret = build_id_cache__purge_all(); 490 462 491 463 if (missing_filename) 492 464 ret = build_id_cache__fprintf_missing(session, stdout);