profiler icon indicating copy to clipboard operation
profiler copied to clipboard

Support importing Instruments profiles

Open rajmeghpara opened this issue 6 years ago • 17 comments

#1138

As a part of GSoC’19, this PR makes Firefox Profiler able to process and visualize profiles generated by Instruments Profiler which is a great macOS sampling profiler tool that’s part of Xcode toolset.

This allows users on macOS to use Firefox Profiler for analyzing and visualizing the Instruments profiles.

Example Instruments profile in Firefox Profiler: https://perfht.ml/2OOYDGY

Call Tree: Screenshot 2019-08-10 at 9 20 28 PM

Flame Graph: Screenshot 2019-08-10 at 9 21 03 PM

Stack Chart: Screenshot 2019-08-10 at 9 21 17 PM

┆Issue is synchronized with this Jira Task

rajmeghpara avatar Jul 09 '19 16:07 rajmeghpara

Codecov Report

Merging #2138 into master will decrease coverage by 0.36%. The diff coverage is 84.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2138      +/-   ##
==========================================
- Coverage   86.14%   85.77%   -0.37%     
==========================================
  Files         204      204              
  Lines       15149    14602     -547     
  Branches     3809     3658     -151     
==========================================
- Hits        13050    12525     -525     
+ Misses       1922     1899      -23     
- Partials      177      178       +1
Impacted Files Coverage Δ
src/components/app/Home.js 50.45% <0%> (-6.7%) :arrow_down:
src/profile-logic/import/instruments/BinReader.js 67.74% <67.74%> (ø)
src/actions/receive-profile.js 84.8% <75%> (-0.19%) :arrow_down:
...-logic/import/instruments/MaybeCompressedReader.js 83.87% <83.87%> (ø)
...file-logic/import/instruments/BinaryPlistParser.js 87.2% <87.2%> (ø)
src/profile-logic/import/instruments/index.js 87.46% <87.46%> (ø)
src/actions/publish.js 83.58% <0%> (-7.33%) :arrow_down:
src/selectors/per-thread/stack-sample.js 90.38% <0%> (-4.26%) :arrow_down:
src/components/timeline/TrackContextMenu.js 86.71% <0%> (-2.56%) :arrow_down:
src/components/marker-chart/Canvas.js 91.04% <0%> (-2.33%) :arrow_down:
... and 71 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0dfcbb6...065af02. Read the comment docs.

codecov[bot] avatar Aug 04 '19 13:08 codecov[bot]

I'll need a bit more time before I have time to look at this. Just letting everyone know.

gregtatum avatar Aug 19 '19 20:08 gregtatum

(I flagged myself so that I don't forget to look at it tomorrow)

julienw avatar Oct 07 '19 15:10 julienw

I think I answered all pending questions, but didn't look at the new code. Also I see some comments are still unresolved, do you need more information about them?

Also again, as you're doing that in your free time, please tell us if you'd like that we help you finishing this up, because this needs a bit of work still and I don't want to put pressure on you. This would be really a pleasure to help you with this :)

julienw avatar Oct 08 '19 17:10 julienw

I am no longer able to load a .trace file (/ directory) in the deploy preview using Firefox Nightly. Is this a Firefox Nightly bug? When I try to choose the .trace item in the file open dialog, Firefox always goes inside the directory and wants me to choose a file. But I want to choose the whole directory. Dragging and dropping the directory into the home page doesn't work either.

mstange avatar Oct 16 '19 20:10 mstange

@mstange I will check. Have you tried dropping a .trace file?

rajmeghpara avatar Oct 19 '19 09:10 rajmeghpara

Thanks @rajmeghpara, is it ready for another review?

julienw avatar Nov 18 '19 14:11 julienw

@julienw , There are 8 more comments which are unresolved. I'll try to resolve all of them by this week. Thanks! :)

rajmeghpara avatar Nov 18 '19 19:11 rajmeghpara

Thanks for the update!

julienw avatar Nov 19 '19 08:11 julienw

@julienw, Apple BinaryPlist data format is very unstructured. For example, root.$objects (one of the parameter in expandKeyedArchive function) array looks like this:

Screenshot 2019-11-23 at 3 20 27 PM

So it's hard to define a type for this kind of arrays or objects. That's why I had to put any types for these kinds of instances.

cc: @canova

rajmeghpara avatar Nov 23 '19 10:11 rajmeghpara

hey raj, a quick note that we didn't forget you, but we've been super busy lately. I still want to look at this soon...

julienw avatar Dec 07 '19 16:12 julienw

@julienw, It's completely fine :) Please review when you get time.

rajmeghpara avatar Dec 07 '19 22:12 rajmeghpara

@julienw, I have resolved your latest comments and made the changes. Thanks for your valuable comments!

rajmeghpara avatar Dec 14 '19 12:12 rajmeghpara

Whoa, I just found some actual documentation! It's packaged inside Instruments.app: file:///Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Packages/Sampling.instrdst/Contents/Documentation/fulldoc.html

If you view a profile in Instruments, you can access this documentation by going to: Main Menu -> Instrument -> Instrument Inspector -> Schemas -> time-profile. This documentation links to documentation on help.apple.com such as the one for the "backtrace" engineering type: https://help.apple.com/instruments/developer/mac/current/#/dev15401019

mstange avatar May 03 '20 18:05 mstange

I have a bug report: Inlined frames seem to be assigned to the wrong parent. It seems they're lifted up one level and become a sibling of their actual parent. To reproduce, load this trace: https://drive.google.com/file/d/1fAMdpODaax4Nk4m5jLUbOdulLt_y8MG2/view?usp=sharing

Instruments (correct): Screen Shot 2020-05-03 at 2 19 57 PM

Firefox profiler (incorrect): https://perfht.ml/3aY8qAx Screen Shot 2020-05-03 at 2 20 04 PM

In this example, the "count" method (_$LT$core..str..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$::count::h44f4fc8cdfe212bc) should be called by the "levenshtein_distance" method (rust::levenshtein_distance::levenshtein_distance::h9950dc9c996816c3). But in the imported profile, the "count" method is called by the "main" method instead (rust::main::_$u7b$$u7b$closure$u7d$$u7d$::h880a062807c5a68a).

mstange avatar May 03 '20 18:05 mstange

This implementation also seems to create huge frameTables / funcTables / stringTables. It seems every thread has all the strings for all the threads. And the frameTable.address values seem wrong.

mstange avatar Jul 15 '20 02:07 mstange

Is it worth keeping this PR open?

julienw avatar Jul 11 '25 15:07 julienw