Where does perfetto store thread name?

57 views
Skip to first unread message

程洋

unread,
Sep 3, 2024, 9:49:15 AM9/3/24
to Perfetto Development - www.perfetto.dev
In document "https://perfetto.dev/docs/reference/trace-packet-proto#ProcessTree"
thread name should be stored in ProcessTree.Threads.name.

However when i use python to parse the perfetto like this. All name field of ProcessTree.threads.name is empty. So where does perfetto store the thread name?


def debugTrace(trace):
    t = perfetto_trace_pb2.Trace()
    with open(trace, "rb") as f:
        t.ParseFromString(f.read())


    for packet in t.packet:
        if packet.HasField("process_tree"):
            process_tree = packet.process_tree

            for process in process_tree.processes:
                pid = process.pid
                if pid not in process_dict:
                    process_dict[pid] = {
                        "threads": {}
                    }

            for thread in process_tree.threads:
                tid = thread.tid
                tgid = thread.tgid
                thread_name = thread.name if thread.HasField("name") else "Unknown"
                if tgid in process_dict:
                    process_dict[tgid]["threads"][tid] = thread_name

Lalit Maganti

unread,
Sep 3, 2024, 9:55:43 AM9/3/24
to 程洋, Perfetto Development - www.perfetto.dev
It is very very very strongly discouraged to parse the protos directly. Please use https://perfetto.dev/docs/analysis/trace-processor for processing Perfetto traces. Trace protos are *not* an stable API for reading, things move around all the time. You are signing up for a lot of pain if you try and parse the protos directly.


All of these are rationalized into the `thread` table of trace processor so you don't have to worry about any of this. If you parse the protos, you will have to deal with all of this and it's painful: we've spent 6 years shaking out all the subtle issues you get by doing this.

Just as an example of the pain: your Python code is not handling the case of pid reuse: tids get reused *all* the time and your code is not dealing with that at all.

--
You received this message because you are subscribed to the Google Groups "Perfetto Development - www.perfetto.dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to perfetto-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/perfetto-dev/606418e0-0162-4213-a0f2-bfcd7f05fc98n%40googlegroups.com.

Lalit Maganti

unread,
Sep 3, 2024, 10:04:49 AM9/3/24
to 程洋, Perfetto Development - www.perfetto.dev

程洋

unread,
Sep 4, 2024, 9:52:47 PM9/4/24
to Perfetto Development - www.perfetto.dev
Thanks for your kind reply.
What we want to do is align 2 traces across devices (such as remote control), and the merge 2 traces into 1.
vperfetto is a good example.
And  your explaination makes senses. We will try to figure out how does it work.

Lalit Maganti

unread,
Sep 4, 2024, 9:54:16 PM9/4/24
to 程洋, Perfetto Development - www.perfetto.dev
Adding support for merging traces natively in Perfetto is almost complete: there are just small bits and pieces to finish

You'd be much better off waiting for that than trying to do something externally. 


程洋

unread,
Sep 5, 2024, 12:19:02 AM9/5/24
to Perfetto Development - www.perfetto.dev
That's cool. Thanks!

ja alex

unread,
Nov 4, 2024, 4:33:46 AM11/4/24
to Perfetto Development - www.perfetto.dev
Is there git commit link to this change?  Could we try the merge trace functionality with latest v48.1 release? 

Lalit Maganti

unread,
Nov 4, 2024, 4:35:09 AM11/4/24
to ja alex, Perfetto Development - www.perfetto.dev


On Mon, 4 Nov 2024, 09:33 ja alex, <lurke...@gmail.com> wrote:
Is there git commit link to this change?  Could we try the merge trace functionality with latest v48.1 release? 

Merging has not been fully implemented yet, it's still a hidden work in progress feature. Once it's ready, it'll be very obviously available in the UI. 

Reply all
Reply to author
Forward
0 new messages