From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 839EBFF885C for ; Sat, 25 Apr 2026 22:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nmZaRmxvqC34085lIoL5dgTRYciZnOOQN4pPPp0OcBc=; b=TVLD8qe6RpA/qzzQWne81vcHxi AduBDM8zZcygjBjskIM4bCnqWQqF8g+u6nisywkE8hsAR3KRhnkS2VnOgbsz1WCP/NiCBX1F0+1Tr gfDjIhH9Zgxeeuj9QQYevy4Pc/+FtjYonSUtPPD+YOcBHqR6CM6hWkG5ZWiE1NbDvSZxzqwShAJRB 8OwQQhWwiDH8UxoPVeTDb7Lq9yetb+sLiySZ3fyxd7Bqup25tH4NeG4nQNrQwxVYCgf2jm1jzVj+n qO/KAg2uUN2OZzV4PeVTToNTWLYHZb6I5/PPCbHHYMRU8fdDLXsqDjj01MabqIOFF+NF2DPoO641O fd9TeDIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wGlqE-0000000EynW-0qN2; Sat, 25 Apr 2026 22:51:14 +0000 Received: from mail-dy1-x134a.google.com ([2607:f8b0:4864:20::134a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wGlpn-0000000EyJw-3CZ7 for linux-arm-kernel@lists.infradead.org; Sat, 25 Apr 2026 22:50:55 +0000 Received: by mail-dy1-x134a.google.com with SMTP id 5a478bee46e88-2bda35eab74so7738800eec.0 for ; Sat, 25 Apr 2026 15:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777157447; x=1777762247; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nmZaRmxvqC34085lIoL5dgTRYciZnOOQN4pPPp0OcBc=; b=lMkEYBBy8MZLEBSSNGWnxwkcWz54i36zk3OtUnP2Sg1kYK5NrNQpRdxpzTKRtpOSh8 y+s1DVLhvuHQISdQNGsM5AenrKCYra3sMswWPBVtWloFU8dUYuz0zG7Vs7MCAOmZFcXD fqXm+W1Rp2JBKIxiKBKkAmO8MUeWgtniSNOXNJX1RYHJFhIDg8vh3QPn3tukF/0+0mRl y1ojTFDpWB5RSuGYIf7jOLn29TSWtwvHETealsBzx8kbjZomGrxRk0w+7n1ozP5UjV8u Rt/Q44SoPlXlUI5GyTS8sX50Y2XXaDKBlBoXLqFF0f6FtA6W81Qwqseqa/UwNF+BbXI8 tpVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777157447; x=1777762247; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nmZaRmxvqC34085lIoL5dgTRYciZnOOQN4pPPp0OcBc=; b=entQeTM5csC1SPOwIQPySmy8Q1HCYH3rzmd9aM+e9cXKL922BzykO+zeg56K/2YSL8 t3hVDG/oXy+5bILvFMaAd1ymkXf9bphAjQkrQzrFYkNRj0veG6pCR+0xEGfo85WY3exC Hh4rmUuYjf2QZdQI4KMKOADG29nNZH+n2UvS0ACZvkHme/vp7MfED42juVhFz5jkbQ6w LILNB3cFgze4XvwtSxcPYZNwLQ+BE1+RgaG82mH6R7+60dId/jVsZuM8XoyP2Br8DP5b mj8jx6rhxOt2cWRTRldWtiokcLtDuDMwG0Y12bVJo6QALX+ukW8tlOep+2iiKt57rscm 85/Q== X-Forwarded-Encrypted: i=1; AFNElJ9z/Umboq4h4ktVdX+3WJdl/81deABvoGlOJmisEizu3+/It7yRD02Zs+EF+ntrH91U7MsPf3wz01uBuqs6NAhl@lists.infradead.org X-Gm-Message-State: AOJu0Yydgqe+leYpdevTiVYWPa8YGEAI/ubmUm3zLPQirRpWbi29Ct8H tPY9dlgjtkD4x4QbBvNqqjMQXB6RyJiClhm7F0y/V9GVfEXaryYfWkIHVpmlUN1oT9VeFSc4gRj tqoTb3PZbfA== X-Received: from dycpq4.prod.google.com ([2002:a05:7301:fd04:b0:2df:6abf:7cee]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:e12a:b0:2d3:9c91:6c45 with SMTP id 5a478bee46e88-2e42c84c585mr16800947eec.6.1777157446435; Sat, 25 Apr 2026 15:50:46 -0700 (PDT) Date: Sat, 25 Apr 2026 15:49:08 -0700 In-Reply-To: <20260425224951.174663-1-irogers@google.com> Mime-Version: 1.0 References: <20260425174858.3922152-1-irogers@google.com> <20260425224951.174663-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260425224951.174663-17-irogers@google.com> Subject: [PATCH v7 16/59] perf python: Add syscall name/id to convert syscall number and name From: Ian Rogers To: acme@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, leo.yan@linux.dev, namhyung@kernel.org, tmricht@linux.ibm.com Cc: alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260425_155047_845282_0DF9C1EE X-CRM114-Status: GOOD ( 16.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use perf's syscalltbl support to convert syscall number to name assuming the number is for the host machine. This avoids python libaudit support as tools/perf/scripts/python/syscall-counts.py requires. Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers --- v2: 1. Guarded with HAVE_LIBTRACEEVENT : Wrapped the syscall functions and their entries in perf__methods with #ifdef HAVE_LIBTRACEEVENT to avoid potential linker errors if CONFIG_TRACE is disabled. 2. Changed Exception Type: Updated pyrf__syscall_id to raise a ValueError instead of a TypeError when a syscall is not found. 3. Fixed Typo: Corrected "name number" to "name" in the docstring for syscall_id. v6: - Added optional keyword-only `elf_machine` argument to `syscall_name` and `syscall_id`. v7: - Made syscalltbl.o unconditional in Build to fix undefined symbol when building without libtraceevent. --- tools/perf/util/Build | 2 +- tools/perf/util/python.c | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 70cc91d00804..fd55d02dd433 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -75,7 +75,7 @@ perf-util-y += sample.o perf-util-y += sample-raw.o perf-util-y += s390-sample-raw.o perf-util-y += amd-sample-raw.o -perf-util-$(CONFIG_TRACE) += syscalltbl.o +perf-util-y += syscalltbl.o perf-util-y += ordered-events.o perf-util-y += namespaces.o perf-util-y += comm.o diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 1af53480661f..861973144106 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -13,6 +13,7 @@ #include "counts.h" #include "data.h" #include "debug.h" +#include "dwarf-regs.h" #include "event.h" #include "evlist.h" #include "evsel.h" @@ -25,6 +26,7 @@ #include "session.h" #include "strbuf.h" #include "symbol.h" +#include "syscalltbl.h" #include "thread.h" #include "thread_map.h" #include "tool.h" @@ -2669,6 +2671,40 @@ static int pyrf_session__setup_types(void) return PyType_Ready(&pyrf_session__type); } +static PyObject *pyrf__syscall_name(PyObject *self, PyObject *args, PyObject *kwargs) +{ + const char *name; + int id; + int elf_machine = EM_HOST; + static char * const kwlist[] = { "id", "elf_machine", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|$i", kwlist, &id, &elf_machine)) + return NULL; + + name = syscalltbl__name(elf_machine, id); + if (!name) + Py_RETURN_NONE; + return PyUnicode_FromString(name); +} + +static PyObject *pyrf__syscall_id(PyObject *self, PyObject *args, PyObject *kwargs) +{ + const char *name; + int id; + int elf_machine = EM_HOST; + static char * const kwlist[] = { "name", "elf_machine", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|$i", kwlist, &name, &elf_machine)) + return NULL; + + id = syscalltbl__id(elf_machine, name); + if (id < 0) { + PyErr_Format(PyExc_ValueError, "Failed to find syscall %s", name); + return NULL; + } + return PyLong_FromLong(id); +} + static PyMethodDef perf__methods[] = { { .ml_name = "metrics", @@ -2702,6 +2738,18 @@ static PyMethodDef perf__methods[] = { .ml_flags = METH_NOARGS, .ml_doc = PyDoc_STR("Returns a sequence of pmus.") }, + { + .ml_name = "syscall_name", + .ml_meth = (PyCFunction) pyrf__syscall_name, + .ml_flags = METH_VARARGS | METH_KEYWORDS, + .ml_doc = PyDoc_STR("Turns a syscall number to a string.") + }, + { + .ml_name = "syscall_id", + .ml_meth = (PyCFunction) pyrf__syscall_id, + .ml_flags = METH_VARARGS | METH_KEYWORDS, + .ml_doc = PyDoc_STR("Turns a syscall name to a number.") + }, { .ml_name = NULL, } }; -- 2.54.0.545.g6539524ca2-goog