From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Yicong Yang <yangyicong@hisilicon.com>,
James Clark <james.clark@linaro.org>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
Levi Yun <yeoreum.yun@arm.com>, Ze Gao <zegao2021@gmail.com>,
Weilin Wang <weilin.wang@intel.com>, Xu Yang <xu.yang_2@nxp.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Howard Chu <howardchu95@gmail.com>
Subject: Re: [PATCH v2 11/11] perf python tracepoint: Switch to using parse_events
Date: Tue, 11 Mar 2025 18:54:57 -0700 [thread overview]
Message-ID: <Z9DpcfWqV7_Za3uu@google.com> (raw)
In-Reply-To: <Z9CwrQTEJoT_rRNA@x1>
On Tue, Mar 11, 2025 at 06:52:45PM -0300, Arnaldo Carvalho de Melo wrote:
> On Tue, Mar 11, 2025 at 03:49:37PM -0300, Arnaldo Carvalho de Melo wrote:
> > So it seems to be something just in the python binding, as perf trace
> > seems to handle it well:
> >
> > ( field 'prev_comm' ret=0x7f7c31f65110, raw_size=68 ) ( field 'prev_pid' ret=0x7f7c23b1bed0, raw_size=68 ) ( field 'prev_prio' ret=0x7f7c239c0030, raw_size=68 ) ( field 'prev_state' ret=0x7f7c239c0250, raw_size=68 ) time 14771421785867 prev_comm= prev_pid=1919907691 prev_prio=796026219 prev_state=0x303a32313175 ==>
> > ( XXX '��' len=16, raw_size=68) ( field 'next_comm' ret=(nil), raw_size=68 ) Traceback (most recent call last):
> > File "/home/acme/git/perf-tools-next/tools/perf/python/tracepoint.py", line 51, in <module>
> > main()
> > File "/home/acme/git/perf-tools-next/tools/perf/python/tracepoint.py", line 46, in main
> > event.next_comm,
> > ^^^^^^^^^^^^^^^
> > AttributeError: 'perf.sample_event' object has no attribute 'next_comm'
> > root@number:/home/acme/git/perf-tools-next# cat /proc/125355/comm
> > kworker/u112:0-i915
> > root@number:/home/acme/git/perf-tools-next#
> > root@number:/home/acme/git/perf-tools-next#
> > root@number:/home/acme/git/perf-tools-next# perf trace -e sched:sched_switch -p 125355
> > 0.000 sched:sched_switch(prev_comm: "kworker/u112:0", prev_pid: 125355 (kworker/u112:0-), prev_prio: 120, prev_state: 128, next_comm: "swapper/6", next_prio: 120)
> > ^Croot@number:/home/acme/git/perf-tools-next#
> >
> > I.e. it chops up the prev_comm size to what is specified in the
> > tracepoint format.
> >
> > And that sample->raw_size is the same accross the sched:sched_switch
> > raw_datas (seemingly suboptimal, most are less than 16 bytes, but
> > probably its not guaranteed that the \0 will be there, so copy all the
> > 16 bytes).
> >
> > Now to try to figure out why simply using PyUnicode_FromStringAndSize
> > doesn't work...
>
> Didn't manage to make progress on this, I spent more time than I
> expected as I think this could be some sort of canary on some coal mine,
> but with the patch below, that gives up and just avoids touching the
> COMM fields and don't switch from string to bytearray in the binding, it
> runs forever, this is just a data point in case somebody wants to
> pursue.
>
> That flipping from string to not string based on just one entry not
> being acceptable is questionable, and I think it should go away, but why
> when COMM fields are bigger what is alloted to them in the tracepoint
> ends up tripping up just the python binding is something I couldn't
> grasp in today's session.
>
> Namhyung, this is something open, but not caused by Ian's patchset, for
> which I give my:
>
> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Thanks for the analysis!
>
> In addition to the tags I provided patch by patch.
Ian, can you check if it works well for you?
Thanks,
Namhyung
> diff --git a/tools/perf/python/tracepoint.py b/tools/perf/python/tracepoint.py
> index 38b2b6d11f64566a..965b50afbdafeeb2 100755
> --- a/tools/perf/python/tracepoint.py
> +++ b/tools/perf/python/tracepoint.py
> @@ -33,15 +33,12 @@ def main():
> if not isinstance(event, perf.sample_event):
> continue
>
> - print("time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % (
> - event.sample_time,
> - event.prev_comm,
> - event.prev_pid,
> - event.prev_prio,
> - event.prev_state,
> - event.next_comm,
> - event.next_pid,
> - event.next_prio))
> + try:
> + print("time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % (
> + event.sample_time, event.prev_comm, event.prev_pid, event.prev_prio, event.prev_state, event.next_comm, event.next_pid, event.next_prio))
> + except:
> + print("time %u prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_pid=%d next_prio=%d" % (
> + event.sample_time, event.prev_pid, event.prev_prio, event.prev_state, event.next_pid, event.next_prio))
>
> if __name__ == '__main__':
> main()
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 6c5bb5e8893998ae..3eb77bd270077cb3 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
> @@ -318,13 +318,10 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
> if (tep_field_is_relative(field->flags))
> offset += field->offset + field->size;
> }
> - if (field->flags & TEP_FIELD_IS_STRING &&
> - is_printable_array(data + offset, len)) {
> + if (field->flags & TEP_FIELD_IS_STRING)
> ret = PyUnicode_FromString((char *)data + offset);
> - } else {
> + else
> ret = PyByteArray_FromStringAndSize((const char *) data + offset, len);
> - field->flags &= ~TEP_FIELD_IS_STRING;
> - }
> } else {
> val = tep_read_number(pevent, data + field->offset,
> field->size);
next prev parent reply other threads:[~2025-03-12 1:55 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 22:22 [PATCH v2 00/11] Python improvements for a real use of parse_events Ian Rogers
2025-02-28 22:22 ` [PATCH v2 01/11] perf debug: Avoid stack overflow in recursive error message Ian Rogers
2025-03-10 20:22 ` Arnaldo Carvalho de Melo
2025-03-10 20:22 ` Arnaldo Carvalho de Melo
2025-02-28 22:22 ` [PATCH v2 02/11] perf evlist: Add success path to evlist__create_syswide_maps Ian Rogers
2025-03-10 20:31 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 03/11] perf evsel: tp_format accessing improvements Ian Rogers
2025-03-10 20:43 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 04/11] perf python: Add evlist enable and disable methods Ian Rogers
2025-03-10 20:45 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 05/11] perf python: Add member access to a number of evsel variables Ian Rogers
2025-03-10 20:45 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 06/11] perf python: Add optional cpus and threads arguments to parse_events Ian Rogers
2025-03-10 20:46 ` Arnaldo Carvalho de Melo
2025-03-10 22:12 ` Namhyung Kim
2025-03-11 0:28 ` Ian Rogers
2025-03-12 1:51 ` Namhyung Kim
2025-02-28 22:23 ` [PATCH v2 07/11] perf python: Update ungrouped evsel leader in clone Ian Rogers
2025-03-10 20:53 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 08/11] perf python: Avoid duplicated code in get_tracepoint_field Ian Rogers
2025-03-10 20:55 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 09/11] perf python: Add evlist all_cpus accessor Ian Rogers
2025-03-10 20:56 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 10/11] perf python: Add evlist.config to set up record options Ian Rogers
2025-03-10 20:59 ` Arnaldo Carvalho de Melo
2025-02-28 22:23 ` [PATCH v2 11/11] perf python tracepoint: Switch to using parse_events Ian Rogers
2025-03-10 21:15 ` Arnaldo Carvalho de Melo
2025-03-10 21:16 ` Arnaldo Carvalho de Melo
2025-03-10 21:17 ` Ian Rogers
2025-03-10 21:28 ` Arnaldo Carvalho de Melo
2025-03-11 15:32 ` Arnaldo Carvalho de Melo
2025-03-11 17:06 ` Arnaldo Carvalho de Melo
2025-03-11 18:49 ` Arnaldo Carvalho de Melo
2025-03-11 21:52 ` Arnaldo Carvalho de Melo
2025-03-12 1:54 ` Namhyung Kim [this message]
2025-03-10 22:17 ` Namhyung Kim
2025-03-10 23:40 ` Ian Rogers
2025-03-12 1:53 ` Namhyung Kim
2025-03-07 2:07 ` [PATCH v2 00/11] Python improvements for a real use of parse_events Howard Chu
2025-03-12 19:53 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9DpcfWqV7_Za3uu@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=howardchu95@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@treblig.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=weilin.wang@intel.com \
--cc=xu.yang_2@nxp.com \
--cc=yangyicong@hisilicon.com \
--cc=yeoreum.yun@arm.com \
--cc=zegao2021@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox