Skip to content

Commit 01bd8ef

Browse files
liu-song-6acmel
authored andcommitted
perf stat: Introduce ':b' modifier
Introduce 'b' modifier to event parser, which means use BPF program to manage this event. This is the same as --bpf-counters option, but only applies to this event. For example, perf stat -e cycles:b,cs # use bpf for cycles, but not cs perf stat -e cycles,cs --bpf-counters # use bpf for both cycles and cs Suggested-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Song Liu <song@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/r/20210425214333.1090950-5-song@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 112cb56 commit 01bd8ef

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

tools/perf/util/bpf_counter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ int bpf_counter__load(struct evsel *evsel, struct target *target)
790790
{
791791
if (target->bpf_str)
792792
evsel->bpf_counter_ops = &bpf_program_profiler_ops;
793-
else if (target->use_bpf ||
793+
else if (target->use_bpf || evsel->bpf_counter ||
794794
evsel__match_bpf_counter_events(evsel->name))
795795
evsel->bpf_counter_ops = &bperf_ops;
796796

tools/perf/util/evsel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct evsel {
8282
bool auto_merge_stats;
8383
bool collect_stat;
8484
bool weak_group;
85+
bool bpf_counter;
8586
int bpf_fd;
8687
struct bpf_object *bpf_obj;
8788
};

tools/perf/util/parse-events.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,7 @@ struct event_modifier {
18041804
int pinned;
18051805
int weak;
18061806
int exclusive;
1807+
int bpf_counter;
18071808
};
18081809

18091810
static int get_event_modifier(struct event_modifier *mod, char *str,
@@ -1824,6 +1825,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
18241825
int exclude = eu | ek | eh;
18251826
int exclude_GH = evsel ? evsel->exclude_GH : 0;
18261827
int weak = 0;
1828+
int bpf_counter = 0;
18271829

18281830
memset(mod, 0, sizeof(*mod));
18291831

@@ -1867,6 +1869,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
18671869
exclusive = 1;
18681870
} else if (*str == 'W') {
18691871
weak = 1;
1872+
} else if (*str == 'b') {
1873+
bpf_counter = 1;
18701874
} else
18711875
break;
18721876

@@ -1898,6 +1902,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
18981902
mod->sample_read = sample_read;
18991903
mod->pinned = pinned;
19001904
mod->weak = weak;
1905+
mod->bpf_counter = bpf_counter;
19011906
mod->exclusive = exclusive;
19021907

19031908
return 0;
@@ -1912,7 +1917,7 @@ static int check_modifier(char *str)
19121917
char *p = str;
19131918

19141919
/* The sizeof includes 0 byte as well. */
1915-
if (strlen(str) > (sizeof("ukhGHpppPSDIWe") - 1))
1920+
if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1))
19161921
return -1;
19171922

19181923
while (*p) {
@@ -1953,6 +1958,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add)
19531958
evsel->sample_read = mod.sample_read;
19541959
evsel->precise_max = mod.precise_max;
19551960
evsel->weak_group = mod.weak;
1961+
evsel->bpf_counter = mod.bpf_counter;
19561962

19571963
if (evsel__is_group_leader(evsel)) {
19581964
evsel->core.attr.pinned = mod.pinned;

tools/perf/util/parse-events.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ name_tag [\'][a-zA-Z_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=]*[\']
210210
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]*
211211
drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
212212
/* If you add a modifier you need to update check_modifier() */
213-
modifier_event [ukhpPGHSDIWe]+
213+
modifier_event [ukhpPGHSDIWeb]+
214214
modifier_bp [rwx]{1,3}
215215

216216
%%

0 commit comments

Comments
 (0)