]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
perf evswitch: Move switch logic to use in other tools
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Aug 2019 14:00:11 +0000 (11:00 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Aug 2019 15:24:31 +0000 (12:24 -0300)
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 <adrian.hunter@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: William Cohen <wcohen@redhat.com>
Link: https://lkml.kernel.org/n/tip-b1trj1q97qwfv251l66q3noj@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-script.c
tools/perf/util/Build
tools/perf/util/evswitch.c [new file with mode: 0644]
tools/perf/util/evswitch.h

index fff02e0d70c40b1289605b127ab2396320404ee8..e7b950e977a9bc70cc944507dd58acfa50a0db79 100644 (file)
@@ -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,
index 7cda749059a9451a64e6d8eb7a095f5c91e46a34..b922c8c297ca501ea25d96a7c731a744542ed8a0 100644 (file)
@@ -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
diff --git a/tools/perf/util/evswitch.c b/tools/perf/util/evswitch.c
new file mode 100644 (file)
index 0000000..c87f988
--- /dev/null
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
+
+#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;
+}
index bb88e8002f39b938fff44b5795135184c81fa42f..bae3a22ad71963ce8063a57270c53fa16be5bd94 100644 (file)
@@ -13,4 +13,6 @@ struct evswitch {
        bool         show_on_off_events;
 };
 
+bool evswitch__discard(struct evswitch *evswitch, struct evsel *evsel);
+
 #endif /* __PERF_EVSWITCH_H */