0001
0002
0003
0004 #include "evswitch.h"
0005 #include "evlist.h"
0006
0007 bool evswitch__discard(struct evswitch *evswitch, struct evsel *evsel)
0008 {
0009 if (evswitch->on && evswitch->discarding) {
0010 if (evswitch->on != evsel)
0011 return true;
0012
0013 evswitch->discarding = false;
0014
0015 if (!evswitch->show_on_off_events)
0016 return true;
0017
0018 return false;
0019 }
0020
0021 if (evswitch->off && !evswitch->discarding) {
0022 if (evswitch->off != evsel)
0023 return false;
0024
0025 evswitch->discarding = true;
0026
0027 if (!evswitch->show_on_off_events)
0028 return true;
0029 }
0030
0031 return false;
0032 }
0033
0034 static int evswitch__fprintf_enoent(FILE *fp, const char *evtype, const char *evname)
0035 {
0036 int printed = fprintf(fp, "ERROR: switch-%s event not found (%s)\n", evtype, evname);
0037
0038 return printed += fprintf(fp, "HINT: use 'perf evlist' to see the available event names\n");
0039 }
0040
0041 int evswitch__init(struct evswitch *evswitch, struct evlist *evlist, FILE *fp)
0042 {
0043 if (evswitch->on_name) {
0044 evswitch->on = evlist__find_evsel_by_str(evlist, evswitch->on_name);
0045 if (evswitch->on == NULL) {
0046 evswitch__fprintf_enoent(fp, "on", evswitch->on_name);
0047 return -ENOENT;
0048 }
0049 evswitch->discarding = true;
0050 }
0051
0052 if (evswitch->off_name) {
0053 evswitch->off = evlist__find_evsel_by_str(evlist, evswitch->off_name);
0054 if (evswitch->off == NULL) {
0055 evswitch__fprintf_enoent(fp, "off", evswitch->off_name);
0056 return -ENOENT;
0057 }
0058 }
0059
0060 return 0;
0061 }