perf stat: Introduce config stat.bpf-counter-events

Currently, to use BPF to aggregate perf event counters, the user uses
--bpf-counters option. Enable "use bpf by default" events with a config
option, stat.bpf-counter-events. Events with name in the option will use
BPF.

This also enables mixed BPF event and regular event in the same sesssion.
For example:

   perf config stat.bpf-counter-events=instructions
   perf stat -e instructions,cs

The second command will use BPF for "instructions" but not "cs".

Signed-off-by: Song Liu <song@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/r/20210425214333.1090950-4-song@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Song Liu
2021-04-25 14:43:31 -07:00
committed by Arnaldo Carvalho de Melo
parent fe3dd8263b
commit 112cb56164
7 changed files with 63 additions and 23 deletions

View File

@@ -492,6 +492,28 @@ const char *evsel__hw_names[PERF_COUNT_HW_MAX] = {
"ref-cycles",
};
char *evsel__bpf_counter_events;
bool evsel__match_bpf_counter_events(const char *name)
{
int name_len;
bool match;
char *ptr;
if (!evsel__bpf_counter_events)
return false;
ptr = strstr(evsel__bpf_counter_events, name);
name_len = strlen(name);
/* check name matches a full token in evsel__bpf_counter_events */
match = (ptr != NULL) &&
((ptr == evsel__bpf_counter_events) || (*(ptr - 1) == ',')) &&
((*(ptr + name_len) == ',') || (*(ptr + name_len) == '\0'));
return match;
}
static const char *__evsel__hw_name(u64 config)
{
if (config < PERF_COUNT_HW_MAX && evsel__hw_names[config])