perf evswitch: Move switch logic to use in other tools
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 8829e56fa050998164e496d380cd69186ae9b8d0 Gitweb: https://git.kernel.org/tip/8829e56fa050998164e496d380cd69186ae9b8d0 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Thu, 15 Aug 2019 11:00:11 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 15 Aug 2019 12:24:31 -0300
perf evswitch: Move switch logic to use in other tools
Now other tools that want switching can use an evswitch for that, just set it up and add it to the PERF_RECORD_SAMPLE processing function.
Cc Adrian Hunter <[email protected]>
Cc Florian Weimer <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc William Cohen <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-script.c | 23 ++--------------------- tools/perf/util/Build | 1 + tools/perf/util/evswitch.c | 31 +++++++++++++++++++++++++++++++ tools/perf/util/evswitch.h | 2 ++ 4 files changed, 36 insertions(+), 21 deletions(-)
tools/perf/builtin-script.c +2 -21
@@ -1807,28 +1807,9 @@ static void process_event(struct perf_script *script,if (!show_event (sample, evsel, thread, al))return ; -if (script->evswitch.on && script->evswitch.discarding) { -if (script->evswitch.on != evsel) -return ; - - script->evswitch.discarding = false; - -if (!script->evswitch.show_on_off_events) -return ; - - goto print_it; - } - -if (script->evswitch.off && !script->evswitch.discarding) { -if (script->evswitch.off != evsel) - goto print_it; - - script->evswitch.discarding = true; +if (evswitch__discard (&script->evswitch, evsel)) +return ; -if (!script->evswitch.show_on_off_events) -return ; - } -print_it: ++es->samples; perf_sample__fprintf_start(sample, thread, evsel,
tools/perf/util/Build +1 -0
@@ -9,6 +9,7 @@ perf-y += event.o perf-y += evlist.o perf-y += evsel.o perf-y += evsel_fprintf.o +perf-y += evswitch.o perf-y += find_bit.o perf-y += get_current_dir_name.o perf-y += kallsyms.o
tools/perf/util/evswitch.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> + +#include "evswitch.h" + +bool evswitch__discard (struct evswitch *evswitch,struct evsel *evsel) +{ +if (evswitch->on && evswitch->discarding) { +if (evswitch->on != evsel) +return true; + + evswitch->discarding = false; + +if (!evswitch->show_on_off_events) +return true; + +return false; + } + +if (evswitch->off && !evswitch->discarding) { +if (evswitch->off != evsel) +return false; + + evswitch->discarding = true; + +if (!evswitch->show_on_off_events) +return true; + } + +return false; +}
tools/perf/util/evswitch.h +2 -0
@@ -13,4 +13,6 @@ struct evswitch { bool show_on_off_events; }; +bool evswitch__discard (struct evswitch *evswitch,struct evsel *evsel); +#endif /* __PERF_EVSWITCH_H */