Skip to contentSkip to conversation

perf/buildid-cache: Add --list and --purge-all options

PATCH Applied Ravi Bangoria 7 participants 16 messages Apr 17, 2018 – May 9, 2018 perf events

lore
Share & tools
lore
#0 lore raw

v2 cover perf/buildid-cache: Add --list and --purge-all options

First patch is a trivial error message fix. Second and third adds new options --list and --purge-all to 'buildid-cache' subcommand.

v2 changes:
- [PATCH v2 2/3] Display optput of 'perf buildid-cache -l' same as 'perf buildid-list'.
- [PATCH v2 2/3] Other minor changes as suggested by Jiri.

v1 can be found at:
https://lkml.org/lkml/2018/4/9/295

Ravi Bangoria (3):
tools/parse-options: Add '\n' at the end of error messages perf/buildid-cache: Support --list option perf/buildid-cache: Support --purge-all option

 tools/lib/subcmd/parse-options.c                |  6 +-
 tools/perf/Documentation/perf-buildid-cache.txt |  7 ++-
 tools/perf/builtin-buildid-cache.c              | 77 ++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 7 deletions(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH v2 1/3 tools/parse-options: Add '\n' at the end of error messages

Few error messages does not have '\n' at the end and thus next prompt gets printed in the same line. Ex,

linux~$ perf buildid-cache -verbose --add ./a.out
Error: did you mean --verbose (with two dashes ?)linux~$

Fix it.

---
 tools/lib/subcmd/parse-options.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/lib/subcmd/parse-options.c +3 -3
index f6a1babcbac4..cb7154eccbdc 100644
@@ -433,7 +433,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 
 	if (ambiguous_option) {
 		 fprintf(stderr,
-			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)",
+			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)\n",
 			 arg,
 			 (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
 			 ambiguous_option->long_name,
@@ -458,7 +458,7 @@ static void check_typos(const char *arg, const struct option *options)
 		return;
 
 	if (strstarts(arg, "no-")) {
-		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
+		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)\n", arg);
 		exit(129);
 	}
 
@@ -466,7 +466,7 @@ static void check_typos(const char *arg, const struct option *options)
 		if (!options->long_name)
 			continue;
 		if (strstarts(options->long_name, arg)) {
-			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
+			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)\n", arg);
 			exit(129);
 		}
 	}
Signature · 1 line
2.14.3
#2 lore raw

[tip:perf/urgent] perf tools: Add '\n' at the end of parse-options error messages

perf tools: Add '\n' at the end of parse-options error messages
Commit-ID:  66f5a0779af2a4f28b1832f6c20bc9d3b1ab1886
Gitweb:     https://git.kernel.org/tip/66f5a0779af2a4f28b1832f6c20bc9d3b1ab1886
Author:     Ravi Bangoria <[email protected]>
AuthorDate: Tue, 17 Apr 2018 09:43:44 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 18 Apr 2018 15:35:51 -0300

perf tools: Add '\n' at the end of parse-options error messages

Few error messages does not have '\n' at the end and thus next prompt gets printed in the same line. Ex,

linux~$ perf buildid-cache -verbose --add ./a.out
Error: did you mean --verbose (with two dashes ?)linux~$

Fix it.

Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kate Stewart <[email protected]>
Cc Krister Johansen <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Sihyeon Jang <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/lib/subcmd/parse-options.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/lib/subcmd/parse-options.c +3 -3
index f6a1babcbac4..cb7154eccbdc 100644
@@ -433,7 +433,7 @@ match:
 
 	if (ambiguous_option) {
 		 fprintf(stderr,
-			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)",
+			 " Error: Ambiguous option: %s (could be --%s%s or --%s%s)\n",
 			 arg,
 			 (ambiguous_flags & OPT_UNSET) ?  "no-" : "",
 			 ambiguous_option->long_name,
@@ -458,7 +458,7 @@ static void check_typos(const char *arg, const struct option *options)
 		return;
 
 	if (strstarts(arg, "no-")) {
-		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
+		fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)\n", arg);
 		exit(129);
 	}
 
@@ -466,7 +466,7 @@ static void check_typos(const char *arg, const struct option *options)
 		if (!options->long_name)
 			continue;
 		if (strstarts(options->long_name, arg)) {
-			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
+			fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)\n", arg);
 			exit(129);
 		}
 	}
#3 lore raw

PATCH v2 2/3 perf/buildid-cache: Support --list option

In reply to Ravi Bangoria

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
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -1
index 73c2650bd0db..3f285ba6e1f9 100644
@@ -59,7 +59,9 @@ OPTIONS
 	exactly same build-id, that is replaced by new one. It can be used
 	to update kallsyms and kernel dso to vmlinux in order to support
 	annotation.
-
+-l::
+--list::
+	List all valid binaries from cache.
 -v::
 --verbose::
 	Be more verbose.
tools/perf/builtin-buildid-cache.c +40 -3

81 lines not on this page · raw message

Signature · 1 line
2.14.3
Acked-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] perf/buildid-cache: Support --list option

Quoted 9 lines · On Tue, 17 Apr 2018 09:43:45 +0530 Ravi Bangoria…

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

Looks good to me.

Thanks!

Quoted 115 lines
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -1
index 73c2650bd0db..3f285ba6e1f9 100644
@@ -59,7 +59,9 @@ OPTIONS
 	exactly same build-id, that is replaced by new one. It can be used
 	to update kallsyms and kernel dso to vmlinux in order to support
 	annotation.
-
+-l::
+--list::
+	List all valid binaries from cache.
 -v::
 --verbose::
 	Be more verbose.
tools/perf/builtin-buildid-cache.c +40 -3
index 41db2cba77eb..fd0a08661b42 100644
@@ -25,6 +25,7 @@
 #include "util/session.h"
 #include "util/symbol.h"
 #include "util/time-utils.h"
+#include "util/probe-file.h"
 
 static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
 {
@@ -297,6 +298,26 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
 	return err;
 }
 
+static int build_id_cache__show_all(void)
+{
+	struct strlist *bidlist;
+	struct str_node *nd;
+	char *buf;
+
+	bidlist = build_id_cache__list_all(true);
+	if (!bidlist) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -1;
+	}
+	strlist__for_each_entry(nd, bidlist) {
+		buf = build_id_cache__origname(nd->s);
+		fprintf(stdout, "%s %s\n", nd->s, buf);
+		free(buf);
+	}
+	strlist__delete(bidlist);
+	return 0;
+}
+
 int cmd_buildid_cache(int argc, const char **argv)
 {
 	struct strlist *list;
@@ -304,6 +325,8 @@ int cmd_buildid_cache(int argc, const char **argv)
 	int ret = 0;
 	int ns_id = -1;
 	bool force = false;
+	bool list_files = false;
+	bool opts_flag = false;
 	char const *add_name_list_str = NULL,
 		   *remove_name_list_str = NULL,
 		   *purge_name_list_str = NULL,
@@ -327,6 +350,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 		    "file(s) to remove"),
 	OPT_STRING('p', "purge", &purge_name_list_str, "file list",
 		    "file(s) to remove (remove old caches too)"),
+	OPT_BOOLEAN('l', "list", &list_files, "list all cached files"),
 	OPT_STRING('M', "missing", &missing_filename, "file",
 		   "to find missing build ids in the cache"),
 	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
@@ -344,11 +368,19 @@ int cmd_buildid_cache(int argc, const char **argv)
 	argc = parse_options(argc, argv, buildid_cache_options,
 			     buildid_cache_usage, 0);
 
-	if (argc || (!add_name_list_str && !kcore_filename &&
-		     !remove_name_list_str && !purge_name_list_str &&
-		     !missing_filename && !update_name_list_str))
+	opts_flag = add_name_list_str || kcore_filename ||
+		remove_name_list_str || purge_name_list_str ||
+		missing_filename || update_name_list_str;
+
+	if (argc || !(list_files || opts_flag))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
 
+	/* -l is exclusive. It can not be used with other options. */
+	if (list_files && opts_flag) {
+		usage_with_options_msg(buildid_cache_usage,
+			buildid_cache_options, "-l is exclusive.\n");
+	}
+
 	if (ns_id > 0)
 		nsi = nsinfo__new(ns_id);
 
@@ -366,6 +398,11 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 	setup_pager();
 
+	if (list_files) {
+		ret = build_id_cache__show_all();
+		goto out;
+	}
+
 	if (add_name_list_str) {
 		list = strlist__new(add_name_list_str, NULL);
 		if (list) {
Signature · 1 line
2.14.3
Signature · 1 line
Masami Hiramatsu <[email protected]>
#5 lore raw

[tip:perf/core] perf buildid-cache: Support --list option

In reply to Ravi Bangoria
perf buildid-cache: Support --list option
Commit-ID:  8e1e0d74672f84e6c4b1e26ce2bb2e529aaf8676
Gitweb:     https://git.kernel.org/tip/8e1e0d74672f84e6c4b1e26ce2bb2e529aaf8676
Author:     Ravi Bangoria <[email protected]>
AuthorDate: Tue, 17 Apr 2018 09:43:45 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Apr 2018 09:30:26 -0300

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
Cc Alexander Shishkin <[email protected]>
Cc Kate Stewart <[email protected]>
Cc Krister Johansen <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Sihyeon Jang <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -1
index 73c2650bd0db..3f285ba6e1f9 100644
@@ -59,7 +59,9 @@ OPTIONS
 	exactly same build-id, that is replaced by new one. It can be used
 	to update kallsyms and kernel dso to vmlinux in order to support
 	annotation.
-
+-l::
+--list::
+	List all valid binaries from cache.
 -v::
 --verbose::
 	Be more verbose.
tools/perf/builtin-buildid-cache.c +40 -3

81 lines not on this page · raw message

#6 lore raw

PATCH v2 3/3 perf/buildid-cache: Support --purge-all option

In reply to Ravi Bangoria

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
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -0
index 3f285ba6e1f9..f6de0952ff3c 100644
@@ -48,6 +48,9 @@ OPTIONS
 --purge=::
         Purge all cached binaries including older caches which have specified
 	path from the cache.
+-P::
+--purge-all::
+	Purge all cached binaries. This will flush out entire cache.
 -M::
 --missing=::
 	List missing build ids in the cache for the specified file.
tools/perf/builtin-buildid-cache.c +35 -1
index fd0a08661b42..d11226f76fbc 100644
@@ -240,6 +240,34 @@ static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi)
 	return err;
 }
 
+static int build_id_cache__purge_all(void)
+{
+	struct strlist *list;
+	struct str_node *pos;
+	int err;
+	char *buf;
+
+	list = build_id_cache__list_all(false);
+	if (!list) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -EINVAL;
+	}
+
+	strlist__for_each_entry(pos, list) {
+		buf = build_id_cache__origname(pos->s);
+		err = build_id_cache__remove_s(pos->s);
+		pr_debug("Removing %s (%s): %s\n", buf, pos->s,
+			 err ? "FAIL" : "Ok");
+		free(buf);
+		if (err)
+			break;
+	}
+	strlist__delete(list);
+
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");
+	return err;
+}
+
 static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
 {
 	char filename[PATH_MAX];
@@ -327,6 +355,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 	bool force = false;
 	bool list_files = false;
 	bool opts_flag = false;
+	bool purge_all = false;
 	char const *add_name_list_str = NULL,
 		   *remove_name_list_str = NULL,
 		   *purge_name_list_str = NULL,
@@ -350,6 +379,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 		    "file(s) to remove"),
 	OPT_STRING('p', "purge", &purge_name_list_str, "file list",
 		    "file(s) to remove (remove old caches too)"),
+	OPT_BOOLEAN('P', "purge-all", &purge_all, "purge all cached files"),
 	OPT_BOOLEAN('l', "list", &list_files, "list all cached files"),
 	OPT_STRING('M', "missing", &missing_filename, "file",
 		   "to find missing build ids in the cache"),
@@ -370,7 +400,8 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 	opts_flag = add_name_list_str || kcore_filename ||
 		remove_name_list_str || purge_name_list_str ||
-		missing_filename || update_name_list_str;
+		missing_filename || update_name_list_str ||
+		purge_all;
 
 	if (argc || !(list_files || opts_flag))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
@@ -457,6 +488,9 @@ int cmd_buildid_cache(int argc, const char **argv)
 		}
 	}
 
+	if (purge_all)
+		ret = build_id_cache__purge_all();
+
 	if (missing_filename)
 		ret = build_id_cache__fprintf_missing(session, stdout);
 
Signature · 1 line
2.14.3
#7 lore raw

Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option

Quoted 57 lines · On Tue, 17 Apr 2018 09:43:46 +0530 Ravi Bangoria…

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
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -0
index 3f285ba6e1f9..f6de0952ff3c 100644
@@ -48,6 +48,9 @@ OPTIONS
 --purge=::
         Purge all cached binaries including older caches which have specified
 	path from the cache.
+-P::
+--purge-all::
+	Purge all cached binaries. This will flush out entire cache.
 -M::
 --missing=::
 	List missing build ids in the cache for the specified file.
tools/perf/builtin-buildid-cache.c +15 -0
index fd0a08661b42..d11226f76fbc 100644
@@ -240,6 +240,34 @@ static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi)
 	return err;
 }
 
+static int build_id_cache__purge_all(void)
+{
+	struct strlist *list;
+	struct str_node *pos;
+	int err;
+	char *buf;
+
+	list = build_id_cache__list_all(false);
+	if (!list) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -EINVAL;
+	}
+
+	strlist__for_each_entry(pos, list) {
+		buf = build_id_cache__origname(pos->s);

tools/perf/builtin-buildid-cache.c static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) · line 267

Quoted 10 lines
tools/perf/builtin-buildid-cache.c +10 -0
+		err = build_id_cache__remove_s(pos->s);
+		pr_debug("Removing %s (%s): %s\n", buf, pos->s,
+			 err ? "FAIL" : "Ok");
+		free(buf);
+		if (err)
+			break;
+	}
+	strlist__delete(list);
+
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");

Hmm, I think this should use pr_info(or pr_warning), at least for Failure case.

Thanks,

Quoted 45 lines
tools/perf/builtin-buildid-cache.c +10 -1
+	return err;
+}
+
 static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
 {
 	char filename[PATH_MAX];
@@ -327,6 +355,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 	bool force = false;
 	bool list_files = false;
 	bool opts_flag = false;
+	bool purge_all = false;
 	char const *add_name_list_str = NULL,
 		   *remove_name_list_str = NULL,
 		   *purge_name_list_str = NULL,
@@ -350,6 +379,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 		    "file(s) to remove"),
 	OPT_STRING('p', "purge", &purge_name_list_str, "file list",
 		    "file(s) to remove (remove old caches too)"),
+	OPT_BOOLEAN('P', "purge-all", &purge_all, "purge all cached files"),
 	OPT_BOOLEAN('l', "list", &list_files, "list all cached files"),
 	OPT_STRING('M', "missing", &missing_filename, "file",
 		   "to find missing build ids in the cache"),
@@ -370,7 +400,8 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 	opts_flag = add_name_list_str || kcore_filename ||
 		remove_name_list_str || purge_name_list_str ||
-		missing_filename || update_name_list_str;
+		missing_filename || update_name_list_str ||
+		purge_all;
 
 	if (argc || !(list_files || opts_flag))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
@@ -457,6 +488,9 @@ int cmd_buildid_cache(int argc, const char **argv)
 		}
 	}
 
+	if (purge_all)
+		ret = build_id_cache__purge_all();
+
 	if (missing_filename)
 		ret = build_id_cache__fprintf_missing(session, stdout);
 
Signature · 1 line
2.14.3
Signature · 1 line
Masami Hiramatsu <[email protected]>
#8 lore raw

Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option

Hi Masami,

Quoted 5 lines · Masami Hiramatsu

tools/perf/builtin-buildid-cache.c static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) · line 267

Quoted 1 line · On Tue, 17 Apr 2018 09:43:46 +0530 Ravi Bangoria…
tools/perf/builtin-buildid-cache.c +1 -0
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");

Hmm, I think this should use pr_info(or pr_warning), at least for Failure case.

Actually, I followed what is already there for other options.

Thanks,
Ravi

#9 lore raw

Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option

Quoted 10 lines · On Thu, 3 May 2018 14:24:04 +0530 Ravi Bangoria <[email protected]>…

Hi Masami,

Quoted 5 lines · Masami Hiramatsu

tools/perf/builtin-buildid-cache.c static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) · line 267

Quoted 1 line · On Tue, 17 Apr 2018 09:43:46 +0530 Ravi Bangoria…
tools/perf/builtin-buildid-cache.c +1 -0
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");

Hmm, I think this should use pr_info(or pr_warning), at least for Failure case.

Actually, I followed what is already there for other options.

Please see cmd_buildid_cache(), if we failed to purge one buildid-cache, it is warned with pr_warning.

	if (purge_name_list_str) {
		list = strlist__new(purge_name_list_str, NULL);
		if (list) {
			strlist__for_each_entry(pos, list)
				if (build_id_cache__purge_path(pos->s, nsi)) {
					if (errno == ENOENT) {
						pr_debug("%s wasn't in the cache\n",
							 pos->s);
						continue;
					}
					pr_warning("Couldn't remove %s: %s\n",
						   pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
				}

			strlist__delete(list);
		}
	}

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
#10 lore raw

Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option

Quoted 6 lines · Masami Hiramatsu
Quoted 3 lines · On Thu, 3 May 2018 14:24:04 +0530 Ravi Bangoria <[email protected]>…

Hi Masami,

On 04/23/2018 12:32 PM, Masami Hiramatsu wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

tools/perf/builtin-buildid-cache.c static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) · line 267

Quoted 1 line · On Tue, 17 Apr 2018 09:43:46 +0530 Ravi Bangoria…
tools/perf/builtin-buildid-cache.c +1 -0
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");

Hmm, I think this should use pr_info(or pr_warning), at least for Failure case.

Actually, I followed what is already there for other options.

Please see cmd_buildid_cache(), if we failed to purge one buildid-cache, it is warned with pr_warning.

Oh ok. I thought you are asking me to change pr_debug(). I'll quickly prepare and send a patch.

Thanks,
Ravi

Quoted 21 lines
	if (purge_name_list_str) {
		list = strlist__new(purge_name_list_str, NULL);
		if (list) {
			strlist__for_each_entry(pos, list)
				if (build_id_cache__purge_path(pos->s, nsi)) {
					if (errno == ENOENT) {
						pr_debug("%s wasn't in the cache\n",
							 pos->s);
						continue;
					}
					pr_warning("Couldn't remove %s: %s\n",
						   pos->s, str_error_r(errno, sbuf, sizeof(sbuf)));
				}

			strlist__delete(list);
		}
	}

Thank you,

#11 lore raw

Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option

In reply to Ravi Bangoria

Em Tue, Apr 17, 2018 at 09:43:46AM +0530, Ravi Bangoria escreveu:

Quoted 59 lines

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
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -0
index 3f285ba6e1f9..f6de0952ff3c 100644
@@ -48,6 +48,9 @@ OPTIONS
 --purge=::
         Purge all cached binaries including older caches which have specified
 	path from the cache.
+-P::
+--purge-all::
+	Purge all cached binaries. This will flush out entire cache.
 -M::
 --missing=::
 	List missing build ids in the cache for the specified file.
tools/perf/builtin-buildid-cache.c +17 -0
index fd0a08661b42..d11226f76fbc 100644
@@ -240,6 +240,34 @@ static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi)
 	return err;
 }
 
+static int build_id_cache__purge_all(void)
+{
+	struct strlist *list;
+	struct str_node *pos;
+	int err;
+	char *buf;
+
+	list = build_id_cache__list_all(false);
+	if (!list) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -EINVAL;
+	}
+
+	strlist__for_each_entry(pos, list) {
+		buf = build_id_cache__origname(pos->s);
+		err = build_id_cache__remove_s(pos->s);
+		pr_debug("Removing %s (%s): %s\n", buf, pos->s,

tools/perf/builtin-buildid-cache.c static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi) · line 269

Quoted 10 lines
tools/perf/builtin-buildid-cache.c +10 -0
+			 err ? "FAIL" : "Ok");
+		free(buf);
+		if (err)
+			break;
+	}
+	strlist__delete(list);
+
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");
+	return err;
+}

err may be used uninitialized, and debian:7 complains with:

CC /tmp/build/perf/util/ctype.o
builtin-buildid-cache.c: In function 'cmd_buildid_cache':
builtin-buildid-cache.c:267:2: error: 'err' may be used uninitialized in this function [-Werror=uninitialized] builtin-buildid-cache.c:247:6: note: 'err' was declared here
MKDIR /tmp/build/perf/util/
cc1: all warnings being treated as errors
CC /tmp/build/perf/util/db-export.o
mv: cannot stat `/tmp/build/perf/.builtin-buildid-cache.o.tmp': No such file or directory make[3]: *** [/tmp/build/perf/builtin-buildid-cache.o] Error 1
make[3]: *** Waiting for unfinished jobs....

I'm initializing it to zero.

- Arnaldo

#12 lore raw

[tip:perf/core] perf buildid-cache: Support --purge-all option

In reply to Ravi Bangoria
perf buildid-cache: Support --purge-all option
Commit-ID:  9a73c308542bea74df921e9bb9fb07d39bbf2cfa
Gitweb:     https://git.kernel.org/tip/9a73c308542bea74df921e9bb9fb07d39bbf2cfa
Author:     Ravi Bangoria <[email protected]>
AuthorDate: Tue, 17 Apr 2018 09:43:46 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Apr 2018 09:30:26 -0300

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
Cc Alexander Shishkin <[email protected]>
Cc Kate Stewart <[email protected]>
Cc Krister Johansen <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Sihyeon Jang <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Initialize 'err' in build_id_cache__purge_all(), to fix build on debian:7, as it can be used uninitialized ]
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -0
index 3f285ba6e1f9..f6de0952ff3c 100644
@@ -48,6 +48,9 @@ OPTIONS
 --purge=::
         Purge all cached binaries including older caches which have specified
 	path from the cache.
+-P::
+--purge-all::
+	Purge all cached binaries. This will flush out entire cache.
 -M::
 --missing=::
 	List missing build ids in the cache for the specified file.
tools/perf/builtin-buildid-cache.c +35 -1
index fd0a08661b42..7a7403913b57 100644
@@ -240,6 +240,34 @@ out:
 	return err;
 }
 
+static int build_id_cache__purge_all(void)
+{
+	struct strlist *list;
+	struct str_node *pos;
+	int err = 0;
+	char *buf;
+
+	list = build_id_cache__list_all(false);
+	if (!list) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -EINVAL;
+	}
+
+	strlist__for_each_entry(pos, list) {
+		buf = build_id_cache__origname(pos->s);
+		err = build_id_cache__remove_s(pos->s);
+		pr_debug("Removing %s (%s): %s\n", buf, pos->s,
+			 err ? "FAIL" : "Ok");
+		free(buf);
+		if (err)
+			break;
+	}
+	strlist__delete(list);
+
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");
+	return err;
+}
+
 static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
 {
 	char filename[PATH_MAX];
@@ -327,6 +355,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 	bool force = false;
 	bool list_files = false;
 	bool opts_flag = false;
+	bool purge_all = false;
 	char const *add_name_list_str = NULL,
 		   *remove_name_list_str = NULL,
 		   *purge_name_list_str = NULL,
@@ -350,6 +379,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 		    "file(s) to remove"),
 	OPT_STRING('p', "purge", &purge_name_list_str, "file list",
 		    "file(s) to remove (remove old caches too)"),
+	OPT_BOOLEAN('P', "purge-all", &purge_all, "purge all cached files"),
 	OPT_BOOLEAN('l', "list", &list_files, "list all cached files"),
 	OPT_STRING('M', "missing", &missing_filename, "file",
 		   "to find missing build ids in the cache"),
@@ -370,7 +400,8 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 	opts_flag = add_name_list_str || kcore_filename ||
 		remove_name_list_str || purge_name_list_str ||
-		missing_filename || update_name_list_str;
+		missing_filename || update_name_list_str ||
+		purge_all;
 
 	if (argc || !(list_files || opts_flag))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
@@ -457,6 +488,9 @@ int cmd_buildid_cache(int argc, const char **argv)
 		}
 	}
 
+	if (purge_all)
+		ret = build_id_cache__purge_all();
+
 	if (missing_filename)
 		ret = build_id_cache__fprintf_missing(session, stdout);
 
Acked-by on the v2 series
#13 lore raw
In reply to Ravi Bangoria
Quoted 8 lines · Ravi Bangoria

First patch is a trivial error message fix. Second and third adds new options --list and --purge-all to 'buildid-cache' subcommand.

v2 changes:
- [PATCH v2 2/3] Display optput of 'perf buildid-cache -l' same as 'perf buildid-list'.
- [PATCH v2 2/3] Other minor changes as suggested by Jiri.

thanks,
jirka

Quoted 17 lines

v1 can be found at:
https://lkml.org/lkml/2018/4/9/295

Ravi Bangoria (3):
tools/parse-options: Add '\n' at the end of error messages perf/buildid-cache: Support --list option perf/buildid-cache: Support --purge-all option

 tools/lib/subcmd/parse-options.c                |  6 +-
 tools/perf/Documentation/perf-buildid-cache.txt |  7 ++-
 tools/perf/builtin-buildid-cache.c              | 77 ++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 7 deletions(-)
Signature · 1 line
2.14.3
#14 lore raw

Em Tue, Apr 17, 2018 at 09:57:50AM +0200, Jiri Olsa escreveu:

Quoted 11 lines · Ravi Bangoria
Quoted 8 lines

First patch is a trivial error message fix. Second and third adds new options --list and --purge-all to 'buildid-cache' subcommand.

v2 changes:
- [PATCH v2 2/3] Display optput of 'perf buildid-cache -l' same as 'perf buildid-list'.
- [PATCH v2 2/3] Other minor changes as suggested by Jiri.

Thanks, applied 1/3 to perf/urgent, 2-3/3 to perf/core.

- Arnaldo

Acked-by on the v2 series
#15 lore raw
In reply to Ravi Bangoria
Quoted 11 lines · On Tue, 17 Apr 2018 09:43:43 +0530 Ravi Bangoria…

First patch is a trivial error message fix. Second and third adds new options --list and --purge-all to 'buildid-cache' subcommand.

v2 changes:
- [PATCH v2 2/3] Display optput of 'perf buildid-cache -l' same as 'perf buildid-list'.
- [PATCH v2 2/3] Other minor changes as suggested by Jiri.

v1 can be found at:
https://lkml.org/lkml/2018/4/9/295

All patches in this series looks good to me.

Thanks,

Quoted 14 lines

Ravi Bangoria (3):
tools/parse-options: Add '\n' at the end of error messages perf/buildid-cache: Support --list option perf/buildid-cache: Support --purge-all option

 tools/lib/subcmd/parse-options.c                |  6 +-
 tools/perf/Documentation/perf-buildid-cache.txt |  7 ++-
 tools/perf/builtin-buildid-cache.c              | 77 ++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 7 deletions(-)
Signature · 1 line
2.14.3
Signature · 1 line
Masami Hiramatsu <[email protected]>