Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1007954yba; Thu, 4 Apr 2019 02:17:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyn/0IAVU9IfbLBcz+6UhKnrrnwVb5z9q5WR16mzCsf5qn2vHJ9SCMebZjPMTvR7x49BUD3 X-Received: by 2002:a63:e14e:: with SMTP id h14mr4715746pgk.184.1554369465666; Thu, 04 Apr 2019 02:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369465; cv=none; d=google.com; s=arc-20160816; b=ajrjUcXhYsmOdzVRR57Ui3+VuMru9udV8SfNmLC3YI8qIVxyV7whO9LwgiziQ5q6ie 9RMErRMDKdTL83y0t9gcCPG3kb62zSCq7bfZeTz2bOIFrGZZ61dKpm0NQnvxnbIaB2Vb MGtl/XNP0IunHT3UJp0ziY7L0+1IAYosYLbG2IiQnwZYGEiVmX161jc8t0bkLRh9nnqy v+EHnPp9qfO7Ic2K8M+D+8gvYpLhbg8CbuYnk5MdAwNErNvLj9F3vYrWNrxKOOUuBO1z KWSIYL6/GE7yh3QwbZgnChUFvUCEOcP8iLWgdbVBq3nBhogXJP287AIhHBFEIxZxIJoZ lunQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/uegZnazLUdQ3FANMjAKeKrgzifVcw3hhP7VT27CMVg=; b=F3TkTrBC3aLnssFJgpCLSgE45DSicCwo50TGHlypbV9g586aDrzxWZAsIYw0AjFS5p JiUyapUnH4AAd+mh6t5PXmksofgL6SHdXonlhZiAoZG+BvxpscOPp00QoaQDwwfcd7oH sN0+TvgnuI7BEuHWAD8edvX++Rbb0Yt8rVkRiGT80KSGs20czWzv6urStpnHaCZ8GS/b RvnzODCwcVsFruISexQFwg+0FHw6gnYZjUYDLzvgifpA97+PG1NJDKrtEjTDmgtIasP8 Ct3VZ7Fq0xanSE7KnVCQdzBXk0xf7haoia6dtceH5YGArvLxkvkQFJOBrdP+bcrYbMNq /YHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c33hpvnP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 124si10554367pgi.38.2019.04.04.02.17.30; Thu, 04 Apr 2019 02:17:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c33hpvnP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388105AbfDDJQq (ORCPT + 99 others); Thu, 4 Apr 2019 05:16:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:57974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387868AbfDDJQn (ORCPT ); Thu, 4 Apr 2019 05:16:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3AEE720693; Thu, 4 Apr 2019 09:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369402; bh=gMxPcSo2/t1c+QqJNyP83ACaOA53yIaf1HtTknBEPlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c33hpvnPtVJRgKFoiSA/bd6Hn2WtSCAnlT/ymfRlUf5yXRSrN2PtDVJhvbKUDlXyo P9fVwxjxO0ALY4JHlELV1xJZ7TFa4/z+unuAGri1sWiR3DflHUQz51fGBzLki27bDd QHCC1bfFCS0T87T4HPFIXJZhgcv2B8RaZ7sysTn4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Jones , Jiri Olsa , Arnaldo Carvalho de Melo , =?UTF-8?q?Jaroslav=20=C5=A0karvada?= , Jonathan Corbet , Ravi Bangoria , Seeteena Thoufeek , Sasha Levin Subject: [PATCH 5.0 202/246] perf script python: Add trace_context extension module to sys.modules Date: Thu, 4 Apr 2019 10:48:22 +0200 Message-Id: <20190404084626.262531646@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit cc437642255224e4140fed1f3e3156fc8ad91903 ] In Python3, the result of PyModule_Create (called from scripts/python/Perf-Trace-Util/Context.c) is not automatically added to sys.modules. See: https://bugs.python.org/issue4592 Below is the observed behavior without the fix: # ldd /usr/bin/perf | grep -i python libpython3.6m.so.1.0 => /usr/lib64/libpython3.6m.so.1.0 (0x00007f8e1dfb2000) # perf record /bin/false [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.015 MB perf.data (17 samples) ] # perf script -g python | cat generated Python script: perf-script.py # perf script -s ./perf-script.py Traceback (most recent call last): File "./perf-script.py", line 18, in from perf_trace_context import * ModuleNotFoundError: No module named 'perf_trace_context' Error running python script ./perf-script.py # Committer notes: To build with python3 use: $ make -C tools/perf PYTHON=python3 Use a non-const variable to pass the 'name' arg to PyImport_AppendInittab(), as python2.6 has that as 'char *', which ends up trowing this in some environments: CC /tmp/build/perf/util/parse-branch-options.o util/scripting-engines/trace-event-python.c: In function 'python_start_script': util/scripting-engines/trace-event-python.c:1520:2: error: passing argument 1 of 'PyImport_AppendInittab' discards 'const' qualifier from pointer target type [-Werror] PyImport_AppendInittab("perf_trace_context", initfunc); ^ In file included from /usr/include/python2.6/Python.h:130:0, from util/scripting-engines/trace-event-python.c:22: /usr/include/python2.6/import.h:54:17: note: expected 'char *' but argument is of type 'const char *' PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void)); ^ cc1: all warnings being treated as errors Signed-off-by: Tony Jones Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Jaroslav Škarvada Cc: Jonathan Corbet Cc: Ravi Bangoria Cc: Seeteena Thoufeek Fixes: 66dfdff03d19 ("perf tools: Add Python 3 support") Link: http://lkml.kernel.org/r/20190124005229.16146-2-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- .../perf/util/scripting-engines/trace-event-python.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 2fe3cc43526f..7059d1be2d09 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1493,34 +1493,40 @@ static void _free_command_line(wchar_t **command_line, int num) static int python_start_script(const char *script, int argc, const char **argv) { struct tables *tables = &tables_global; + PyMODINIT_FUNC (*initfunc)(void); #if PY_MAJOR_VERSION < 3 const char **command_line; #else wchar_t **command_line; #endif - char buf[PATH_MAX]; + /* + * Use a non-const name variable to cope with python 2.6's + * PyImport_AppendInittab prototype + */ + char buf[PATH_MAX], name[19] = "perf_trace_context"; int i, err = 0; FILE *fp; #if PY_MAJOR_VERSION < 3 + initfunc = initperf_trace_context; command_line = malloc((argc + 1) * sizeof(const char *)); command_line[0] = script; for (i = 1; i < argc + 1; i++) command_line[i] = argv[i - 1]; #else + initfunc = PyInit_perf_trace_context; command_line = malloc((argc + 1) * sizeof(wchar_t *)); command_line[0] = Py_DecodeLocale(script, NULL); for (i = 1; i < argc + 1; i++) command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); #endif + PyImport_AppendInittab(name, initfunc); Py_Initialize(); #if PY_MAJOR_VERSION < 3 - initperf_trace_context(); PySys_SetArgv(argc + 1, (char **)command_line); #else - PyInit_perf_trace_context(); PySys_SetArgv(argc + 1, command_line); #endif -- 2.19.1