Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf scripting python: Add function to get a config value

This can be used to get config values like which objdump Perf uses for
disassembly.

Reviewed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Tested-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ruidong Tian <tianruidong@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: coresight@lists.linaro.org
Cc: John Garry <john.g.garry@oracle.com>
Cc: scclevenger@os.amperecomputing.com
Link: https://lore.kernel.org/r/20240916135743.1490403-4-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

James Clark and committed by
Namhyung Kim
9943581c ba5ae78a

+35 -1
+1 -1
tools/perf/Documentation/perf-script-python.txt
··· 624 624 perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already 625 625 perf_sample_srcline(context) - returns source_file_name, line_number 626 626 perf_sample_srccode(context) - returns source_file_name, line_number, source_line 627 - 627 + perf_config_get(config_name) - returns the value of the named config item, or None if unset 628 628 629 629 Util.py Module 630 630 ~~~~~~~~~~~~~~
+11
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 12 12 #define PY_SSIZE_T_CLEAN 13 13 14 14 #include <Python.h> 15 + #include "../../../util/config.h" 15 16 #include "../../../util/trace-event.h" 16 17 #include "../../../util/event.h" 17 18 #include "../../../util/symbol.h" ··· 183 182 return perf_sample_src(obj, args, true); 184 183 } 185 184 185 + static PyObject *__perf_config_get(PyObject *obj, PyObject *args) 186 + { 187 + const char *config_name; 188 + 189 + if (!PyArg_ParseTuple(args, "s", &config_name)) 190 + return NULL; 191 + return Py_BuildValue("s", perf_config_get(config_name)); 192 + } 193 + 186 194 static PyMethodDef ContextMethods[] = { 187 195 #ifdef HAVE_LIBTRACEEVENT 188 196 { "common_pc", perf_trace_context_common_pc, METH_VARARGS, ··· 209 199 METH_VARARGS, "Get source file name and line number."}, 210 200 { "perf_sample_srccode", perf_sample_srccode, 211 201 METH_VARARGS, "Get source file name, line number and line."}, 202 + { "perf_config_get", __perf_config_get, METH_VARARGS, "Get perf config entry"}, 212 203 { NULL, NULL, 0, NULL} 213 204 }; 214 205
+22
tools/perf/util/config.c
··· 912 912 struct perf_config_scan_data { 913 913 const char *name; 914 914 const char *fmt; 915 + const char *value; 915 916 va_list args; 916 917 int ret; 917 918 }; ··· 939 938 va_end(d.args); 940 939 941 940 return d.ret; 941 + } 942 + 943 + static int perf_config_get_cb(const char *var, const char *value, void *data) 944 + { 945 + struct perf_config_scan_data *d = data; 946 + 947 + if (!strcmp(var, d->name)) 948 + d->value = value; 949 + 950 + return 0; 951 + } 952 + 953 + const char *perf_config_get(const char *name) 954 + { 955 + struct perf_config_scan_data d = { 956 + .name = name, 957 + .value = NULL, 958 + }; 959 + 960 + perf_config(perf_config_get_cb, &d); 961 + return d.value; 942 962 }
+1
tools/perf/util/config.h
··· 30 30 int perf_default_config(const char *, const char *, void *); 31 31 int perf_config(config_fn_t fn, void *); 32 32 int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3); 33 + const char *perf_config_get(const char *name); 33 34 int perf_config_set(struct perf_config_set *set, 34 35 config_fn_t fn, void *data); 35 36 int perf_config_int(int *dest, const char *, const char *);