[PATCH v1 19/58] perf python: Add config file access

From: Ian Rogers

Date: Sun Apr 19 2026 - 20:04:37 EST


Enhance the perf Python module by adding lazy address resolution and
Add perf.config_get(name) to expose the perf configuration system.

Assisted-by: Gemini:gemini-3.1-pro-preview
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/python.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 6baf38a08690..e5f96bc695fd 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -12,6 +12,7 @@
#include "build-id.h"
#include "callchain.h"
#include "comm.h"
+#include "config.h"
#include "counts.h"
#include "data.h"
#include "debug.h"
@@ -3130,7 +3131,26 @@ static PyObject *pyrf__syscall_id(PyObject *self, PyObject *args)
return PyLong_FromLong(id);
}

+static PyObject *pyrf__config_get(PyObject *self, PyObject *args)
+{
+ const char *config_name, *val;
+
+ if (!PyArg_ParseTuple(args, "s", &config_name))
+ return NULL;
+
+ val = perf_config_get(config_name);
+ if (!val)
+ Py_RETURN_NONE;
+ return PyUnicode_FromString(val);
+}
+
static PyMethodDef perf__methods[] = {
+ {
+ .ml_name = "config_get",
+ .ml_meth = (PyCFunction) pyrf__config_get,
+ .ml_flags = METH_VARARGS,
+ .ml_doc = PyDoc_STR("Get a perf config value.")
+ },
{
.ml_name = "metrics",
.ml_meth = (PyCFunction) pyrf__metrics,
--
2.54.0.rc1.513.gad8abe7a5a-goog