From patchwork Thu Sep 5 10:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13792154 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 129BCCD5BA9 for ; Thu, 5 Sep 2024 10:57:26 +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-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=lYfiCJsSv3gXTfpU8JIawVQNlE 2NRaOQR5fpZvsjK3jYQTbS8lsHLIj/HASPVHA9kp6WZ7cG/OR/M9ytM5Wu1PAHBMeEV+I+W2aiJEv tsKb1n8aeq0tjv8l7V5HyTNppYLG7SHzEfc+Az8GtZ6YorAfrvFNeQ/jtYHgUBm3D4grTWUxvzjBq Oa9PawtVpqc/HE0UN1yEJuF8isbb6hH9040S0pMS3n1oytEr2Ztr3ZIZMZ2g29VtUYh6l1LFrlZKY 5j2RhRcL+HVq/HjA+c1X7lDbsrGnMW99csG+YdJKCDxH7lkmQ1UWiEieaN+EvwZCF1ubOpz886879 jOZhKQmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smAAu-000000082qp-43J1; Thu, 05 Sep 2024 10:57:16 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA5F-000000081RE-13Jx for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:51:29 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42bc19e94bdso4673675e9.3 for ; Thu, 05 Sep 2024 03:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725533483; x=1726138283; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=cMPX2M/PkOQl2n0Ozp6EnzXdmNcBQdIdKcDCvD5ULBORJzlwmIaarUcjDLTI/nLcW5 PzAeRnAZ8XKdVCDaa4kvaaqvWbb54Ve3WhDsoJalsJGRKxHRLw3UxmRdRP8txqkZYvNH 4f7DkNzO/LdJc9flDtV6cCA2R93lXt+X/IARbA099DY1Vp0GtTITjejQzrbOOO358vwr +x55lGTyxt3/AZoyHpuFb0xfEXnKN7xTd5kr9z3QGuSS7gXYjYiUqH2a6rloe3hqcVSh jeBZSkxL0aZ6wFpUkqX0AFgXc3mlZLV0HTkA+f3qlbLK407esw0oI0jFIwruIU/fDWoV GmAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725533483; x=1726138283; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGGfB6w3kWS1PGl7UZ8XD03PjQ67uo73eIy0DvIbGgM=; b=EMBnqMNio5unMD31UCXPgsMcRU20xQkBWdYfYFDk2BWLfEqj+pQTC4VZ2MsZK3BLYf 5VWEoCR5Sx0lwizzkR5sF6MDoR7ttYkcbMmxZGKaLJUdri1RVTHeC0ZlLT7FRSX854j5 52H/u/TsdXsJrDExYyC+K1A8vTdTbvyERqiB6en2IeXBfPk/UFe0HIjVtqwYsni5KZe0 /vOnsOtrnqDmsWYhfn1N1BlNjAOIgSp8/w+NkHpwWoG5sFbKrO1jni9zhlnRQpcQyA5Q M6SSxn8EI9zmsqqHP9Zbjzj8TWVq85dbIyA8qUkvpid+EnvDBX56oT7IqnWhwxls0z/e EzCg== X-Forwarded-Encrypted: i=1; AJvYcCXmWRs/5u4QcnTvFb4U/0bYX2189q75Y0xKBzwVcPLUYlUV2sIpeCAckbnrxXOLS66rp2SrjeTuMqX2JNDRWtAL@lists.infradead.org X-Gm-Message-State: AOJu0YzFKTtMhdjQ1tOjN2Yc9fFjUAVTuVYENgYEX0ghkk4d8LPA4l9e w04vT1SLj8PmvPkEtuTRDjjdYO22X7Dqa0eCy2xx+RsOUPG/TRgk80KIcQqsSfo= X-Google-Smtp-Source: AGHT+IEL1yvO9/AmK9ifjqYg7iMQs4H/ox7GyqpcdtMyB1K5iTwls0MsnKmwOXtbuu/kXAMOTl2r5Q== X-Received: by 2002:a05:600c:241:b0:427:9a8f:9717 with SMTP id 5b1f17b1804b1-42c8e41bef0mr47718195e9.0.1725533483317; Thu, 05 Sep 2024 03:51:23 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6df0dbcsm231089965e9.17.2024.09.05.03.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 03:51:22 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, gankulkarni@os.amperecomputing.com, coresight@lists.linaro.org, leo.yan@arm.com, scclevenger@os.amperecomputing.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Leo Yan , Ben Gainey , Ruidong Tian , Benjamin Gray , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/8] perf scripting python: Add function to get a config value Date: Thu, 5 Sep 2024 11:50:35 +0100 Message-Id: <20240905105043.160225-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905105043.160225-1-james.clark@linaro.org> References: <20240905105043.160225-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_035125_296049_E3A68D0E X-CRM114-Status: GOOD ( 19.44 ) 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 This can be used to get config values like which objdump Perf uses for disassembly. Signed-off-by: James Clark --- .../perf/Documentation/perf-script-python.txt | 2 +- .../scripts/python/Perf-Trace-Util/Context.c | 11 ++++++++++ tools/perf/util/config.c | 22 +++++++++++++++++++ tools/perf/util/config.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt index 13e37e9385ee..27a1cac6fe76 100644 --- a/tools/perf/Documentation/perf-script-python.txt +++ b/tools/perf/Documentation/perf-script-python.txt @@ -624,7 +624,7 @@ as perf_trace_context.perf_script_context . perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already perf_sample_srcline(context) - returns source_file_name, line_number perf_sample_srccode(context) - returns source_file_name, line_number, source_line - + perf_config_get(config_name) - returns the value of the named config item, or None if unset Util.py Module ~~~~~~~~~~~~~~ diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c index 3954bd1587ce..01f54d6724a5 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -12,6 +12,7 @@ #define PY_SSIZE_T_CLEAN #include +#include "../../../util/config.h" #include "../../../util/trace-event.h" #include "../../../util/event.h" #include "../../../util/symbol.h" @@ -182,6 +183,15 @@ static PyObject *perf_sample_srccode(PyObject *obj, PyObject *args) return perf_sample_src(obj, args, true); } +static PyObject *__perf_config_get(PyObject *obj, PyObject *args) +{ + const char *config_name; + + if (!PyArg_ParseTuple(args, "s", &config_name)) + return NULL; + return Py_BuildValue("s", perf_config_get(config_name)); +} + static PyMethodDef ContextMethods[] = { #ifdef HAVE_LIBTRACEEVENT { "common_pc", perf_trace_context_common_pc, METH_VARARGS, @@ -199,6 +209,7 @@ static PyMethodDef ContextMethods[] = { METH_VARARGS, "Get source file name and line number."}, { "perf_sample_srccode", perf_sample_srccode, METH_VARARGS, "Get source file name, line number and line."}, + { "perf_config_get", __perf_config_get, METH_VARARGS, "Get perf config entry"}, { NULL, NULL, 0, NULL} }; diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 7a650de0db83..68f9407ca74b 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -912,6 +912,7 @@ void set_buildid_dir(const char *dir) struct perf_config_scan_data { const char *name; const char *fmt; + const char *value; va_list args; int ret; }; @@ -939,3 +940,24 @@ int perf_config_scan(const char *name, const char *fmt, ...) return d.ret; } + +static int perf_config_get_cb(const char *var, const char *value, void *data) +{ + struct perf_config_scan_data *d = data; + + if (!strcmp(var, d->name)) + d->value = value; + + return 0; +} + +const char *perf_config_get(const char *name) +{ + struct perf_config_scan_data d = { + .name = name, + .value = NULL, + }; + + perf_config(perf_config_get_cb, &d); + return d.value; +} diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h index 2e5e808928a5..9971313d61c1 100644 --- a/tools/perf/util/config.h +++ b/tools/perf/util/config.h @@ -30,6 +30,7 @@ typedef int (*config_fn_t)(const char *, const char *, void *); int perf_default_config(const char *, const char *, void *); int perf_config(config_fn_t fn, void *); int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3); +const char *perf_config_get(const char *name); int perf_config_set(struct perf_config_set *set, config_fn_t fn, void *data); int perf_config_int(int *dest, const char *, const char *);