jlfwong / speedscope

🔬 A fast, interactive web-based viewer for performance profiles.
https://www.speedscope.app
MIT License
5.58k stars 247 forks source link

Support stackprof object mode #391

Closed alexcoco closed 2 years ago

alexcoco commented 2 years ago

First off, apologies for not opening and issue to discuss this ahead of time as recommended in the contributing guide -- I kind of worked on this on a whim this morning.

This PR attempts to support stackprof's object mode which tracks the number of allocated objects. This differs from the other modes (cpu and wall) by taking samples every time a Ruby object is allocated using Ruby's NEWOBJ tracepoint.

When importing an object mode profile into speedscope today it still works but what you see is a profile using time units. The profile will only have samples for when an object was allocated which means even if time is reported, the profile is not really meaningful when looking at time.

To address this I've done three things when mode is object:

Here's what it looks like before and after my changes (note the units and weight of samples):

wall (before) object (before) object (after)
Screen Shot 2022-05-11 at 4 51 31 PM Screen Shot 2022-05-11 at 4 51 34 PM Screen Shot 2022-05-11 at 4 51 42 PM
Test code ```ruby require 'stackprof' require 'json' def do_test 5.times do make_a_word end end def make_a_word ('a'..'z').to_a.shuffle.map(&:upcase).join end StackProf.start(mode: :object, interval: 1, raw: true) do_test StackProf.stop File.write('tmp/object_profile.json', JSON.generate(StackProf.results)) StackProf.start(mode: :wall, interval: 1, raw: true) do_test StackProf.stop File.write('tmp/wall_profile.json', JSON.generate(StackProf.results)) ```

Finally, I am not super familiar with TypeScript and even less familiar with this codebase so I'm not sure what tests, if any, are needed for a change like this. I'm happy to add whatever else is needed. 🙇

jlfwong commented 2 years ago

Hi @alexcoco! Thanks for adding this -- this seems totally reasonable to me.

Before this can land, this needs tests to cover the new codepath. You can see how the other test for stackprof works by looking here: https://github.com/jlfwong/speedscope/blob/main/src/import/stackprof.test.ts

That test file was generated, I believe, using the following test file: https://github.com/jlfwong/speedscope/blob/main/sample/programs/ruby/simple.rb

Please include the ruby file you used to profile, and a new profile. Both the program and the resulting profile should be as short as possible while still exercising the core functionality.

Let me know if you need any help!

Speedscope is badly in need of a new release. I'm planning on doing that sometime in the next month.

coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.06%) to 41.14% when pulling 9e856e354567dcb0cb7a2db2461def43d76bb8f4 on alexcoco:stackprof-object-mode into e37f6fa7c38c110205e22081560b99cb89ce885e on jlfwong:main.