Closed Bug 1528859 Opened 6 years ago Closed 2 years ago

Make "MOZ_PROFILER_SHUTDOWN=filename-%p.json" output profiles from all processes

Categories

(Core :: Gecko Profiler, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
108 Branch
Tracking Status
firefox67 --- wontfix
firefox108 --- fixed

People

(Reporter: mozbugz, Assigned: florian)

References

Details

Attachments

(1 file, 1 obsolete file)

Currently MOZ_PROFILER_SHUTDOWN only ends up producing the profile for the main thread.

(In fact, it's producing all of them, but they use the same name, and the main thread goes last and overwrites previous sub-process files!)

I'm proposing to change the meaning of the MOZ_PROFILER_SHUTDOWN arguments, from a full filename to a prefix name, so that each process may output its own profile in a separate file.
E.g., MOZ_PROFILER_SHUTDOWN="prof-" will generate "prof-123.json", "prof-127.json", where the numbers are process IDs.

It's not ideal, but I think it would be a good & easy first step until we can implement a better (more complicated) solution.
Maybe a small external utility could be created to stitch multiple profiles together, if deemed useful?

I've got a WIP patch working, I'll submit it for review soon, but please give feedback/criticism if you think of anything.

Alternative suggestion: Ignore MOZ_PROFILER_SHUTDOWN in content processes (or forcefully unset that variable when launching subprocesses in GetProfilerEnvVarsForChildProcess), and make the profile from the parent process include all the subprocess profiles. The subprocesses should already be sending their "exit profile" to the parent process, those exit profiles just need to be included.

Oh, now I see bug 1509533 again which wants to implement the proper fix. I don't think the proper fix is hard to do.

Thank you for the hint, I thought bug 1509533 would be more difficult (dealing with sending profiles across processes), I'll give it a try...

Will resolve bug 1509533 instead.

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WONTFIX

Reviving this bug, as it may still be needed to capture child processes (other than web content processes, which are captured thanks to bug 1509533).
Unless follow-up bug 1529131 can be fixed soon enough.

Status: RESOLVED → REOPENED
Depends on: 1509533
Resolution: WONTFIX → ---
See Also: 15095331529131

I've got a WIP with an imperfect* but working MOZ_PROFILER_SHUTDOWN=filename-%p.json, which will produce one file per process, then running Firefox again with MOZ_PROFILER_SHUTDOWN_COMBINE=filename-%p.json (notice "_COMBINE") will stitch the files together, and the resulting filename-C.json can be fed to profiler.firefox.com.

It's not perfect: It relies on the textual formatting produced by JSONWriter, and some processes get duplicated (but thankfully the frontend only displays the later and better ones), albeit with strange numbering (I'll open an issue for the frontend to fix that, if time permits).
I'm still putting it up for review and landing, because MOZ_PROFILER_SHUTDOWN without "%p" will work exactly like before, and I would guess few people will use it, so we don't need something super robust and sparkling clean, but at least it's there for the few people who may have a good need for it.

Example:
Parent process only, as the plain MOZ_PROFILER_SHUTDOWN would have produced: https://share.firefox.dev/30mApqg
Combined profile: https://share.firefox.dev/2WwocOH
Notice the added GPU Process, and the other sub-processes show a bit more data at their ends.

Summary: Make "MOZ_PROFILER_SHUTDOWN" output profiles from all processes → Make "MOZ_PROFILER_SHUTDOWN=filename-%p.json" output profiles from all processes

(In reply to Gerald Squelart [:gerald] (he/him) from comment #6)

Combined profile: https://share.firefox.dev/2WwocOH
Notice the added GPU Process, and the other sub-processes show a bit more data at their ends.

It's strange that the GPU Process starts during shutdown. I wonder what causes this process to start, and if it's something that happens frequently.

(In reply to Florian Quèze [:florian] (PTO until July 20th) from comment #7)

It's strange that the GPU Process starts during shutdown. I wonder what causes this process to start, and if it's something that happens frequently.

Oh, that was a full startup-to-shutdown profile! (Start Firefox, open wikipedia and click a couple of links, quit.)

But yes, it seems to start late, so maybe it did crash during profiling -- I remember a flash and some graphicky assertions, that must have been it. So we're only seeing the last respawned GPU process.

Running it again now, I see those flashes, with a !TimeStamp::IsNull() in ImageComposite::SetImages, I think it's in the profiler marker code that computes time jitter. That's why it doesn't happen in non-profiled code. I'll file a bug...

Upcoming GPU process fix in bug 1654106.

New profiles after fix:

But landing the _COMBINE patch is delayed, I was using <filesystem> APIs that are only available on Windows. 😭

(In reply to Gerald Squelart [:gerald] (he/him) from comment #9)

Upcoming GPU process fix in bug 1654106.

New profiles after fix:

In this profile we spend a lot of time GC'ing after the last IPC, I don't think that's very useful (it takes 200 to 400ms per child process to cleanup after the last IPC), but this profile is from a debug build, so the behavior may be very different from what we would normally see.

These profiles are a demonstration of the fact that we can obtain the profiles and merge them, their content isn't all that relevant, there's not much need to analyze them (other than checking that the relevant processes are present).

If the filename given to MOZ_PROFILER_SHUTDOWN contains "%p", all processes will write their own profile, and change "%p" in the filename to 'P'/'S' (Parent/Subprocess) and their process id.

The filename given to MOZ_PROFILER_SHUTDOWN_COMBINE should be the exact same one as given to MOZ_PROFILER_SHUTDOWN (including "%p").
All files will be stitched together into one output file, the filename is the same as the others but with "%p" replaced with "C".

Note that the implementation is minimal and inflexible, it relies on the textual format output by MOZ_PROFILER_SHUTDOWN.
Also, some sub-process may actually be present multiple times (because they were both sent through IPCs and then saved to a shutdown file), but the frontend helpfully only keeps that later one, which is from the shutdown file and actually contains a bit more data (from after the IPC output) -- though these duplicated processes will manifest in strange numberings, e.g., "Content Process (2/2)" but no "Content Process (1/2)".

Depends on D157193

Sadly I won't have time to finish this.
The first patch should work fine, and doesn't affect the normal use of MOZ_PROFILER_SHUTDOWN without "%p".
However I don't think it's really useful without the second patch that stitches the separate files together, but that patch is not ready to ship:

  • It uses <filesystem>, which I think is not available on all our platforms.
  • It relied on the old JSON generation with lots of spaces and lines! So it would probably have to be redone, maybe by using a real JSON parser to read the files, stitch them as JSON objects, and save the result. Maybe it would be better as a separate python or js program?
Assignee: mozbugz → nobody
Severity: normal → S3
Assignee: nobody → florian
Attachment #9294397 - Attachment is obsolete: true
Attachment #9294396 - Attachment description: WIP: Bug 1528859 - Write files from all processes with MOZ_PROFILER_SHUTDOWN=file-%p.json → Bug 1528859 - Replace %p with the process id in the MOZ_PROFILER_SHUTDOWN environment variable, r=canaltinova.
Pushed by fqueze@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/509ae9259314 Replace %p with the process id in the MOZ_PROFILER_SHUTDOWN environment variable, r=canaltinova.
Status: REOPENED → RESOLVED
Closed: 6 years ago2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 108 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: