Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1406486imu; Wed, 23 Jan 2019 16:52:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN4RwIf9tb7v8iu7fC6HJETuTmc7W7lkAqAr6zvK194oFwaUccsirzVa9zmMP55aqF9VUcNS X-Received: by 2002:a17:902:a58a:: with SMTP id az10mr4567182plb.10.1548291135887; Wed, 23 Jan 2019 16:52:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548291135; cv=none; d=google.com; s=arc-20160816; b=WJZHllB0vbpq6VpXF4zxXGF14HQNbF1aFGsjwt3EzeeNRuTPpujOBXUrVT2iO273SX ACVUNEyCnW/vkdZ5P0fJ8yahMRafDblRD1csUMCekNBieFhbB7LLOuoa15qCbzGyvVDB +ztBV16L3glipMuAd7yZHuba87BEf9I+1kDshB0gUYg/FVenhBGbBfxSUtnvLq0IAU7z D2R5tVzFa+MIt/9O7v9ZOIzBQzVdg/Y5wdpSTda9ecdDg699d82ZL6wRGKRE8e0zPm1x XLELCEdhfWzhZl4xtZwOcN5YZK+ol/wp5dxMWf1HlqWx6Srx+rEuUIdmrVY4/4IlN7kf RGMA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4lvBbD7TNjd4x6ogSqzudxCDxHkj9qEOZK63ZgbOaHQ=; b=pgpdnx14JKdEd4/OE2QopygzJWKpctMmn5fxBA0zLWvlhrRmATYvg+A70ffCAXyfBX pMFehsgeslL61KvFyHS8U9yIIo7J3fLjCXk52pWLURPYABrsMR97aulYtQqML8pKHmZk rWbzNytPe5AJdOwXaqjecIgyHAKEL7uKI7QBzvoZgSzVBzewaIFo1XtU6iXbajhrNRpv CnkRy8qlMCuWZHGKCSP5uOPZU6eOqyOMInX2iuLIlV7hqJeqTfE76cp5RLlSgiBndHNi fsvFMNZpjLQo4SSbXFJxLpm4f0YX8ujdMkbz0xUHGfR3E9RDaymcDhorOYtVavIvnaps JIGA== ARC-Authentication-Results: i=1; mx.google.com; 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 i90si21015256pli.135.2019.01.23.16.51.56; Wed, 23 Jan 2019 16:52:15 -0800 (PST) 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; 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 S1726957AbfAXAvt (ORCPT + 99 others); Wed, 23 Jan 2019 19:51:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:37564 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726235AbfAXAvs (ORCPT ); Wed, 23 Jan 2019 19:51:48 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98A01AFCB; Thu, 24 Jan 2019 00:51:47 +0000 (UTC) From: Tony Jones To: linux-kernel@vger.kernel.org Cc: Seeteena Thoufeek , Ravi Bangoria , Arnaldo Carvalho de Melo , Jiri Olsa , Jonathan Corbet , linux-perf-users@vger.kernel.org, Tony Jones , =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Subject: [PATCH 1/6] perf script python: Add trace_context extension module to sys,modules Date: Wed, 23 Jan 2019 16:52:24 -0800 Message-Id: <20190124005229.16146-2-tonyj@suse.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124005229.16146-1-tonyj@suse.de> References: <20190124005229.16146-1-tonyj@suse.de> 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 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 Signed-off-By: Tony Jones Cc: Jaroslav Škarvada Fixes: 66dfdff03d196e51322c6a85c0d8db8bb2bdd655 --- tools/perf/util/scripting-engines/trace-event-python.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 87ef16a1b17e..40300d8e80a7 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1494,6 +1494,7 @@ 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 @@ -1504,24 +1505,25 @@ static int python_start_script(const char *script, int argc, const char **argv) 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("perf_trace_context", 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.20.1