0001
0002 #include <stdio.h>
0003 #include "pmu.h"
0004 #include "pmu-hybrid.h"
0005 #include "topdown.h"
0006
0007 int topdown_filter_events(const char **attr, char **str, bool use_group,
0008 const char *pmu_name)
0009 {
0010 int off = 0;
0011 int i;
0012 int len = 0;
0013 char *s;
0014 bool is_hybrid = perf_pmu__is_hybrid(pmu_name);
0015
0016 for (i = 0; attr[i]; i++) {
0017 if (pmu_have_event(pmu_name, attr[i])) {
0018 if (is_hybrid)
0019 len += strlen(attr[i]) + strlen(pmu_name) + 3;
0020 else
0021 len += strlen(attr[i]) + 1;
0022 attr[i - off] = attr[i];
0023 } else
0024 off++;
0025 }
0026 attr[i - off] = NULL;
0027
0028 *str = malloc(len + 1 + 2);
0029 if (!*str)
0030 return -1;
0031 s = *str;
0032 if (i - off == 0) {
0033 *s = 0;
0034 return 0;
0035 }
0036 if (use_group)
0037 *s++ = '{';
0038 for (i = 0; attr[i]; i++) {
0039 if (!is_hybrid)
0040 strcpy(s, attr[i]);
0041 else
0042 sprintf(s, "%s/%s/", pmu_name, attr[i]);
0043 s += strlen(s);
0044 *s++ = ',';
0045 }
0046 if (use_group) {
0047 s[-1] = '}';
0048 *s = 0;
0049 } else
0050 s[-1] = 0;
0051 return 0;
0052 }
0053
0054 __weak bool arch_topdown_check_group(bool *warn)
0055 {
0056 *warn = false;
0057 return false;
0058 }
0059
0060 __weak void arch_topdown_group_warn(void)
0061 {
0062 }
0063
0064 __weak bool arch_topdown_sample_read(struct evsel *leader __maybe_unused)
0065 {
0066 return false;
0067 }
0068
0069 __weak const char *arch_get_topdown_pmu_name(struct evlist *evlist
0070 __maybe_unused,
0071 bool warn __maybe_unused)
0072 {
0073 return "cpu";
0074 }