From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6919450737082630144 X-Received: by 2002:a5d:69ca:: with SMTP id s10mr27320729wrw.78.1619515514381; Tue, 27 Apr 2021 02:25:14 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:adf:fb47:: with SMTP id c7ls5173306wrs.0.gmail; Tue, 27 Apr 2021 02:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziTWghPVKAqWnn7lKmw9HQJUgah/6OMfeZgi8aY9aCgYX6Hv+HE/M18aN9ibIxBpX7emz3 X-Received: by 2002:adf:9042:: with SMTP id h60mr28038644wrh.362.1619515513603; Tue, 27 Apr 2021 02:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619515513; cv=none; d=google.com; s=arc-20160816; b=gNZLsv8Zhn70qSJX4O22HD1jP3yxbx2hLV8uBgPRcN92RbAPjW0FyFER5Ka4veqMZD 3ZU5Bx8QmVymQp9iQ9N3X2V2pho/12ZKi3TcUwPUGceaFnCcA3uPGd51AO1f8smNKaKV bcCmkcanGB8dwN9qAVXeFq0bgGg23l78/Vh+2URu63i4kL6rbL8IrsUajphVcaGo0p1o DCGUT1ZyTZzozq70BxDqd/9BceC67SsCQRtDG+b6gvhtMeI7IGnWyaUO1pLLQ9MY+Rnm kRJ8W9YlBxGQRd49fdrjWDjH6bES5PcP3usgYlBGy+av6883Rz/cSROOo61tiZ7LQxrJ 37cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=nIzFCX2XAvu0K+mTL79TxuwLFkbWdHbTPwvabLmd8sA=; b=mtUjqhDTKJ0a1DB7tqNMG4Rhudxli5YZEpoD5KGfgd4ASKlkyynFk3hjHi70AfZBWp negjNeDuReJVCPiC3a3ejoT3Picfws6INgg1+mp1oRhSSTG8lJJIUcv/fe33oIg1ia5x l/kIufzOP08f6VZF8n/R967cN+iNhq7p3yA4WjgoKrycVrXIKWd8JqH9MUg3x4AsfIO7 yXuI1Q7V/LLL5qYOLALmHQ+IKqRhpmEzYyZk6IXKLYAVxu7oebSHYSNDbaSYV4ECdSa2 jRmysxAIbZQENVDdB5/923wyjbA0fWdyag/NDt3qcLnQBnrchyjgnJgExzVOj3ERRWI7 Wpmg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=felix.moessbauer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id p65si132360wmp.0.2021.04.27.02.25.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Apr 2021 02:25:13 -0700 (PDT) Received-SPF: pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of felix.moessbauer@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=felix.moessbauer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id 13R9PCaV024649 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Apr 2021 11:25:13 +0200 Received: from MD1T0KAC-VM.ad001.siemens.net (md1t0kac.ad001.siemens.net [139.25.0.7]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id 13R9P5qb006138; Tue, 27 Apr 2021 11:25:12 +0200 From: Felix Moessbauer To: isar-users@googlegroups.com, amikan@ilbers.de, jan.kiszka@siemens.com Cc: henning.schild@siemens.com, Felix Moessbauer Subject: [PATCH v2 2/2] Add wrapper to load correct python perf module based on kernel Date: Tue, 27 Apr 2021 11:24:58 +0200 Message-Id: <20210427092458.4261-3-felix.moessbauer@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <4d3f03d0-817a-4815-1a37-ce91388463ab@ilbers.de> References: <4d3f03d0-817a-4815-1a37-ce91388463ab@ilbers.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: 1XqeIIKbU2HH This patch adds a wrapper around the versioned python bindings of perf. The wrapper takes care of detecting the current kernel version and loading the perf_ module. Then, it mapps this module to just perf, so downstream python modules just have to `import perf` instead of the versioned version. Signed-off-by: Felix Moessbauer --- .../files/debian/linux-base.install | 6 +++++ .../files/lib/python3/dist-packages/perf.py | 23 +++++++++++++++++ .../recipes-core/linux-base/linux-base_4.6.bb | 25 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 meta-isar/recipes-core/linux-base/files/debian/linux-base.install create mode 100644 meta-isar/recipes-core/linux-base/files/lib/python3/dist-packages/perf.py create mode 100644 meta-isar/recipes-core/linux-base/linux-base_4.6.bb diff --git a/meta-isar/recipes-core/linux-base/files/debian/linux-base.install b/meta-isar/recipes-core/linux-base/files/debian/linux-base.install new file mode 100644 index 0000000..b94175d --- /dev/null +++ b/meta-isar/recipes-core/linux-base/files/debian/linux-base.install @@ -0,0 +1,6 @@ +bin/linux-check-removal usr/bin +bin/linux-update-symlinks usr/bin +bin/linux-version usr/bin +bin/perf usr/bin +lib/DebianLinux.pm usr/share/perl5 +lib/python3/dist-packages/perf.py usr/lib/python3/dist-packages/ diff --git a/meta-isar/recipes-core/linux-base/files/lib/python3/dist-packages/perf.py b/meta-isar/recipes-core/linux-base/files/lib/python3/dist-packages/perf.py new file mode 100644 index 0000000..26d3e81 --- /dev/null +++ b/meta-isar/recipes-core/linux-base/files/lib/python3/dist-packages/perf.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +# Wrapper to load the kernel-specific version +# of the python perf module + +import platform + +uname = platform.uname().release +kvers = uname.split('.') + +if len(kvers) < 2: + raise RuntimeError('Could not detect kernel version in: {}'.format(kvers)) +try: + perf = __import__('perf_{}_{}'.format(kvers[0], kvers[1])) + symbols = [symbol for symbol in perf.__dict__ if not symbol.startswith("_")] + globals().update({symbol: getattr(perf, symbol) for symbol in symbols}) + del perf + del symbols +except ModuleNotFoundError: + raise ModuleNotFoundError('perf package not found. Install debian package linux-perf-{}.{}'.format(kvers[0],kvers[1])) + +del platform +del uname +del kvers diff --git a/meta-isar/recipes-core/linux-base/linux-base_4.6.bb b/meta-isar/recipes-core/linux-base/linux-base_4.6.bb new file mode 100644 index 0000000..178e4cb --- /dev/null +++ b/meta-isar/recipes-core/linux-base/linux-base_4.6.bb @@ -0,0 +1,25 @@ +# Patched version of linux-base that includes perf python wrapper +# +# This software is a part of ISAR. +# Copyright (c) Siemens AG, 2021 +# +# SPDX-License-Identifier: MIT + +inherit dpkg + +SRC_URI = " \ + apt://${PN} \ + file://lib/python3/dist-packages/perf.py \ + file://debian/linux-base.install \ + " + +MAINTAINER ?= "isar-users " +CHANGELOG_V ?= "+isar" + +do_prepare_build() { + mkdir -p ${S}/lib/python3/dist-packages + cp -r ${WORKDIR}/lib ${S} + cp -r ${WORKDIR}/debian ${S} + cd ${S} + deb_add_changelog +} -- 2.20.1