All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options
@ 2018-04-17  4:13 Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages Ravi Bangoria
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Ravi Bangoria @ 2018-04-17  4:13 UTC (permalink / raw)
  To: mhiramat, jolsa, acme
  Cc: kstewart, tglx, pombredanne, linux-kernel, peterz, mingo,
	alexander.shishkin, namhyung, uneedsihyeon, kjlx, 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

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(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages
  2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
@ 2018-04-17  4:13 ` Ravi Bangoria
  2018-04-21  7:52   ` [tip:perf/urgent] perf tools: Add '\n' at the end of parse-options " tip-bot for Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 2/3] perf/buildid-cache: Support --list option Ravi Bangoria
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Ravi Bangoria @ 2018-04-17  4:13 UTC (permalink / raw)
  To: mhiramat, jolsa, acme
  Cc: kstewart, tglx, pombredanne, linux-kernel, peterz, mingo,
	alexander.shishkin, namhyung, uneedsihyeon, kjlx, Ravi Bangoria

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.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/lib/subcmd/parse-options.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index f6a1babcbac4..cb7154eccbdc 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -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);
 		}
 	}
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/3] perf/buildid-cache: Support --list option
  2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages Ravi Bangoria
@ 2018-04-17  4:13 ` Ravi Bangoria
  2018-04-23  6:59   ` Masami Hiramatsu
  2018-05-02 17:39   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: Ravi Bangoria @ 2018-04-17  4:13 UTC (permalink / raw)
  To: mhiramat, jolsa, acme
  Cc: kstewart, tglx, pombredanne, linux-kernel, peterz, mingo,
	alexander.shishkin, namhyung, uneedsihyeon, kjlx, 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

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
index 73c2650bd0db..3f285ba6e1f9 100644
--- a/tools/perf/Documentation/perf-buildid-cache.txt
+++ b/tools/perf/Documentation/perf-buildid-cache.txt
@@ -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.
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 41db2cba77eb..fd0a08661b42 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -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) {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages Ravi Bangoria
  2018-04-17  4:13 ` [PATCH v2 2/3] perf/buildid-cache: Support --list option Ravi Bangoria
@ 2018-04-17  4:13 ` Ravi Bangoria
  2018-04-23  7:02   ` Masami Hiramatsu
                     ` (2 more replies)
  2018-04-17  7:57 ` [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Jiri Olsa
  2018-04-18  5:54 ` Masami Hiramatsu
  4 siblings, 3 replies; 16+ messages in thread
From: Ravi Bangoria @ 2018-04-17  4:13 UTC (permalink / raw)
  To: mhiramat, jolsa, acme
  Cc: kstewart, tglx, pombredanne, linux-kernel, peterz, mingo,
	alexander.shishkin, namhyung, uneedsihyeon, kjlx, 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

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
index 3f285ba6e1f9..f6de0952ff3c 100644
--- a/tools/perf/Documentation/perf-buildid-cache.txt
+++ b/tools/perf/Documentation/perf-buildid-cache.txt
@@ -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.
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index fd0a08661b42..d11226f76fbc 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -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);
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options
  2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
                   ` (2 preceding siblings ...)
  2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
@ 2018-04-17  7:57 ` Jiri Olsa
  2018-04-17 13:58   ` Arnaldo Carvalho de Melo
  2018-04-18  5:54 ` Masami Hiramatsu
  4 siblings, 1 reply; 16+ messages in thread
From: Jiri Olsa @ 2018-04-17  7:57 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: mhiramat, acme, kstewart, tglx, pombredanne, linux-kernel,
	peterz, mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

On Tue, Apr 17, 2018 at 09:43:43AM +0530, Ravi Bangoria wrote:
> 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.

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> 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(-)
> 
> -- 
> 2.14.3
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options
  2018-04-17  7:57 ` [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Jiri Olsa
@ 2018-04-17 13:58   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-04-17 13:58 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Ravi Bangoria, mhiramat, kstewart, tglx, pombredanne,
	linux-kernel, peterz, mingo, alexander.shishkin, namhyung,
	uneedsihyeon, kjlx

Em Tue, Apr 17, 2018 at 09:57:50AM +0200, Jiri Olsa escreveu:
> On Tue, Apr 17, 2018 at 09:43:43AM +0530, Ravi Bangoria wrote:
> > 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.
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

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

- Arnaldo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options
  2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
                   ` (3 preceding siblings ...)
  2018-04-17  7:57 ` [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Jiri Olsa
@ 2018-04-18  5:54 ` Masami Hiramatsu
  4 siblings, 0 replies; 16+ messages in thread
From: Masami Hiramatsu @ 2018-04-18  5:54 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: jolsa, acme, kstewart, tglx, pombredanne, linux-kernel, peterz,
	mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

On Tue, 17 Apr 2018 09:43:43 +0530
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:

> 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.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks,

> 
> 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(-)
> 
> -- 
> 2.14.3
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip:perf/urgent] perf tools: Add '\n' at the end of parse-options error messages
  2018-04-17  4:13 ` [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages Ravi Bangoria
@ 2018-04-21  7:52   ` tip-bot for Ravi Bangoria
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Ravi Bangoria @ 2018-04-21  7:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, jolsa, tglx, pombredanne, uneedsihyeon, ravi.bangoria,
	alexander.shishkin, linux-kernel, mhiramat, kstewart, hpa,
	namhyung, kjlx, acme, peterz

Commit-ID:  66f5a0779af2a4f28b1832f6c20bc9d3b1ab1886
Gitweb:     https://git.kernel.org/tip/66f5a0779af2a4f28b1832f6c20bc9d3b1ab1886
Author:     Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
AuthorDate: Tue, 17 Apr 2018 09:43:44 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
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.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
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-2-ravi.bangoria@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/subcmd/parse-options.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index f6a1babcbac4..cb7154eccbdc 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -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);
 		}
 	}

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] perf/buildid-cache: Support --list option
  2018-04-17  4:13 ` [PATCH v2 2/3] perf/buildid-cache: Support --list option Ravi Bangoria
@ 2018-04-23  6:59   ` Masami Hiramatsu
  2018-05-02 17:39   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
  1 sibling, 0 replies; 16+ messages in thread
From: Masami Hiramatsu @ 2018-04-23  6:59 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: jolsa, acme, kstewart, tglx, pombredanne, linux-kernel, peterz,
	mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

On Tue, 17 Apr 2018 09:43:45 +0530
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:

> 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.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!

> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
> ---
>  tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
>  tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
>  2 files changed, 43 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
> index 73c2650bd0db..3f285ba6e1f9 100644
> --- a/tools/perf/Documentation/perf-buildid-cache.txt
> +++ b/tools/perf/Documentation/perf-buildid-cache.txt
> @@ -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.
> diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
> index 41db2cba77eb..fd0a08661b42 100644
> --- a/tools/perf/builtin-buildid-cache.c
> +++ b/tools/perf/builtin-buildid-cache.c
> @@ -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) {
> -- 
> 2.14.3
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
@ 2018-04-23  7:02   ` Masami Hiramatsu
  2018-05-03  8:54     ` Ravi Bangoria
  2018-04-23 18:59   ` Arnaldo Carvalho de Melo
  2018-05-02 17:40   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
  2 siblings, 1 reply; 16+ messages in thread
From: Masami Hiramatsu @ 2018-04-23  7:02 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: jolsa, acme, kstewart, tglx, pombredanne, linux-kernel, peterz,
	mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

On Tue, 17 Apr 2018 09:43:46 +0530
Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:

> 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>
> ---
>  tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
>  tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
>  2 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
> index 3f285ba6e1f9..f6de0952ff3c 100644
> --- a/tools/perf/Documentation/perf-buildid-cache.txt
> +++ b/tools/perf/Documentation/perf-buildid-cache.txt
> @@ -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.
> diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
> index fd0a08661b42..d11226f76fbc 100644
> --- a/tools/perf/builtin-buildid-cache.c
> +++ b/tools/perf/builtin-buildid-cache.c
> @@ -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");

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

Thanks,

> +	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);
>  
> -- 
> 2.14.3
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
  2018-04-23  7:02   ` Masami Hiramatsu
@ 2018-04-23 18:59   ` Arnaldo Carvalho de Melo
  2018-05-02 17:40   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
  2 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-04-23 18:59 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: mhiramat, jolsa, acme, kstewart, tglx, pombredanne, linux-kernel,
	peterz, mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

Em Tue, Apr 17, 2018 at 09:43:46AM +0530, Ravi Bangoria escreveu:
> 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>
> ---
>  tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
>  tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
>  2 files changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
> index 3f285ba6e1f9..f6de0952ff3c 100644
> --- a/tools/perf/Documentation/perf-buildid-cache.txt
> +++ b/tools/perf/Documentation/perf-buildid-cache.txt
> @@ -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.
> diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
> index fd0a08661b42..d11226f76fbc 100644
> --- a/tools/perf/builtin-buildid-cache.c
> +++ b/tools/perf/builtin-buildid-cache.c
> @@ -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;
> +}

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip:perf/core] perf buildid-cache: Support --list option
  2018-04-17  4:13 ` [PATCH v2 2/3] perf/buildid-cache: Support --list option Ravi Bangoria
  2018-04-23  6:59   ` Masami Hiramatsu
@ 2018-05-02 17:39   ` tip-bot for Ravi Bangoria
  1 sibling, 0 replies; 16+ messages in thread
From: tip-bot for Ravi Bangoria @ 2018-05-02 17:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, acme, tglx, kjlx, pombredanne, peterz, linux-kernel, jolsa,
	uneedsihyeon, ravi.bangoria, mhiramat, namhyung,
	alexander.shishkin, kstewart, mingo

Commit-ID:  8e1e0d74672f84e6c4b1e26ce2bb2e529aaf8676
Gitweb:     https://git.kernel.org/tip/8e1e0d74672f84e6c4b1e26ce2bb2e529aaf8676
Author:     Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
AuthorDate: Tue, 17 Apr 2018 09:43:45 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
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

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>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
index 73c2650bd0db..3f285ba6e1f9 100644
--- a/tools/perf/Documentation/perf-buildid-cache.txt
+++ b/tools/perf/Documentation/perf-buildid-cache.txt
@@ -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.
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 41db2cba77eb..fd0a08661b42 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -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) {

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip:perf/core] perf buildid-cache: Support --purge-all option
  2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
  2018-04-23  7:02   ` Masami Hiramatsu
  2018-04-23 18:59   ` Arnaldo Carvalho de Melo
@ 2018-05-02 17:40   ` tip-bot for Ravi Bangoria
  2 siblings, 0 replies; 16+ messages in thread
From: tip-bot for Ravi Bangoria @ 2018-05-02 17:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, uneedsihyeon, acme, ravi.bangoria, jolsa,
	mhiramat, namhyung, tglx, mingo, kjlx, hpa, kstewart,
	linux-kernel, pombredanne, peterz

Commit-ID:  9a73c308542bea74df921e9bb9fb07d39bbf2cfa
Gitweb:     https://git.kernel.org/tip/9a73c308542bea74df921e9bb9fb07d39bbf2cfa
Author:     Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
AuthorDate: Tue, 17 Apr 2018 09:43:46 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
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

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>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt
index 3f285ba6e1f9..f6de0952ff3c 100644
--- a/tools/perf/Documentation/perf-buildid-cache.txt
+++ b/tools/perf/Documentation/perf-buildid-cache.txt
@@ -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.
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index fd0a08661b42..7a7403913b57 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -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);
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-04-23  7:02   ` Masami Hiramatsu
@ 2018-05-03  8:54     ` Ravi Bangoria
  2018-05-08 15:42       ` Masami Hiramatsu
  0 siblings, 1 reply; 16+ messages in thread
From: Ravi Bangoria @ 2018-05-03  8:54 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ravi Bangoria, jolsa, acme, kstewart, tglx, pombredanne,
	linux-kernel, peterz, mingo, alexander.shishkin, namhyung,
	uneedsihyeon, kjlx

Hi Masami,

On 04/23/2018 12:32 PM, Masami Hiramatsu wrote:
> On Tue, 17 Apr 2018 09:43:46 +0530
> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>
>> +	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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-05-03  8:54     ` Ravi Bangoria
@ 2018-05-08 15:42       ` Masami Hiramatsu
  2018-05-09  6:00         ` Ravi Bangoria
  0 siblings, 1 reply; 16+ messages in thread
From: Masami Hiramatsu @ 2018-05-08 15:42 UTC (permalink / raw)
  To: Ravi Bangoria
  Cc: jolsa, acme, kstewart, tglx, pombredanne, linux-kernel, peterz,
	mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx

On Thu, 3 May 2018 14:24:04 +0530
Ravi Bangoria <ravi.bangoria@linux.ibm.com> wrote:

> Hi Masami,
> 
> On 04/23/2018 12:32 PM, Masami Hiramatsu wrote:
> > On Tue, 17 Apr 2018 09:43:46 +0530
> > Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
> >
> >> +	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,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option
  2018-05-08 15:42       ` Masami Hiramatsu
@ 2018-05-09  6:00         ` Ravi Bangoria
  0 siblings, 0 replies; 16+ messages in thread
From: Ravi Bangoria @ 2018-05-09  6:00 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: jolsa, acme, kstewart, tglx, pombredanne, linux-kernel, peterz,
	mingo, alexander.shishkin, namhyung, uneedsihyeon, kjlx,
	Ravi Bangoria



On 05/08/2018 09:12 PM, Masami Hiramatsu wrote:
> On Thu, 3 May 2018 14:24:04 +0530
> Ravi Bangoria <ravi.bangoria@linux.ibm.com> wrote:
>
>> Hi Masami,
>>
>> On 04/23/2018 12:32 PM, Masami Hiramatsu wrote:
>>> On Tue, 17 Apr 2018 09:43:46 +0530
>>> Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> wrote:
>>>
>>>> +	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

>
> 	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,
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-05-09  6:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17  4:13 [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Ravi Bangoria
2018-04-17  4:13 ` [PATCH v2 1/3] tools/parse-options: Add '\n' at the end of error messages Ravi Bangoria
2018-04-21  7:52   ` [tip:perf/urgent] perf tools: Add '\n' at the end of parse-options " tip-bot for Ravi Bangoria
2018-04-17  4:13 ` [PATCH v2 2/3] perf/buildid-cache: Support --list option Ravi Bangoria
2018-04-23  6:59   ` Masami Hiramatsu
2018-05-02 17:39   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
2018-04-17  4:13 ` [PATCH v2 3/3] perf/buildid-cache: Support --purge-all option Ravi Bangoria
2018-04-23  7:02   ` Masami Hiramatsu
2018-05-03  8:54     ` Ravi Bangoria
2018-05-08 15:42       ` Masami Hiramatsu
2018-05-09  6:00         ` Ravi Bangoria
2018-04-23 18:59   ` Arnaldo Carvalho de Melo
2018-05-02 17:40   ` [tip:perf/core] perf buildid-cache: " tip-bot for Ravi Bangoria
2018-04-17  7:57 ` [PATCH v2 0/3] perf/buildid-cache: Add --list and --purge-all options Jiri Olsa
2018-04-17 13:58   ` Arnaldo Carvalho de Melo
2018-04-18  5:54 ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.