Shopify / yjit-bench

Set of benchmarks for the YJIT CRuby JIT compiler and other Ruby implementations.
MIT License
87 stars 22 forks source link

Add harnesses to profile with stackprof and vernier #316

Closed rwstauner closed 3 months ago

rwstauner commented 3 months ago

Auto install the gems outside of any gems the benchmark might require. Save the file to the data dir and show a report when finished.

I've been using this to get allocation info:

$ STACKPROF_OPTS='mode:object' MIN_BENCH_TIME=1 MIN_BENCH_ITRS=1 RBENV_VERSION=ruby-master ruby -v -I harness-stackprof benchmarks/protoboeuf-encode/benchmark.rb
ruby 3.4.0dev (2024-08-01T19:54:08Z master f6e829603e) [arm64-darwin23]
Adding to load path: /Users/rwstauner/.rubies/ruby-master/lib/ruby/gems/3.4.0+0/gems/stackprof-0.2.26/lib
==================================
  Mode: object(1)
  Samples: 175 (0.00% miss rate)
  GC: 0 (0.00%)
==================================
     TOTAL    (pct)     SAMPLES    (pct)     FRAME
       132  (75.4%)         132  (75.4%)     String#+@
        12   (6.9%)          12   (6.9%)     #<Object:0x0000000104a4ed68>.fetch
       174  (99.4%)           8   (4.6%)     Object#run_enough_to_profile
         7   (4.0%)           6   (3.4%)     ProtoBoeuf::ParkingSpace#_encode
       149  (85.1%)           4   (2.3%)     ProtoBoeuf::ParkingLot.encode
         3   (1.7%)           3   (1.7%)     Object#get_time
        11   (6.3%)           3   (1.7%)     ProtoBoeuf::ParkingFloor#_encode
       151  (86.3%)           2   (1.1%)     block (2 levels) in <main>
        13   (7.4%)           2   (1.1%)     ProtoBoeuf::ParkingLot#_encode
         1   (0.6%)           1   (0.6%)     ProtoBoeuf::Vehicle#_encode
         1   (0.6%)           1   (0.6%)     BasicObject#!=
       175 (100.0%)           1   (0.6%)     Object#run_benchmark
       151  (86.3%)           0   (0.0%)     Integer#times
       151  (86.3%)           0   (0.0%)     block in <main>
       151  (86.3%)           0   (0.0%)     Array#each
       168  (96.0%)           0   (0.0%)     Kernel#loop
       175 (100.0%)           0   (0.0%)     <main>
       175 (100.0%)           0   (0.0%)     StackProf.run
Stackprof dump file:
/Users/rwstauner/src/github.com/Shopify/yjit-bench/data/stackprof-object-2024-08-01-155820-ruby-3.4.0-protoboeuf-encode.dump

You can then run further stackprof analysis on the file shown at the end.

rwstauner commented 3 months ago

Does that seem like a good level of commenting? I want it to be helpful without being too much to read or too likely to become out of date.

maximecb commented 3 months ago

Does that seem like a good level of commenting? I want it to be helpful without being too much to read or too likely to become out of date.

Sure this seems good. Thank you :)