[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZyPcowY1YlRTTJN2@x1>
Date: Thu, 31 Oct 2024 16:38:11 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>,
James Clark <james.clark@...aro.org>,
Howard Chu <howardchu95@...il.com>,
Athira Jajeev <atrajeev@...ux.vnet.ibm.com>,
Michael Petlan <mpetlan@...hat.com>,
Veronika Molnarova <vmolnaro@...hat.com>,
Dapeng Mi <dapeng1.mi@...ux.intel.com>,
Thomas Richter <tmricht@...ux.ibm.com>,
Ilya Leoshkevich <iii@...ux.ibm.com>,
Colin Ian King <colin.i.king@...il.com>,
Weilin Wang <weilin.wang@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
Josh Poimboeuf <jpoimboe@...hat.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v5 20/21] perf python: Add __str__ and __repr__ functions
to evsel
On Wed, Oct 30, 2024 at 06:42:51PM -0700, Ian Rogers wrote:
> This allows evsel to be shown in the REPL like:
> ```
> Python 3.11.9 (main, Jun 19 2024, 00:38:48) [GCC 13.2.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> sys.path.insert(0, '/tmp/perf/python')
> >>> import perf
> >>> x=perf.parse_events('cycles,data_read')
> >>> print(x)
> evlist([cycles,uncore_imc_free_running_0/data_read/,uncore_imc_free_running_1/data_read/])
> >>> x[0]
> evsel(cycles)
> >>> x[1]
> evsel(uncore_imc_free_running_0/data_read/)
> >>> x[2]
> evsel(uncore_imc_free_running_1/data_read/)
> ```
Tested-by: Arnaldo Carvalho de Melo <acme@...hat.com>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
> tools/perf/util/python.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index a71bad3418da..0d71ec673aa3 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
> @@ -781,6 +781,17 @@ static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel,
> return Py_None;
> }
>
> +static PyObject *pyrf_evsel__str(PyObject *self)
> +{
> + struct pyrf_evsel *pevsel = (void *)self;
> + struct evsel *evsel = &pevsel->evsel;
> +
> + if (!evsel->pmu)
> + return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel));
> +
> + return PyUnicode_FromFormat("evsel(%s/%s/)", evsel->pmu->name, evsel__name(evsel));
> +}
> +
> static PyMethodDef pyrf_evsel__methods[] = {
> {
> .ml_name = "open",
> @@ -802,6 +813,8 @@ static PyTypeObject pyrf_evsel__type = {
> .tp_doc = pyrf_evsel__doc,
> .tp_methods = pyrf_evsel__methods,
> .tp_init = (initproc)pyrf_evsel__init,
> + .tp_str = pyrf_evsel__str,
> + .tp_repr = pyrf_evsel__str,
> };
>
> static int pyrf_evsel__setup_types(void)
> --
> 2.47.0.163.g1226f6d8fa-goog
>
Powered by blists - more mailing lists