Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perfetto output for using in ff profiler #16

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpcamara
Copy link
Contributor

@jpcamara jpcamara commented Dec 4, 2023

* Firefox Profiler requires a "traceEvents" key and that every row has a "name" key (which is not required by the perfetto spec for "E" phases)

* WIP - it's not fully functional yet
@jpcamara
Copy link
Contributor Author

jpcamara commented Dec 4, 2023

Once finished, this handles Add support for producing data in a format readable by the [Firefox Profiler](https://profiler.firefox.com/) or [Speedscope](https://www.speedscope.app/) here #13

Copy link
Owner

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting! I've been wanting to get this working for a bunch of time 🎉

Using the previous_state for all events I guess may be buggy when native threads get reused / GvlTracing gets started and stopped, but as you hinted, this will need a overhaul to support the MN scheduling on 3.3 anyway.

I've tried the output on the firefox profiler and it seems... odd -- I can see the events but the lanes at the top are all empty. Did you figure out if there's anything else missing? (or are we just emitting too little information, and that's how firefox profiler renders the info we have right now?)

case RUBY_INTERNAL_THREAD_EVENT_STARTED: return "started";
case RUBY_INTERNAL_THREAD_EVENT_EXITED: return "died";
case RUBY_INTERNAL_EVENT_GC_ENTER: return "gc";
// TODO: is it possible the thread wasn't running? Might need to save the last state.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can happen -- from what I've seen, Ruby always triggers GC in the thread that was running, since there's no background GC, so it's always something that the thread does that triggers GC.

fprintf(output_file,
// Finish previous duration
" {\"ph\": \"E\", \"pid\": %"PRId64", \"tid\": %"PRIu64", \"ts\": %f, \"name\": \"%s\"},\n",
process_id, thread_id, now_microseconds, previous_event_name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I'm getting this right, the firefox parser wants the event name to be included in both the begin and end phases of a duration event? That's.... kinda weird but ok 🤷‍♂️

@@ -195,14 +211,16 @@ static void render_event(const char *event_name) {
// Important note: We've observed some rendering issues in perfetto if the tid or pid are numbers that are "too big",
// see https://github.com/ivoanjo/gvl-tracing/pull/4#issuecomment-1196463364 for an example.

if (strcmp(event_name, "started_tracing") != 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: One alternative to avoid doing this every time would be to pass in the previous_event_name as NULL

@ivoanjo
Copy link
Owner

ivoanjo commented Mar 29, 2024

Btw now that Ruby 3.3 support seems to be in good shape, I'd love to get this in as well ;) (no pressure! haha)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants