Skip to content

Commit d17cccb

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/urgent fixes from Arnaldo Carvalho de Melo: * Fix up /proc/PID/maps parsing, where perfectly fine mmap entries were being trown away when synthesizing PERF_RECORD_MMAP for preexisting threads, prevenging symbol resolution to work for those threads, broken in the MMAP2 removal. Reported and pinpointed by Markus Trippelsdorf, * Fix mem leak in the python 'perf script' backend, due to missing Py_DECREFs on dict entries, fix from Joseph Schuchart. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 959f585 + 2fd869f commit d17cccb

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

tools/perf/util/event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
213213
&event->mmap.pgoff,
214214
execname);
215215

216-
if (n != 8)
216+
if (n != 5)
217217
continue;
218218

219219
if (prot[2] != 'x')

tools/perf/util/scripting-engines/trace-event-python.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ static void handler_call_die(const char *handler_name)
5656
Py_FatalError("problem in Python trace event handler");
5757
}
5858

59+
/*
60+
* Insert val into into the dictionary and decrement the reference counter.
61+
* This is necessary for dictionaries since PyDict_SetItemString() does not
62+
* steal a reference, as opposed to PyTuple_SetItem().
63+
*/
64+
static void pydict_set_item_string_decref(PyObject *dict, const char *key, PyObject *val)
65+
{
66+
PyDict_SetItemString(dict, key, val);
67+
Py_DECREF(val);
68+
}
69+
5970
static void define_value(enum print_arg_type field_type,
6071
const char *ev_name,
6172
const char *field_name,
@@ -279,11 +290,11 @@ static void python_process_tracepoint(union perf_event *perf_event
279290
PyTuple_SetItem(t, n++, PyInt_FromLong(pid));
280291
PyTuple_SetItem(t, n++, PyString_FromString(comm));
281292
} else {
282-
PyDict_SetItemString(dict, "common_cpu", PyInt_FromLong(cpu));
283-
PyDict_SetItemString(dict, "common_s", PyInt_FromLong(s));
284-
PyDict_SetItemString(dict, "common_ns", PyInt_FromLong(ns));
285-
PyDict_SetItemString(dict, "common_pid", PyInt_FromLong(pid));
286-
PyDict_SetItemString(dict, "common_comm", PyString_FromString(comm));
293+
pydict_set_item_string_decref(dict, "common_cpu", PyInt_FromLong(cpu));
294+
pydict_set_item_string_decref(dict, "common_s", PyInt_FromLong(s));
295+
pydict_set_item_string_decref(dict, "common_ns", PyInt_FromLong(ns));
296+
pydict_set_item_string_decref(dict, "common_pid", PyInt_FromLong(pid));
297+
pydict_set_item_string_decref(dict, "common_comm", PyString_FromString(comm));
287298
}
288299
for (field = event->format.fields; field; field = field->next) {
289300
if (field->flags & FIELD_IS_STRING) {
@@ -313,7 +324,7 @@ static void python_process_tracepoint(union perf_event *perf_event
313324
if (handler)
314325
PyTuple_SetItem(t, n++, obj);
315326
else
316-
PyDict_SetItemString(dict, field->name, obj);
327+
pydict_set_item_string_decref(dict, field->name, obj);
317328

318329
}
319330
if (!handler)
@@ -370,21 +381,21 @@ static void python_process_general_event(union perf_event *perf_event
370381
if (!handler || !PyCallable_Check(handler))
371382
goto exit;
372383

373-
PyDict_SetItemString(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
374-
PyDict_SetItemString(dict, "attr", PyString_FromStringAndSize(
384+
pydict_set_item_string_decref(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
385+
pydict_set_item_string_decref(dict, "attr", PyString_FromStringAndSize(
375386
(const char *)&evsel->attr, sizeof(evsel->attr)));
376-
PyDict_SetItemString(dict, "sample", PyString_FromStringAndSize(
387+
pydict_set_item_string_decref(dict, "sample", PyString_FromStringAndSize(
377388
(const char *)sample, sizeof(*sample)));
378-
PyDict_SetItemString(dict, "raw_buf", PyString_FromStringAndSize(
389+
pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize(
379390
(const char *)sample->raw_data, sample->raw_size));
380-
PyDict_SetItemString(dict, "comm",
391+
pydict_set_item_string_decref(dict, "comm",
381392
PyString_FromString(thread->comm));
382393
if (al->map) {
383-
PyDict_SetItemString(dict, "dso",
394+
pydict_set_item_string_decref(dict, "dso",
384395
PyString_FromString(al->map->dso->name));
385396
}
386397
if (al->sym) {
387-
PyDict_SetItemString(dict, "symbol",
398+
pydict_set_item_string_decref(dict, "symbol",
388399
PyString_FromString(al->sym->name));
389400
}
390401

0 commit comments

Comments
 (0)