|
13 | 13 | #include "evsel.h" |
14 | 14 | #include "event.h" |
15 | 15 | #include "print_binary.h" |
| 16 | +#include "strbuf.h" |
16 | 17 | #include "thread_map.h" |
17 | 18 | #include "trace-event.h" |
18 | 19 | #include "mmap.h" |
@@ -1247,13 +1248,73 @@ static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel, |
1247 | 1248 | #endif // HAVE_LIBTRACEEVENT |
1248 | 1249 | } |
1249 | 1250 |
|
| 1251 | +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) |
| 1252 | +{ |
| 1253 | + struct pyrf_evsel *pevsel = PyObject_New(struct pyrf_evsel, &pyrf_evsel__type); |
| 1254 | + |
| 1255 | + if (!pevsel) |
| 1256 | + return NULL; |
| 1257 | + |
| 1258 | + memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); |
| 1259 | + evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); |
| 1260 | + |
| 1261 | + evsel__clone(&pevsel->evsel, evsel); |
| 1262 | + return (PyObject *)pevsel; |
| 1263 | +} |
| 1264 | + |
| 1265 | +static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) |
| 1266 | +{ |
| 1267 | + struct pyrf_evlist *pevlist = PyObject_New(struct pyrf_evlist, &pyrf_evlist__type); |
| 1268 | + struct evsel *pos; |
| 1269 | + |
| 1270 | + if (!pevlist) |
| 1271 | + return NULL; |
| 1272 | + |
| 1273 | + memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); |
| 1274 | + evlist__init(&pevlist->evlist, evlist->core.all_cpus, evlist->core.threads); |
| 1275 | + evlist__for_each_entry(evlist, pos) { |
| 1276 | + struct pyrf_evsel *pevsel = (void *)pyrf_evsel__from_evsel(pos); |
| 1277 | + |
| 1278 | + evlist__add(&pevlist->evlist, &pevsel->evsel); |
| 1279 | + } |
| 1280 | + return (PyObject *)pevlist; |
| 1281 | +} |
| 1282 | + |
| 1283 | +static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) |
| 1284 | +{ |
| 1285 | + const char *input; |
| 1286 | + struct evlist evlist = {}; |
| 1287 | + struct parse_events_error err; |
| 1288 | + PyObject *result; |
| 1289 | + |
| 1290 | + if (!PyArg_ParseTuple(args, "s", &input)) |
| 1291 | + return NULL; |
| 1292 | + |
| 1293 | + parse_events_error__init(&err); |
| 1294 | + evlist__init(&evlist, NULL, NULL); |
| 1295 | + if (parse_events(&evlist, input, &err)) { |
| 1296 | + parse_events_error__print(&err, input); |
| 1297 | + PyErr_SetFromErrno(PyExc_OSError); |
| 1298 | + return NULL; |
| 1299 | + } |
| 1300 | + result = pyrf_evlist__from_evlist(&evlist); |
| 1301 | + evlist__exit(&evlist); |
| 1302 | + return result; |
| 1303 | +} |
| 1304 | + |
1250 | 1305 | static PyMethodDef perf__methods[] = { |
1251 | 1306 | { |
1252 | 1307 | .ml_name = "tracepoint", |
1253 | 1308 | .ml_meth = (PyCFunction) pyrf__tracepoint, |
1254 | 1309 | .ml_flags = METH_VARARGS | METH_KEYWORDS, |
1255 | 1310 | .ml_doc = PyDoc_STR("Get tracepoint config.") |
1256 | 1311 | }, |
| 1312 | + { |
| 1313 | + .ml_name = "parse_events", |
| 1314 | + .ml_meth = (PyCFunction) pyrf__parse_events, |
| 1315 | + .ml_flags = METH_VARARGS, |
| 1316 | + .ml_doc = PyDoc_STR("Parse a string of events and return an evlist.") |
| 1317 | + }, |
1257 | 1318 | { .ml_name = NULL, } |
1258 | 1319 | }; |
1259 | 1320 |
|
|
0 commit comments