Closed gaogaotiantian closed 2 years ago
Hmm a couple of thoughts:
All in all the idea is not bad but I feel this is so high-cost (given the complexities above) and low-benefit and I don't think will be worth getting to in O(years)
.proto
definition, seems like the structure is already in. https://cs.android.com/android/platform/superproject/+/master:external/perfetto/protos/perfetto/trace/track_event/source_location.proto This is exactly the data I mentioned. I don't think this will increase the size of trace events significantly, at least not significantly more than other possible info.source_location.proto is really for things like PostTask in chromium that take a FROM_HERE macro that tells the location in the source code that posted a task (maybe you want something similar though?), is not filled for all events.
The great benefit from this is, when you share the trace log to a colleague, they can see the exact source file you've used, without having to checkout anything, in a single click. Also it would be much easier for anyone to quickly check the source code of a slice.
Yeah but how would the UI know how to lookup the actual source? Unless you pass a full url, like a github-based source URL?
The UI won't get access to the file, the file is stored into the trace log as a string
Oooh wait but then who would take care of storing the full source file into the trace? I mean from at some point you build an executable and run it. How would you inject the source file into the trace at that point?
source_location.proto
is exactly what I'm looking for in trace packets. The user could optionally use this field to store the source file info for the slice I think? It's already in TrackEvent
anyway. Of course if it's conflicting with existing logic, a similar field is fine. I do think this name and it's position represents the exact needs for me though.
Yes I meant storing the full source file(or the selected source file that's interesting) into the trace. The trace creator should be responsible for this, in C++ the Perfetto SDK could utilize __FILE__
and __LINE__
macro(again, this is optional). I'm not familiar with Perfetto trace generating part. I'm thinking from VizTracer point of view, and packing the source file into the trace data is already something I do now.
Actually, a github-based source URL is not a bad idea either, but the sync(making sure the source file matches the executable) is more complicated.
I believe TrackEvent these days has SourceLocation quite well supported (including offline symbolization) so closing this.
This is a long shot but I think it would be very interesting for perfetto to support source file display when users click on certain slices. It would be useful to quickly debug the code without switching between tabs.
The source files could be stored in protobuf as a
TracePacket
, with a unique id and it's file type(Java, C++). For eachtrack_event
, there could be optionalfile_id
andfile_lineno
fields, indicating where the original code generated this slice. As both of them are integers, the extra overhead on speed and size won't be much. The file name and line number is actually pretty accessible in C++ with macros.In the front end, on the callback that currently shows
Slice Details
, the right half of the panel is unused, which could be used to display source code. I've attached an image of modified catapult trace viewer(which is the front-end of VizTracer now) as an example.Personally, I think this is very helpful when I'm looking at the trace report, and it's not a burden in the front end.
Is this a feature worth considering?