lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aC3SjgsOWMh07G_K@x1>
Date: Wed, 21 May 2025 10:18:06 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Gautam Menghani <gautam@...ux.ibm.com>,
	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>,
	Howard Chu <howardchu95@...il.com>, linux-kernel@...r.kernel.org,
	linux-perf-users@...r.kernel.org, maddy@...ux.ibm.com
Subject: Re: [PATCH v3 5/7] perf python: Add evsel read method

On Mon, May 19, 2025 at 12:51:42PM -0700, Ian Rogers wrote:
> From: Gautam Menghani <gautam@...ux.ibm.com>
> 
> Add the evsel read method to enable python to read counter data for the
> given evsel.
> 
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> Signed-off-by: Gautam Menghani <gautam@...ux.ibm.com>
> ---
> Ian modified from v2 to make the API take a CPU and thread then

I'll add this note right before your Signed-off-by, with a link to the
discussion, i.e. as:

Signed-off-by: Gautam Menghani <gautam@...ux.ibm.com>
Link: https://lore.kernel.org/linux-perf-users/20250512055748.479786-1-gautam@linux.ibm.com/
[ make the API take a CPU and thread then compute from these the appropriate indices.
Signed-off-by: Ian Rogers <irogers@...gle.com>

> compute from these the appropriate indices. This was discussed as the
> preferred API with Arnaldo:
> https://lore.kernel.org/linux-perf-users/20250512055748.479786-1-gautam@linux.ibm.com/
> ---
>  tools/perf/util/python.c | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 1cbddfe77c7c..281e706e102d 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
> @@ -888,6 +888,37 @@ static PyObject *pyrf_evsel__threads(struct pyrf_evsel *pevsel)
>  	return (PyObject *)pthread_map;
>  }
>  
> +static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel,
> +				  PyObject *args, PyObject *kwargs)
> +{
> +	struct evsel *evsel = &pevsel->evsel;
> +	int cpu = 0, cpu_idx, thread = 0, thread_idx;
> +	struct perf_counts_values counts;
> +	struct pyrf_counts_values *count_values = PyObject_New(struct pyrf_counts_values,
> +							       &pyrf_counts_values__type);
> +
> +	if (!count_values)
> +		return NULL;
> +
> +	if (!PyArg_ParseTuple(args, "ii", &cpu, &thread))
> +		return NULL;
> +
> +	cpu_idx = perf_cpu_map__idx(evsel->core.cpus, (struct perf_cpu){.cpu = cpu});
> +	if (cpu_idx < 0) {
> +		PyErr_Format(PyExc_TypeError, "CPU %d is not part of evsel's CPUs", cpu);
> +		return NULL;
> +	}
> +	thread_idx = perf_thread_map__idx(evsel->core.threads, thread);
> +	if (cpu_idx < 0) {
> +		PyErr_Format(PyExc_TypeError, "Thread %d is not part of evsel's threads",
> +			     thread);
> +		return NULL;
> +	}
> +	perf_evsel__read(&(evsel->core), cpu_idx, thread_idx, &counts);
> +	count_values->values = counts;
> +	return (PyObject *)count_values;
> +}
> +
>  static PyObject *pyrf_evsel__str(PyObject *self)
>  {
>  	struct pyrf_evsel *pevsel = (void *)self;
> @@ -918,6 +949,12 @@ static PyMethodDef pyrf_evsel__methods[] = {
>  		.ml_flags = METH_NOARGS,
>  		.ml_doc	  = PyDoc_STR("threads the event is to be used with.")
>  	},
> +	{
> +		.ml_name  = "read",
> +		.ml_meth  = (PyCFunction)pyrf_evsel__read,
> +		.ml_flags = METH_VARARGS | METH_KEYWORDS,
> +		.ml_doc	  = PyDoc_STR("read counters")
> +	},
>  	{ .ml_name = NULL, }
>  };
>  
> -- 
> 2.49.0.1101.gccaa498523-goog
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ