From patchwork Thu Sep 12 15:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13802298 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 A4502EED613 for ; Thu, 12 Sep 2024 15:24:24 +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=ucTLjSrDPBW7itralIk9qlLv2Y 4+eYhavqWCsX4r2Nl+IzGJFwSH5IrJKtXr/kRT3M4V066H7k3j/oSedMM0paSafNtG/uTNbUbgbgi IKsqWaJ9ct8KkKI/EfUoMGjy4MZk32JuAhYprTR8jYt72DfLfV2MUTvrPES3p0ECRUhffBl4w0FnS T7FDcGB901O3B1zH6BAzJIeRsUaPLnfKqEBuxhw6xbzSqNH4+JcXLx4SrFNww9flLST08UEF6Pcvh RW8jrwDfTa2TakMyJvRSo7jb554swuhRrNzTdfXdO+UuTz2dFVCB4SRRUdxtKfMIjvpMhK6C3di/G dp/NAcPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1solg2-0000000DXpG-1BUb; Thu, 12 Sep 2024 15:24:10 +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 1solUx-0000000DV8n-38FC for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 15:12:45 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso10190475e9.2 for ; Thu, 12 Sep 2024 08:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726153962; x=1726758762; 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=xBfafZ0qDvMnmNpmTFzW3++iPIrz0nA2T54JYAUS3UduaLKyzopk77T09z/w4I08EP JQgkm73Uh2hqPaV8S1DQSgW0kk1fws5CfUNWRdLl/v0G6Dwro+ne6vU5iIL3xAzDEo41 gK4VDTwGVu66AV+oIfM4DwCE3FLtqgpEWY7PTM371W1moiTAODDA6muH9lcrLVbk5irP BeCFb96A/gvBC5H0v0S9krHua80g/euy/uj7k9RBJWW3cH4bEKWgg77i74CwBJ2kHlhp F00Su3iD34YOOI6N7Z37YeWKztoDAEGk4xJw1+1UkT9yWQxu3Ps+WReGr/VWDT90dUhV vaRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726153962; x=1726758762; 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=PDjS38J6+2ERowBtDehh9qJKpkdWwomIoipNbtyntcErlCbSQ//DtR3SfgnwhWae8J K9pKMWhzEZ2T113unF5GzKyEPwERJA/2luDGB/Jw+MFd4PPNHQxPadRf6LX1gATur1jL grH+3xOz0zFhseVKMI07/rmlyIt2yxoyH98xNdkUi+o3BAZTtKEj6Jdlvh15/bGn00fN KcUAZB2Sn5GPww/wYHqbb00Oxro0a/ThxLrLvwA23eJ49y3Bmy111FQURyantik4ZxY4 fODUFpY7lUaNcGf4rzROZ2r7hmUGbsFSQAsKkyckYwVuiC7fmnkEJDQ2kiOClpKESXfL HKVw== X-Forwarded-Encrypted: i=1; AJvYcCXPa10J+eM1nA9txXjtx5UYPNyhm/vDZKbiwt27uMFWrbpGkuTNPGCRMCi6LeEXa0JpzRkeut/25YaS5/QoviOG@lists.infradead.org X-Gm-Message-State: AOJu0Yx+K+mtd1Ys0WNBoD94ebIJsRWtv1jblBVyQjJShB2y7ggCJXCr pvY1zYy9PpHYBtpaxbdEFJyPzJwHQuAhJh7dssY2h+9Wa09pbBQeSC4LQnFswUU= X-Google-Smtp-Source: AGHT+IHHXQ3L4ph9W3/LKP4w6PXlKUgz1FmPRZxqdPxBCXFwutCTMRNnHYk9J1u/W+htrP1UYDcjqA== X-Received: by 2002:a05:600c:35c1:b0:42c:bfb1:766e with SMTP id 5b1f17b1804b1-42cdb55006fmr26068025e9.21.1726153962042; Thu, 12 Sep 2024 08:12:42 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb0dbcb6bsm171928845e9.30.2024.09.12.08.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 08:12:41 -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 v2 3/7] perf scripting python: Add function to get a config value Date: Thu, 12 Sep 2024 16:11:34 +0100 Message-Id: <20240912151143.1264483-4-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912151143.1264483-1-james.clark@linaro.org> References: <20240912151143.1264483-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-20240912_081243_821610_350BE344 X-CRM114-Status: GOOD ( 19.70 ) 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 Reviewed-by: Leo Yan --- .../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 *);