From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 324A93A6F0A for ; Thu, 23 Apr 2026 16:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776962094; cv=none; b=l9wbaaHWCbXJ4xu/yD2E9trUmdpxRjlkcKtlzCXbMPJJ/ykFxwDATxbOj8UYErcHZmB26t0JiYJmywuO2XBHDc4iAq6ujnGTqEJvk8DyF26SVIDVCfsOlISbvzNPd/Ep0dwMa+ixLqD4CMQW+M/PheoNWy2QVj3VlQrxxAGi9YI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776962094; c=relaxed/simple; bh=/WAm6bqeJBhq2D+iKPcDWe1EhSKPK75SqyvYyfliOWY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WVqBEEqnyd1oazhUvJd3/shirIj2iIwHZZ+Hi+xegwNhU/zITxTFQR6FUDBw7HWtiBeBsXqAHoLFbbMk+5mwSPLh3QrfLfw32e8bfXu5CEbBki9mVVmFg9IYj7mYHN12WgX7drLGUCLl5d+peM9yn6rdwU1qh5dOCszf0y44BN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eijyD7Gl; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eijyD7Gl" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2ba8013a9e3so7408656eec.0 for ; Thu, 23 Apr 2026 09:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776962092; x=1777566892; darn=vger.kernel.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=CWf6Qami7NRlFpvOBe8d9c6H2MSbHEw6hdBOQg4jYMQ=; b=eijyD7GlRmilElDvgKiG4OmKCNFwafugKzj1DcCuK9Al87F+ZOESwLMyQ9sjkPkeVa n69Aq8wpsN90sKK2K43+Ub/1IgxB4g9mrOIqFKU/jml/Nr9IwxQ4wBmS4vX+XbTL/fQW +ilX+tzjQUPRJAGFjq301BA1LB4CyNGiuKOhkKalizDZwO1lVEeqLWbxnDxCC09h8nrr zW6Wi/6tkLKptrq/3sL0Ih/njnpTtOZymwNJlXCepXCQbQ5vTgGzmEfsKUGq4qs7g0T3 famJeOp6yR2edQUj3xWAO7McO9YBfJDeyfCdwtqZgJuiu70qXI0nLQRuANMcNm40n/Vj AMXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776962092; x=1777566892; 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=CWf6Qami7NRlFpvOBe8d9c6H2MSbHEw6hdBOQg4jYMQ=; b=eJxH90+pi4aX8HNerJuVJlaUb+FW42cosj73K4W5C3Udtb2Jav1H9sXxdIXoSVXHb2 lWPl2Q5qxL2/gLd8C7mzUXaBgMCE6rDnmvGK//sGLIKgCeMEtLl+01N2cbJ3BPilp8wN n80e2zNxSGbhzzc7t3Y7g16nIRGF16qoWN0ja77JsJVU5q27niB5ERE3PK7XXtigGDAr pIDgw/4qrC62RBApGEUXu+oP2nRs5fn9BYvbIM1g5vNcuGThWFjhwKvNQ5z3n/xypwZO exHwhV+q85wsgQgEBw7hRogjH09vcI88wKWnIUmb9XmMJe1r9E5akqcFBnYZAw15+trK Qjnw== X-Forwarded-Encrypted: i=1; AFNElJ+6E2OhK/HsbTwQ001Jz7rBJKuhGCvQMrR9/SEQsdE9Uag4dDuSMfvY7BvAT19MqJh+7rGgmIUMJRglr84=@vger.kernel.org X-Gm-Message-State: AOJu0YyCB1vKcWw+QZT5PGQzR1hAiPWdojIUdJVZm4UDasryn/bSbMaO Qe2JlXZfSqWq128SAXbR4ROauGw/SnMuPRzRC9bjRaCmo7jrhxuaTIX836egI6++OrywfoOPZ49 w92Wxy6cbpg== X-Received: from dlak21.prod.google.com ([2002:a05:701b:2915:b0:12c:71e:5ab3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:48c:b0:128:ca83:5aa3 with SMTP id a92af1059eb24-12c73f6d910mr15777795c88.1.1776962092033; Thu, 23 Apr 2026 09:34:52 -0700 (PDT) Date: Thu, 23 Apr 2026 09:33:24 -0700 In-Reply-To: <20260423163406.1779809-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260423161006.1762700-1-irogers@google.com> <20260423163406.1779809-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260423163406.1779809-17-irogers@google.com> Subject: [PATCH v4 16/58] perf python: Add syscall name/id to convert syscall number and name From: Ian Rogers To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, james.clark@linaro.org, leo.yan@linux.dev, namhyung@kernel.org, tmricht@linux.ibm.com Cc: 9erthalion6@gmail.com, adityab1@linux.ibm.com, alexandre.chartre@oracle.com, alice.mei.rogers@gmail.com, ankur.a.arora@oracle.com, ashelat@redhat.com, atrajeev@linux.ibm.com, blakejones@google.com, changbin.du@huawei.com, chuck.lever@oracle.com, collin.funk1@gmail.com, coresight@lists.linaro.org, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dsterba@suse.com, gautam@linux.ibm.com, howardchu95@gmail.com, john.g.garry@oracle.com, jolsa@kernel.org, jonathan.cameron@huawei.com, justinstitt@google.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mike.leach@arm.com, mingo@redhat.com, morbo@google.com, nathan@kernel.org, nichen@iscas.ac.cn, nick.desaulniers+lkml@gmail.com, pan.deng@intel.com, peterz@infradead.org, ravi.bangoria@amd.com, ricky.ringler@proton.me, stephen.s.brennan@oracle.com, sun.jian.kdev@gmail.com, suzuki.poulose@arm.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, terrelln@fb.com, thomas.falcon@intel.com, tianyou.li@intel.com, tycho@kernel.org, wangyang.guo@intel.com, xiaqinxin@huawei.com, yang.lee@linux.alibaba.com, yuzhuo@google.com, zhiguo.zhou@intel.com, zli94@ncsu.edu Content-Type: text/plain; charset="UTF-8" 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. --- tools/perf/util/python.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 35eda69a32e1..f240905e07d6 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" @@ -2635,6 +2637,36 @@ static int pyrf_session__setup_types(void) return PyType_Ready(&pyrf_session__type); } +static PyObject *pyrf__syscall_name(PyObject *self, PyObject *args) +{ + const char *name; + int id; + + if (!PyArg_ParseTuple(args, "i", &id)) + return NULL; + + name = syscalltbl__name(EM_HOST, id); + if (!name) + Py_RETURN_NONE; + return PyUnicode_FromString(name); +} + +static PyObject *pyrf__syscall_id(PyObject *self, PyObject *args) +{ + const char *name; + int id; + + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + + id = syscalltbl__id(EM_HOST, 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", @@ -2668,6 +2700,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, + .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, + .ml_doc = PyDoc_STR("Turns a syscall name to a number.") + }, { .ml_name = NULL, } }; -- 2.54.0.rc2.533.g4f5dca5207-goog