Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1022219yba; Thu, 4 Apr 2019 02:37:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpipxfrZi1DEsf7H0iIJ1aPwnkyzotATkBz9u72HxmZRE6r9uvzyEZ+PhlzLS5uz6hWw+N X-Received: by 2002:a63:707:: with SMTP id 7mr4677689pgh.390.1554370670461; Thu, 04 Apr 2019 02:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370670; cv=none; d=google.com; s=arc-20160816; b=WmrFdfqUpglOtShQ4+HXCVIkxDOB7Z6OQUHVmn1yMluGl7EVarvhk3VxiXgzkPz7lU qmXoBDe/zFzSeeXftkbbcyCjZ33bhzCqgicGFI13inFifKQOiwRtf1QifNurZea4zR8G SxLZKFFP/4v/6Wgd9XctKffzeGPFrElYa0UPMb/FyMWjSPd6Mmn5PJ2aaRptn2ZYlh8f eNDcYJeC61afgijcivHArC5ffgIxg/ukXUaMCP6EVoH+4oOzBz8YTgn/YgenkXGVqPKn AswIcg16wo0kFXt2WPxTHV2wt7A93uMebq7id5f0jpcg654w9VRU1p6KKGdsAZCN8tHd p1mA== 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=vQcUQOjDYzDrIISzGPRhdzy61XDJ4ZSboeKifRfstiU=; b=OCH02rDilZHDQnthGzKKGGTAD+tp5l8k3/sxGGPhXn8V0thNjlNx6P0gcpijXjiFHm SdrNkHcQjyPCxSEH9H2qQX17G3rNqzrYop+wOn1LzsendRMlAePNAjs43BpCGJa9gytH HuWNMEFv5o4crBnrOPH6k2vaXjRZlDYAaibAzxWNuLdWE7XnG03OJ8QhAFyTIJq4CGGX Muy7l4vGkvwoqGRhXRJqmLqG93DzYH3JRR3YjAiYMyDAe6p2AxnhXD1cL3nU2HuHYFQv 2kr97zh7RjSpnTr5vMOIh6087cT/lPi9pKfKVvYp3uLJFrVC/7XqLDfJ7Y1BX/q3QCRx TrEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QadUbjG6; 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 s26si16182659pgm.223.2019.04.04.02.37.35; Thu, 04 Apr 2019 02:37:50 -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=QadUbjG6; 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 S1732072AbfDDJgQ (ORCPT + 99 others); Thu, 4 Apr 2019 05:36:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:44066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730246AbfDDJFs (ORCPT ); Thu, 4 Apr 2019 05:05:48 -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 C84E021855; Thu, 4 Apr 2019 09:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368747; bh=RVQ76LLQor2ryz6bxmMfusmXLgD4cADWDGnSCaP6ybw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QadUbjG6W1cuGiFnpKWOK3g9YfOqDEYgIpm5UbkQJfDTXrPhd/04LmLzuldRwSpEt uGv99F1wIXumbEySXaH0/3pC1xe6XjPZ8Ka2YJXg5VrW0DzVvUQPjGC6R2XRAxGrc0 velD9VEVgS3uCiQTW9ujMgUZ366veTt9Rcib8dKI= 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 4.19 155/187] perf script python: Add trace_context extension module to sys.modules Date: Thu, 4 Apr 2019 10:48:12 +0200 Message-Id: <20190404084610.426069706@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@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 4.19-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 fb11396ec861..9569cc06e0a7 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