Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1496824 > unrolled thread
| Started by | Andi Kleen <andi@firstfloor.org> |
|---|---|
| First post | 2016-10-06 21:30 +0200 |
| Last post | 2016-10-06 22:10 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 1/3] perf, tools: Add support for perf list json Andi Kleen <andi@firstfloor.org> - 2016-10-06 21:30 +0200
[PATCH 3/3] perf, tools: Fix completion script to handle comma list Andi Kleen <andi@firstfloor.org> - 2016-10-06 21:30 +0200
Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-06 22:10 +0200
Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list Andi Kleen <ak@linux.intel.com> - 2016-10-06 22:10 +0200
Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-06 22:40 +0200
Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list Andi Kleen <ak@linux.intel.com> - 2016-10-06 22:50 +0200
Re: [PATCH 1/3] perf, tools: Add support for perf list json Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-06 22:10 +0200
| From | Andi Kleen <andi@firstfloor.org> |
|---|---|
| Date | 2016-10-06 21:30 +0200 |
| Subject | [PATCH 1/3] perf, tools: Add support for perf list json |
| Message-ID | <spmwF-5ch-5@gated-at.bofh.it> |
From: Andi Kleen <ak@linux.intel.com>
Add an argument to perf list to only list json events. To be used
for the command line completion script. This requires adding
a new flag to the alias structure.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/Documentation/perf-list.txt | 2 +-
tools/perf/builtin-list.c | 9 ++++++---
tools/perf/util/parse-events.c | 2 +-
tools/perf/util/pmu.c | 14 ++++++++++----
tools/perf/util/pmu.h | 3 ++-
5 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 41857cce5e86..50a35b27a64d 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types
SYNOPSIS
--------
[verse]
-'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|event_glob]
+'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|json|sdt|event_glob]
DESCRIPTION
-----------
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index ba9322ff858b..b9ccdc7ec733 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -32,7 +32,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_END()
};
const char * const list_usage[] = {
- "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
+ "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|json|event_glob]",
NULL
};
@@ -69,9 +69,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
print_hwcache_events(NULL, raw_dump);
else if (strcmp(argv[i], "pmu") == 0)
print_pmu_events(NULL, raw_dump, !desc_flag,
- long_desc_flag);
+ long_desc_flag, false);
else if (strcmp(argv[i], "sdt") == 0)
print_sdt_events(NULL, NULL, raw_dump);
+ else if (strcmp(argv[i], "json") == 0)
+ print_pmu_events(NULL, raw_dump, !desc_flag,
+ long_desc_flag, true);
else if ((sep = strchr(argv[i], ':')) != NULL) {
int sep_idx;
@@ -100,7 +103,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
print_hwcache_events(s, raw_dump);
print_pmu_events(s, raw_dump, !desc_flag,
- long_desc_flag);
+ long_desc_flag, false);
print_tracepoint_events(NULL, s, raw_dump);
print_sdt_events(NULL, s, raw_dump);
free(s);
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 4e778eae1510..948ef84e4c6a 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2275,7 +2275,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,
print_hwcache_events(event_glob, name_only);
- print_pmu_events(event_glob, name_only, quiet_flag, long_desc);
+ print_pmu_events(event_glob, name_only, quiet_flag, long_desc, false);
if (event_glob != NULL)
return;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b1474dcadfa2..d8d7d4c0319c 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -224,7 +224,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
char *desc, char *val, char *long_desc,
- char *topic)
+ char *topic, bool json)
{
struct perf_pmu_alias *alias;
int ret;
@@ -238,6 +238,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
alias->unit[0] = '\0';
alias->per_pkg = false;
alias->snapshot = false;
+ alias->json = json;
ret = parse_events_terms(&alias->terms, val);
if (ret) {
@@ -278,7 +279,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
buf[ret] = 0;
- return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL);
+ return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, false);
}
static inline bool pmu_alias_info_file(char *name)
@@ -537,7 +538,8 @@ static void pmu_add_cpu_aliases(struct list_head *head)
/* need type casts to override 'const' */
__perf_pmu__new_alias(head, NULL, (char *)pe->name,
(char *)pe->desc, (char *)pe->event,
- (char *)pe->long_desc, (char *)pe->topic);
+ (char *)pe->long_desc, (char *)pe->topic,
+ true);
}
out:
@@ -1103,7 +1105,7 @@ static void wordwrap(char *s, int start, int max, int corr)
}
void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
- bool long_desc)
+ bool long_desc, bool json_only)
{
struct perf_pmu *pmu;
struct perf_pmu_alias *alias;
@@ -1134,6 +1136,9 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
format_alias(buf, sizeof(buf), pmu, alias);
bool is_cpu = !strcmp(pmu->name, "cpu");
+ if (json_only && !alias->json)
+ continue;
+
if (event_glob != NULL &&
!(strglobmatch(name, event_glob) ||
(!is_cpu && strglobmatch(alias->name,
@@ -1158,6 +1163,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
j++;
}
if (pmu->selectable &&
+ !json_only &&
(event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
char *s;
if (asprintf(&s, "%s//", pmu->name) < 0)
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 25712034c815..19fa2e19dbe9 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -49,6 +49,7 @@ struct perf_pmu_alias {
double scale;
bool per_pkg;
bool snapshot;
+ bool json;
};
struct perf_pmu *perf_pmu__find(const char *name);
@@ -75,7 +76,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
- bool long_desc);
+ bool long_desc, bool json_only);
bool pmu_have_event(const char *pname, const char *name);
int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
--
2.5.5
[toc] | [next] | [standalone]
| From | Andi Kleen <andi@firstfloor.org> |
|---|---|
| Date | 2016-10-06 21:30 +0200 |
| Subject | [PATCH 3/3] perf, tools: Fix completion script to handle comma list |
| Message-ID | <spmwF-5ch-13@gated-at.bofh.it> |
| In reply to | #1496824 |
From: Andi Kleen <ak@linux.intel.com>
The perf event completion script only handled a single event per
-e option. So for "perf stat -e cycles,branches" branches could
not be completed.
Fix that issue by always only using the last suffix for completion.
For some reason it only works in bash currently, but zsh
is the same as before.
v2: Handle conflict with upper case completion patch
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/perf-completion.sh | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 3b5a258a4b7b..819a1346689f 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -166,7 +166,11 @@ __perf_main ()
[[:upper:]]*) evts=$($cmd list --raw-dump json | tr a-z A-Z) ;;
*) evts=$($cmd list --raw-dump) ;;
esac
+ old="$cur"
+ cur="${cur/*[,{]/}"
+ prefix=${old%$cur}
__perfcomp_colon "$evts" "$cur"
+ COMPREPLY=("${prefix}${COMPREPLY[0]}")
else
# List subcommands for perf commands
if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|
--
2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-10-06 22:10 +0200 |
| Subject | Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list |
| Message-ID | <spn9n-5J3-3@gated-at.bofh.it> |
| In reply to | #1496825 |
Em Thu, Oct 06, 2016 at 12:23:27PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
>
> The perf event completion script only handled a single event per
> -e option. So for "perf stat -e cycles,branches" branches could
> not be completed.
>
> Fix that issue by always only using the last suffix for completion.
>
> For some reason it only works in bash currently, but zsh
> is the same as before.
It works partially, for instance, if I try completing:
perf stat -e CPL<TAB>
I get:
perf stat -e CPL_CYCLES.RING0
but if I try:
perf stat -e cycles,CPL<TAB>
I get nothing :-\
Is this working with you?
> v2: Handle conflict with upper case completion patch
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
> tools/perf/perf-completion.sh | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
> index 3b5a258a4b7b..819a1346689f 100644
> --- a/tools/perf/perf-completion.sh
> +++ b/tools/perf/perf-completion.sh
> @@ -166,7 +166,11 @@ __perf_main ()
> [[:upper:]]*) evts=$($cmd list --raw-dump json | tr a-z A-Z) ;;
> *) evts=$($cmd list --raw-dump) ;;
> esac
> + old="$cur"
> + cur="${cur/*[,{]/}"
> + prefix=${old%$cur}
> __perfcomp_colon "$evts" "$cur"
> + COMPREPLY=("${prefix}${COMPREPLY[0]}")
> else
> # List subcommands for perf commands
> if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|
> --
> 2.5.5
[toc] | [prev] | [next] | [standalone]
| From | Andi Kleen <ak@linux.intel.com> |
|---|---|
| Date | 2016-10-06 22:10 +0200 |
| Subject | Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list |
| Message-ID | <spn9n-5J3-7@gated-at.bofh.it> |
| In reply to | #1496835 |
> perf stat -e CPL_CYCLES.RING0 > > but if I try: > > perf stat -e cycles,CPL<TAB> > > I get nothing :-\ > > Is this working with you? You can't mix cases like this, the upper case patch doesn't support that. It's either all upper or all lower case. If you continue with lower case it should work. -Andi
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-10-06 22:40 +0200 |
| Subject | Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list |
| Message-ID | <spnCq-5Wo-15@gated-at.bofh.it> |
| In reply to | #1496838 |
Em Thu, Oct 06, 2016 at 01:08:39PM -0700, Andi Kleen escreveu: > > perf stat -e CPL_CYCLES.RING0 > > > > but if I try: > > > > perf stat -e cycles,CPL<TAB> > > > > I get nothing :-\ > > > > Is this working with you? > > You can't mix cases like this, the upper case patch doesn't support that. > It's either all upper or all lower case. > > If you continue with lower case it should work. I understand that this should be a limitation of the current patch, but if we decide to support completion after a comma, I think people will expect that all events will be available :-\ - Arnaldo
[toc] | [prev] | [next] | [standalone]
| From | Andi Kleen <ak@linux.intel.com> |
|---|---|
| Date | 2016-10-06 22:50 +0200 |
| Subject | Re: [PATCH 3/3] perf, tools: Fix completion script to handle comma list |
| Message-ID | <spnM6-5ZP-7@gated-at.bofh.it> |
| In reply to | #1496856 |
On Thu, Oct 06, 2016 at 05:29:44PM -0300, Arnaldo Carvalho de Melo wrote: > Em Thu, Oct 06, 2016 at 01:08:39PM -0700, Andi Kleen escreveu: > > > perf stat -e CPL_CYCLES.RING0 > > > > > > but if I try: > > > > > > perf stat -e cycles,CPL<TAB> > > > > > > I get nothing :-\ > > > > > > Is this working with you? > > > > You can't mix cases like this, the upper case patch doesn't support that. > > It's either all upper or all lower case. > > > > If you continue with lower case it should work. > > I understand that this should be a limitation of the current patch, but > if we decide to support completion after a comma, I think people will > expect that all events will be available :-\ I don't see a simple way to do it. I'm not gonna write a complex parser in shell. If that really is a requirement the patch has to be withdrawn. -Andi
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2016-10-06 22:10 +0200 |
| Message-ID | <spn9n-5J3-1@gated-at.bofh.it> |
| In reply to | #1496824 |
Em Thu, Oct 06, 2016 at 12:23:25PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
>
> Add an argument to perf list to only list json events. To be used
> for the command line completion script. This requires adding
> a new flag to the alias structure.
Thanks, applied.
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
> tools/perf/Documentation/perf-list.txt | 2 +-
> tools/perf/builtin-list.c | 9 ++++++---
> tools/perf/util/parse-events.c | 2 +-
> tools/perf/util/pmu.c | 14 ++++++++++----
> tools/perf/util/pmu.h | 3 ++-
> 5 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
> index 41857cce5e86..50a35b27a64d 100644
> --- a/tools/perf/Documentation/perf-list.txt
> +++ b/tools/perf/Documentation/perf-list.txt
> @@ -8,7 +8,7 @@ perf-list - List all symbolic event types
> SYNOPSIS
> --------
> [verse]
> -'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|event_glob]
> +'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|json|sdt|event_glob]
>
> DESCRIPTION
> -----------
> diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> index ba9322ff858b..b9ccdc7ec733 100644
> --- a/tools/perf/builtin-list.c
> +++ b/tools/perf/builtin-list.c
> @@ -32,7 +32,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
> OPT_END()
> };
> const char * const list_usage[] = {
> - "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
> + "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|json|event_glob]",
> NULL
> };
>
> @@ -69,9 +69,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
> print_hwcache_events(NULL, raw_dump);
> else if (strcmp(argv[i], "pmu") == 0)
> print_pmu_events(NULL, raw_dump, !desc_flag,
> - long_desc_flag);
> + long_desc_flag, false);
> else if (strcmp(argv[i], "sdt") == 0)
> print_sdt_events(NULL, NULL, raw_dump);
> + else if (strcmp(argv[i], "json") == 0)
> + print_pmu_events(NULL, raw_dump, !desc_flag,
> + long_desc_flag, true);
> else if ((sep = strchr(argv[i], ':')) != NULL) {
> int sep_idx;
>
> @@ -100,7 +103,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
> event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
> print_hwcache_events(s, raw_dump);
> print_pmu_events(s, raw_dump, !desc_flag,
> - long_desc_flag);
> + long_desc_flag, false);
> print_tracepoint_events(NULL, s, raw_dump);
> print_sdt_events(NULL, s, raw_dump);
> free(s);
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 4e778eae1510..948ef84e4c6a 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -2275,7 +2275,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,
>
> print_hwcache_events(event_glob, name_only);
>
> - print_pmu_events(event_glob, name_only, quiet_flag, long_desc);
> + print_pmu_events(event_glob, name_only, quiet_flag, long_desc, false);
>
> if (event_glob != NULL)
> return;
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index b1474dcadfa2..d8d7d4c0319c 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -224,7 +224,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
>
> static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
> char *desc, char *val, char *long_desc,
> - char *topic)
> + char *topic, bool json)
> {
> struct perf_pmu_alias *alias;
> int ret;
> @@ -238,6 +238,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
> alias->unit[0] = '\0';
> alias->per_pkg = false;
> alias->snapshot = false;
> + alias->json = json;
>
> ret = parse_events_terms(&alias->terms, val);
> if (ret) {
> @@ -278,7 +279,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
>
> buf[ret] = 0;
>
> - return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL);
> + return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, false);
> }
>
> static inline bool pmu_alias_info_file(char *name)
> @@ -537,7 +538,8 @@ static void pmu_add_cpu_aliases(struct list_head *head)
> /* need type casts to override 'const' */
> __perf_pmu__new_alias(head, NULL, (char *)pe->name,
> (char *)pe->desc, (char *)pe->event,
> - (char *)pe->long_desc, (char *)pe->topic);
> + (char *)pe->long_desc, (char *)pe->topic,
> + true);
> }
>
> out:
> @@ -1103,7 +1105,7 @@ static void wordwrap(char *s, int start, int max, int corr)
> }
>
> void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
> - bool long_desc)
> + bool long_desc, bool json_only)
> {
> struct perf_pmu *pmu;
> struct perf_pmu_alias *alias;
> @@ -1134,6 +1136,9 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
> format_alias(buf, sizeof(buf), pmu, alias);
> bool is_cpu = !strcmp(pmu->name, "cpu");
>
> + if (json_only && !alias->json)
> + continue;
> +
> if (event_glob != NULL &&
> !(strglobmatch(name, event_glob) ||
> (!is_cpu && strglobmatch(alias->name,
> @@ -1158,6 +1163,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
> j++;
> }
> if (pmu->selectable &&
> + !json_only &&
> (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
> char *s;
> if (asprintf(&s, "%s//", pmu->name) < 0)
> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
> index 25712034c815..19fa2e19dbe9 100644
> --- a/tools/perf/util/pmu.h
> +++ b/tools/perf/util/pmu.h
> @@ -49,6 +49,7 @@ struct perf_pmu_alias {
> double scale;
> bool per_pkg;
> bool snapshot;
> + bool json;
> };
>
> struct perf_pmu *perf_pmu__find(const char *name);
> @@ -75,7 +76,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
> struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
>
> void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
> - bool long_desc);
> + bool long_desc, bool json_only);
> bool pmu_have_event(const char *pname, const char *name);
>
> int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
> --
> 2.5.5
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web