Skip to content

Commit ddc4bec

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-4.17-20180220' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: - Initial support for linking with python3, by explicitely setting the PYTHON Makefile variable, python2 remains supported, more work needed to test the shipped python scripts used with 'perf script' (Jaroslav Škarvada) - Make twatch.py, an example python script that sets up evlists and evsels to then parse events from mmap, to work with both python2 and python3 (Arnaldo Carvalho de Melo) - Fix setting 'perf ftrace' function filter when using a non-existent function, which should result in an error instead of simply not setting the filter and showing all functions (Changbin Du) - Fix paranoid check in machine__set_kernel_mmap(), problem introduced in previous perf/core batch (Namhyung Kim) - Fix reading cpuid model information in s/390, ditto, also introduced in the previous perf/core batch (Thomas Richter) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 11737ca + 66dfdff commit ddc4bec

File tree

10 files changed

+243
-96
lines changed

10 files changed

+243
-96
lines changed

tools/perf/Makefile.config

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -668,25 +668,10 @@ else
668668
ifneq ($(feature-libpython), 1)
669669
$(call disable-python,No 'Python.h' (for Python 2.x support) was found: disables Python support - please install python-devel/python-dev)
670670
else
671-
ifneq ($(feature-libpython-version), 1)
672-
$(warning Python 3 is not yet supported; please set)
673-
$(warning PYTHON and/or PYTHON_CONFIG appropriately.)
674-
$(warning If you also have Python 2 installed, then)
675-
$(warning try something like:)
676-
$(warning $(and ,))
677-
$(warning $(and ,) make PYTHON=python2)
678-
$(warning $(and ,))
679-
$(warning Otherwise, disable Python support entirely:)
680-
$(warning $(and ,))
681-
$(warning $(and ,) make NO_LIBPYTHON=1)
682-
$(warning $(and ,))
683-
$(error $(and ,))
684-
else
685-
LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
686-
EXTLIBS += $(PYTHON_EMBED_LIBADD)
687-
LANG_BINDINGS += $(obj-perf)python/perf.so
688-
$(call detected,CONFIG_LIBPYTHON)
689-
endif
671+
LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
672+
EXTLIBS += $(PYTHON_EMBED_LIBADD)
673+
LANG_BINDINGS += $(obj-perf)python/perf.so
674+
$(call detected,CONFIG_LIBPYTHON)
690675
endif
691676
endif
692677
endif

tools/perf/Makefile.perf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
302302
PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/
303303
export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
304304

305-
python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so
305+
python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf*.so
306306

307307
PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
308308
PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) $(LIBAPI)
@@ -479,7 +479,7 @@ $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_D
479479
$(PYTHON_WORD) util/setup.py \
480480
--quiet build_ext; \
481481
mkdir -p $(OUTPUT)python && \
482-
cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/
482+
cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/
483483

484484
please_set_SHELL_PATH_to_a_more_modern_shell:
485485
$(Q)$$(:)

tools/perf/arch/s390/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int get_cpuid(char *buffer, size_t sz)
8181
line2 = line + strlen(SYSINFO_MODEL);
8282

8383
while ((cp = strtok_r(line2, "\n ", &line2))) {
84-
mdsize += scnprintf(model + mdsize, sizeof(type) - mdsize,
84+
mdsize += scnprintf(model + mdsize, sizeof(model) - mdsize,
8585
"%s%s", model[0] ? "," : "", cp);
8686
}
8787
break;

tools/perf/builtin-ftrace.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
7272
ssize_t size = strlen(val);
7373
int flags = O_WRONLY;
7474
char errbuf[512];
75+
char *val_copy;
7576

7677
file = get_tracing_file(name);
7778
if (!file) {
@@ -91,12 +92,23 @@ static int __write_tracing_file(const char *name, const char *val, bool append)
9192
goto out;
9293
}
9394

94-
if (write(fd, val, size) == size)
95+
/*
96+
* Copy the original value and append a '\n'. Without this,
97+
* the kernel can hide possible errors.
98+
*/
99+
val_copy = strdup(val);
100+
if (!val_copy)
101+
goto out_close;
102+
val_copy[size] = '\n';
103+
104+
if (write(fd, val_copy, size + 1) == size + 1)
95105
ret = 0;
96106
else
97107
pr_debug("write '%s' to tracing/%s failed: %s\n",
98108
val, name, str_error_r(errno, errbuf, sizeof(errbuf)));
99109

110+
free(val_copy);
111+
out_close:
100112
close(fd);
101113
out:
102114
put_tracing_file(file);
@@ -280,8 +292,10 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
280292
signal(SIGCHLD, sig_handler);
281293
signal(SIGPIPE, sig_handler);
282294

283-
if (reset_tracing_files(ftrace) < 0)
295+
if (reset_tracing_files(ftrace) < 0) {
296+
pr_err("failed to reset ftrace\n");
284297
goto out;
298+
}
285299

286300
/* reset ftrace buffer */
287301
if (write_tracing_file("trace", "0") < 0)

tools/perf/python/twatch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def main(context_switch = 0, thread = -1):
4242
event = evlist.read_on_cpu(cpu)
4343
if not event:
4444
continue
45-
print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
46-
event.sample_pid,
47-
event.sample_tid),
48-
print event
45+
print("cpu: {0}, pid: {1}, tid: {2} {3}".format(event.sample_cpu,
46+
event.sample_pid,
47+
event.sample_tid,
48+
event))
4949

5050
if __name__ == '__main__':
5151
"""

tools/perf/scripts/python/Perf-Trace-Util/Context.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@
2323
#include "../../../perf.h"
2424
#include "../../../util/trace-event.h"
2525

26+
#if PY_MAJOR_VERSION < 3
27+
#define _PyCapsule_GetPointer(arg1, arg2) \
28+
PyCObject_AsVoidPtr(arg1)
29+
2630
PyMODINIT_FUNC initperf_trace_context(void);
31+
#else
32+
#define _PyCapsule_GetPointer(arg1, arg2) \
33+
PyCapsule_GetPointer((arg1), (arg2))
34+
35+
PyMODINIT_FUNC PyInit_perf_trace_context(void);
36+
#endif
2737

2838
static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
2939
{
@@ -34,7 +44,7 @@ static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
3444
if (!PyArg_ParseTuple(args, "O", &context))
3545
return NULL;
3646

37-
scripting_context = PyCObject_AsVoidPtr(context);
47+
scripting_context = _PyCapsule_GetPointer(context, NULL);
3848
retval = common_pc(scripting_context);
3949

4050
return Py_BuildValue("i", retval);
@@ -50,7 +60,7 @@ static PyObject *perf_trace_context_common_flags(PyObject *obj,
5060
if (!PyArg_ParseTuple(args, "O", &context))
5161
return NULL;
5262

53-
scripting_context = PyCObject_AsVoidPtr(context);
63+
scripting_context = _PyCapsule_GetPointer(context, NULL);
5464
retval = common_flags(scripting_context);
5565

5666
return Py_BuildValue("i", retval);
@@ -66,7 +76,7 @@ static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
6676
if (!PyArg_ParseTuple(args, "O", &context))
6777
return NULL;
6878

69-
scripting_context = PyCObject_AsVoidPtr(context);
79+
scripting_context = _PyCapsule_GetPointer(context, NULL);
7080
retval = common_lock_depth(scripting_context);
7181

7282
return Py_BuildValue("i", retval);
@@ -82,7 +92,25 @@ static PyMethodDef ContextMethods[] = {
8292
{ NULL, NULL, 0, NULL}
8393
};
8494

95+
#if PY_MAJOR_VERSION < 3
8596
PyMODINIT_FUNC initperf_trace_context(void)
8697
{
8798
(void) Py_InitModule("perf_trace_context", ContextMethods);
8899
}
100+
#else
101+
PyMODINIT_FUNC PyInit_perf_trace_context(void)
102+
{
103+
static struct PyModuleDef moduledef = {
104+
PyModuleDef_HEAD_INIT,
105+
"perf_trace_context", /* m_name */
106+
"", /* m_doc */
107+
-1, /* m_size */
108+
ContextMethods, /* m_methods */
109+
NULL, /* m_reload */
110+
NULL, /* m_traverse */
111+
NULL, /* m_clear */
112+
NULL, /* m_free */
113+
};
114+
return PyModule_Create(&moduledef);
115+
}
116+
#endif

tools/perf/util/machine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ static void machine__set_kernel_mmap(struct machine *machine,
12261226
* Be a bit paranoid here, some perf.data file came with
12271227
* a zero sized synthesized MMAP event for the kernel.
12281228
*/
1229-
if (machine->vmlinux_maps[i]->end == 0)
1229+
if (start == 0 && end == 0)
12301230
machine->vmlinux_maps[i]->end = ~0ULL;
12311231
}
12321232
}

0 commit comments

Comments
 (0)