Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evswitch: Introduce init() method to set the on/off evsels from the command line

Another step in having all the boilerplate in just one place to then use
in the other tools.

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-snreb1wmwyjei3eefwotxp1l@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+30 -18
+3 -18
tools/perf/builtin-script.c
··· 3868 3868 script.range_num); 3869 3869 } 3870 3870 3871 - if (script.evswitch.on_name) { 3872 - script.evswitch.on = perf_evlist__find_evsel_by_str(session->evlist, script.evswitch.on_name); 3873 - if (script.evswitch.on == NULL) { 3874 - fprintf(stderr, "switch-on event not found (%s)\n", script.evswitch.on_name); 3875 - err = -ENOENT; 3876 - goto out_delete; 3877 - } 3878 - script.evswitch.discarding = true; 3879 - } 3880 - 3881 - if (script.evswitch.off_name) { 3882 - script.evswitch.off = perf_evlist__find_evsel_by_str(session->evlist, script.evswitch.off_name); 3883 - if (script.evswitch.off == NULL) { 3884 - fprintf(stderr, "switch-off event not found (%s)\n", script.evswitch.off_name); 3885 - err = -ENOENT; 3886 - goto out_delete; 3887 - } 3888 - } 3871 + err = evswitch__init(&script.evswitch, session->evlist, stderr); 3872 + if (err) 3873 + goto out_delete; 3889 3874 3890 3875 err = __cmd_script(&script); 3891 3876
+23
tools/perf/util/evswitch.c
··· 2 2 // Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 3 4 4 #include "evswitch.h" 5 + #include "evlist.h" 5 6 6 7 bool evswitch__discard(struct evswitch *evswitch, struct evsel *evsel) 7 8 { ··· 29 28 } 30 29 31 30 return false; 31 + } 32 + 33 + int evswitch__init(struct evswitch *evswitch, struct evlist *evlist, FILE *fp) 34 + { 35 + if (evswitch->on_name) { 36 + evswitch->on = perf_evlist__find_evsel_by_str(evlist, evswitch->on_name); 37 + if (evswitch->on == NULL) { 38 + fprintf(fp, "switch-on event not found (%s)\n", evswitch->on_name); 39 + return -ENOENT; 40 + } 41 + evswitch->discarding = true; 42 + } 43 + 44 + if (evswitch->off_name) { 45 + evswitch->off = perf_evlist__find_evsel_by_str(evlist, evswitch->off_name); 46 + if (evswitch->off == NULL) { 47 + fprintf(fp, "switch-off event not found (%s)\n", evswitch->off_name); 48 + return -ENOENT; 49 + } 50 + } 51 + 52 + return 0; 32 53 }
+4
tools/perf/util/evswitch.h
··· 4 4 #define __PERF_EVSWITCH_H 1 5 5 6 6 #include <stdbool.h> 7 + #include <stdio.h> 7 8 8 9 struct evsel; 10 + struct evlist; 9 11 10 12 struct evswitch { 11 13 struct evsel *on, *off; ··· 15 13 bool discarding; 16 14 bool show_on_off_events; 17 15 }; 16 + 17 + int evswitch__init(struct evswitch *evswitch, struct evlist *evlist, FILE *fp); 18 18 19 19 bool evswitch__discard(struct evswitch *evswitch, struct evsel *evsel); 20 20