Closed alexcoco closed 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.
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
isobject
:StackListProfileBuilder
to use the number of samples (since each sample is one allocation)nSamples
(which I believe is always1
but I'm not positive)Here's what it looks like before and after my changes (note the units and weight of samples):
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. 🙇