Repository: jlfwong/speedscope
Pull request #425 (2023-06-06 12:50:45)

Stackprof: weight on-cpu samples by period rather than timestamp delta
This attempts to improve the quality of the on-CPU profiles stackprof provides. Rather than weighing samples by their timestamp deltas, which, in our opinion, are only valid in wall-clock mode, this weighs callchains by:


```
S = number of samples
P = sample period in nanoseconds

W = S * P
```

The difference after this change is quite substantial, specially in profiles that previously were showing up with heavy IO frames:  

* Total profile weight is almost down by 90%, which actually makes sense for an on-CPU profile if the app is relatively idle
* Certain callchains that blocked in syscalls / IO are now much lower weight. This was what I was expecting to find.
Here is an example of the latter point.

In delta mode, we see an io select taking a long time, it is a significant portion of the profile:

<img width="1100" alt="236936508-709bee01-d616-4246-ba74-ab004331dcd3" src="https://github.com/dalehamel/speedscope/assets/4398256/39140f1e-50a9-4f33-8a61-ec98b6273fd4">

But in period scaling mode, it is only a couple of sample periods ultimately:

<img width="206" alt="236936693-9d44304e-a1c2-4906-b3c8-50e19e6f9f27" src="https://github.com/dalehamel/speedscope/assets/4398256/7d19077f-ef25-4d79-980b-cfa1775d928d">


jlfwong: Hi @manuelfelipe!

This seems reasonable to me! Can you please include tests which would catch changes to this behaviour were it to break. I think this would mean including a new profile with the `cpu` mode set in https://github.com/jlfwong/speedscope/blob/main/src/import/stackprof.test.ts
coveralls: 
[![Coverage Status](https://coveralls.io/builds/60568732/badge)](https://coveralls.io/builds/60568732)

coverage: 41.983% (-0.05%) from 42.032% when pulling **5fc7787badc875c5792080e76250a464e4f5ebd8 on dalehamel:stackprof-cpu-weight-fixes-upstream** into **0414c2f617742e7fb0cf31a66ac0f77c2f5c0540 on jlfwong:main**.

manuelfelipe: thanks @jlfwong. Rebased base on latest changes on main, and re-ran `run jest -- -u` in https://github.com/jlfwong/speedscope/pull/425/commits/2b92d51817072d50d69a5827adce7061f14b581e to try and get CI happy. 


Not sure I fully understand what is the actual thing failing failure in https://github.com/jlfwong/speedscope/actions/runs/5201005116/jobs/9543115054.  Locally tests are passing, so hoping the thing that was causing the issue are the outdated snapshots. 
dalehamel: FYI @jlfwong I enabled actions on my fork, Manuel pushed to it, and it passes there https://github.com/dalehamel/speedscope/actions/runs/5280170594 (since we cannot run workflows here, this seemed the most expedient way).

Patch:
diff --git a/sample/profiles/stackprof/simple-cpu-stackprof.json b/sample/profiles/stackprof/simple-cpu-stackprof.json
new file mode 100644
index 0000000..ea9fddc
--- /dev/null
+++ b/sample/profiles/stackprof/simple-cpu-stackprof.json
@@ -0,0 +1,1 @@
+{"version":1.2,"mode":"cpu","interval":1000,"samples":489,"gc_samples":79,"missed_samples":0,"metadata":{},"frames":{"5335909920":{"name":"Object#d","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":24,"total_samples":331,"samples":331,"edges":{"5335909920":331},"lines":{"27":[291,291],"26":[331,0],"28":[40,40]}},"5335911040":{"name":"Object#b","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":12,"total_samples":154,"samples":0,"edges":{"5335909920":154,"5335911040":154},"lines":{"14":[154,0],"13":[154,0]}},"5335911080":{"name":"Object#a","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":4,"total_samples":410,"samples":0,"edges":{"5335911040":154,"5335911080":410,"5335910560":177,"5335909880":79},"lines":{"6":[154,0],"5":[410,0],"7":[177,0],"8":[79,0]}},"4530486680":{"name":"block in <main>","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":37,"total_samples":410,"samples":0,"edges":{"5335911080":410},"lines":{"38":[410,0]}},"4530376200":{"name":"<main>","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","total_samples":410,"samples":0,"edges":{"4530486680":410},"lines":{"37":[410,0]}},"5352342240":{"name":"<main>","file":"sample/programs/ruby/simple.rb","total_samples":410,"samples":0,"edges":{"4530376200":410}},"5335910560":{"name":"Object#c","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":18,"total_samples":177,"samples":0,"edges":{"5335909920":177,"5335910560":177},"lines":{"20":[177,0],"19":[177,0]}},"5335909880":{"name":"Object#e","file":"/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb","line":32,"total_samples":79,"samples":79,"lines":{"33":[79,79]}},"5":{"name":"(sweeping)","file":"","total_samples":71,"samples":71},"1":{"name":"(garbage collection)","file":"","total_samples":79,"samples":0,"edges":{"5":71,"3":8}},"3":{"name":"(marking)","file":"","total_samples":8,"samples":8}},"raw":[9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,5,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,3,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,3,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,2,1,5,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,5,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,4,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,4,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,2,1,5,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,5,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,2,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,4,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,3,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,5,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,1,2,1,5,2,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,2,1,5,1,6,5352342240,4530376200,4530486680,5335911080,5335911080,5335909880,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,4,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335911040,5335911040,5335909920,5335909920,2,2,1,5,1,9,5352342240,4530376200,4530486680,5335911080,5335911080,5335910560,5335910560,5335909920,5335909920,3],"raw_sample_timestamps":[1290743986341,1290743987775,1290743990708,1290744045501,1290744052386,1290744054263,1290744055506,1290744107906,1290744109038,1290744116579,1290744117869,1290744171455,1290744173235,1290744174824,1290744176358,1290744179990,1290744181456,1290744234994,1290744236042,1290744237076,1290744238111,1290744239130,1290744240458,1290744243783,1290744244998,1290744300469,1290744301528,1290744310104,1290744366089,1290744370786,1290744372828,1290744375716,1290744378528,1290744432576,1290744433593,1290744434679,1290744442403,1290744443765,1290744445132,1290744499474,1290744505143,1290744508121,1290744509473,1290744511947,1290744566414,1290744576396,1290744632952,1290744633982,1290744635065,1290744642949,1290744644124,1290744698775,1290744700389,1290744702574,1290744708405,1290744713830,1290744768203,1290744769357,1290744772270,1290744775487,1290744832637,1290744834590,1290744835764,1290744839414,1290744842412,1290744899664,1290744900699,1290744902236,1290744907867,1290744908937,1290744909993,1290744911025,1290744963299,1290744964335,1290744972463,1290744974392,1290745033163,1290745035467,1290745089049,1290745092414,1290745099043,1290745100927,1290745101914,1290745103346,1290745155408,1290745156598,1290745159823,1290745164475,1290745165519,1290745166841,1290745167863,1290745220282,1290745221566,1290745230276,1290745285986,1290745287196,1290745291247,1290745292992,1290745295972,1290745352253,1290745362237,1290745364785,1290745418541,1290745420383,1290745427374,1290745428540,1290745485384,1290745486395,1290745487435,1290745488511,1290745492381,1290745494549,1290745553048,1290745559210,1290745563032,1290745564864,1290745621531,1290745623450,1290745624514,1290745625956,1290745626971,1290745630035,1290745631517,1290745638159,1290745690647,1290745691633,1290745692656,1290745697248,1290745699880,1290745757536,1290745764504,1290745767521,1290745772249,1290745773465,1290745825543,1290745826694,1290745835024,1290745836067,1290745888120,1290745889175,1290745890541,1290745891568,1290745897832,1290745950757,1290745951689,1290745952722,1290745954247,1290745955971,1290745957153,1290745960812,1290746013470,1290746014647,1290746016416,1290746020382,1290746023443,1290746024797,1290746076500,1290746077996,1290746080126,1290746084078,1290746086486,1290746088752,1290746140898,1290746142833,1290746146974,1290746150880,1290746206384,1290746207808,1290746209141,1290746212103,1290746216387,1290746272907,1290746274705,1290746281956,1290746285828,1290746339282,1290746340299,1290746341381,1290746345833,1290746348059,1290746349283,1290746352226,1290746406588,1290746414635,1290746416576,1290746417794,1290746474080,1290746481479,1290746484080,1290746541841,1290746546714,1290746548379,1290746551840,1290746553122,1290746609586,1290746610711,1290746619573,1290746622957,1290746626521,1290746687486,1290746691012,1290746744744,1290746749874,1290746751340,1290746754745,1290746812279,1290746818152,1290746822267,1290746824599,1290746825977,1290746827933,1290746880364,1290746884654,1290746890367,1290746892527,1290746898362,1290746952496,1290746956378,1290746959441,1290747013397,1290747023393,1290747077987,1290747079227,1290747080249,1290747082584,1290747088414,1290747089581,1290747141751,1290747142957,1290747150101,1290747151720,1290747208578,1290747215705,1290747218601,1290747220377,1290747273884,1290747275866,1290747283850,1290747285279,1290747288263,1290747340378,1290747349430,1290747405118,1290747409256,1290747412381,1290747415120,1290747418897,1290747471366,1290747480003,1290747481365,1290747484380,1290747487297,1290747541927,1290747548658,1290747605697,1290747615696,1290747671880,1290747672933,1290747674005,1290747675625,1290747678098,1290747679806,1290747681884,1290747683891,1290747739170,1290747748381,1290747754706,1290747806846,1290747808160,1290747811346,1290747816456,1290747820378,1290747874380,1290747878070,1290747884378,1290747886042,1290747887211,1290747889103,1290747942023,1290747946432,1290747949416,1290747952022,1290747958456,1290748014617,1290748015883,1290748019766,1290748021328,1290748077752,1290748083918,1290748087644,1290748092316,1290748145496,1290748149802,1290748155493,1290748158256,1290748211960,1290748214721,1290748217675,1290748219146,1290748221960,1290748224430,1290748225993,1290748278915,1290748282617,1290748285681,1290748287002,1290748288921,1290748292600,1290748346490,1290748355734,1290748414570,1290748418906,1290748420376,1290748424576,1290748482970,1290748492374,1290748551110,1290748552437,1290748556039,1290748561132,1290748562294,1290748563560,1290748565781,1290748566770,1290748619341,1290748628605,1290748633854,1290748686277,1290748688476,1290748696279,1290748700542,1290748753493,1290748759789,1290748761054,1290748763493,1290748820957,1290748822800,1290748823868,1290748828903,1290748830953,1290748888615,1290748891054,1290748892174,1290748898602,1290748955677,1290748956829,1290748957844,1290748964117,1290748965675,1290748966889,1290748972377,1290749029334,1290749033542,1290749088606,1290749090293,1290749092370,1290749094315,1290749098603,1290749101413,1290749102908,1290749159101,1290749164609,1290749167748,1290749221834,1290749223272,1290749230623,1290749231815,1290749236377,1290749238186,1290749297548,1290749300059,1290749303692,1290749357803,1290749367788,1290749369619,1290749425385,1290749426444,1290749427437,1290749435387,1290749439614,1290749492413,1290749494037,1290749495595,1290749500764,1290749501750,1290749503713,1290749505713,1290749508095,1290749565116,1290749566460,1290749569266,1290749621442,1290749630534,1290749684888,1290749691499,1290749692682,1290749694870,1290749750061,1290749760059,1290749764377,1290749816561,1290749821117,1290749823892,1290749826558,1290749882619,1290749885882,1290749886940,1290749890207,1290749892620,1290749896770,1290749949608,1290749956381,1290749959594,1290750017707,1290750018842,1290750019934,1290750021800,1290750023226,1290750027694,1290750028854,1290750085971,1290750092245,1290750095962,1290750097723,1290750153922,1290750155035,1290750156269,1290750158007,1290750159406,1290750160429,1290750161458,1290750163960,1290750165167,1290750217250,1290750218341,1290750220368,1290750226131,1290750227757,1290750228763,1290750281534,1290750283151,1290750284169,1290750285847,1290750291521,1290750292796,1290750294331,1290750295347,1290750297892,1290750351188,1290750357455,1290750359403,1290750361210,1290750362453,1290750363501,1290750365095,1290750366107,1290750367285,1290750420714,1290750422663,1290750423796,1290750430713,1290750436927,1290750437948,1290750491067,1290750492063,1290750495188,1290750496258,1290750499067,1290750501614,1290750558176,1290750559220,1290750560388,1290750562279,1290750563298,1290750564692,1290750566124,1290750568175,1290750569762,1290750571165,1290750572195,1290750573340,1290750574388,1290750575459,1290750627477,1290750628746,1290750630702,1290750633134,1290750635421,1290750636682],"raw_timestamp_deltas":[1174,1431,2932,54792,6883,1876,1243,52399,1126,7540,1290,53586,1778,1588,1534,3631,1465,53538,1047,1032,1034,1018,1327,3325,1214,55471,1043,8576,55984,4693,2041,2887,2812,54048,1012,1085,7722,1360,1366,54341,5668,2977,1351,2473,54466,9979,56555,1027,1082,7883,1174,54649,1610,2184,5830,5424,54372,1152,2912,3217,57149,1952,1173,3649,2997,57252,1031,1536,5630,1069,1056,1031,52272,1035,8126,1928,58770,2303,53581,3361,6628,1883,978,1430,52062,1187,3224,4648,1043,1319,1021,52418,1281,8709,55708,1207,4050,1744,2979,56280,9975,2547,53756,1840,6990,1165,56843,1010,1039,1075,3869,2167,58498,6158,3821,1831,56666,1913,1063,1440,1013,3063,1481,6640,52487,985,1021,4591,2632,57655,6964,3016,4727,1215,52076,1150,8328,1042,52052,1051,1365,1027,6264,52921,931,1031,1525,1722,1181,3658,52658,1170,1767,3965,3060,1353,51703,1490,2130,3951,2407,2265,52145,1931,4140,3905,55503,1422,1332,2961,4283,56519,1797,7250,3870,53454,1015,1082,4451,2225,1224,2942,54361,8043,1939,1217,56286,7397,2600,57760,4871,1664,3460,1281,56463,1120,8860,3382,3563,60964,3523,53731,5129,1465,3404,57533,5870,4114,2331,1377,1956,52429,4288,5712,2159,5834,54133,3881,3062,53956,9993,54593,1228,1022,2334,5828,1166,52170,1199,7143,1618,56858,7123,2895,1775,53506,1975,7983,1428,2983,52114,9050,55687,4137,3124,2738,3776,52469,8636,1361,3014,2917,54630,6728,57038,9997,56183,1050,1072,1618,2472,1707,2077,2007,55278,9208,6324,52139,1313,3185,5109,3921,54001,3689,6307,1662,1168,1891,52919,4408,2983,2606,6433,56161,1264,3882,1560,56423,6164,3725,4671,53180,4304,5690,2762,53701,2759,2953,1470,2813,2469,1562,52921,3701,3063,1320,1918,3679,53888,9243,58835,4334,1469,4199,58394,9402,58734,1302,3601,5092,1159,1265,2220,989,52569,9250,5248,52422,2196,7802,4262,52950,6294,1263,2438,57463,1841,1067,5034,2049,57661,2435,1119,6427,57074,1150,1014,6271,1557,1212,5487,56956,4206,55063,1685,2076,1944,4287,2809,1494,56192,5506,3138,54085,1433,7350,1191,4561,1808,59361,2510,3632,54110,9982,1830,55765,1057,992,7949,4226,52798,1622,1558,5168,985,1961,1999,2380,57020,1342,2806,52175,9089,54353,6608,1182,2188,55191,9997,4317,52183,4555,2774,2665,56059,3262,1057,3266,2412,4149,52837,6769,3213,58111,1129,1091,1864,1424,4467,1158,57116,6269,3715,1760,56197,1109,1234,1737,1399,1019,1029,2501,1206,52082,1087,2025,5762,1626,1004,52769,1614,1016,1677,5673,1274,1533,1014,2544,53295,6266,1947,1807,1240,1046,1593,1010,1177,53429,1946,1133,6915,6214,1019,53118,996,3123,1068,2808,2546,56561,1038,1167,1890,1018,1394,1432,2050,1586,1403,1029,1144,1046,1071,52017,1266,1955,2431,2286,1260]}
diff --git a/sample/programs/ruby/simple.rb b/sample/programs/ruby/simple.rb
index 74ce15e..3bed212 100644
--- a/sample/programs/ruby/simple.rb
+++ b/sample/programs/ruby/simple.rb
@@ -5,6 +5,7 @@ def a
   for i in 0..100 do
     b
     c
+    e
   end
 end
 
@@ -28,8 +29,13 @@ def d
   prod
 end
 
-profile = StackProf.run(mode: :wall, raw: true) do
+def e
+  sleep 0.05
+end
+
+mode = (ARGV[0] || :wall).to_sym
+profile = StackProf.run(mode: mode, raw: true) do
   a
 end
 
-puts JSON.generate(profile)
\ No newline at end of file
+puts JSON.generate(profile)
diff --git a/src/import/stackprof.ts b/src/import/stackprof.ts
index 0ace853..c6c23e5 100644
--- a/src/import/stackprof.ts
+++ b/src/import/stackprof.ts
@@ -1,7 +1,7 @@
 // https://github.com/tmm1/stackprof
 
 import {Profile, FrameInfo, StackListProfileBuilder} from '../lib/profile'
-import {TimeFormatter} from '../lib/value-formatters'
+import {RawValueFormatter, TimeFormatter} from '../lib/value-formatters'
 
 interface StackprofFrame {
   name?: string
@@ -15,14 +15,13 @@ export interface StackprofProfile {
   raw: number[]
   raw_timestamp_deltas: number[]
   samples: number
+  interval: number
 }
 
 export function importFromStackprof(stackprofProfile: StackprofProfile): Profile {
-  const {frames, mode, raw, raw_timestamp_deltas, samples} = stackprofProfile
-  const objectMode = mode == 'object'
-
-  const size = objectMode ? samples : stackprofProfile.raw_timestamp_deltas.reduce((a, b) => a + b, 0)
-  const profile = new StackListProfileBuilder(size)
+  const {frames, mode, raw, raw_timestamp_deltas, interval} = stackprofProfile
+  const profile = new StackListProfileBuilder()
+  profile.setValueFormatter(new TimeFormatter('microseconds')) // default to time format unless we're in object mode
 
   let sampleIndex = 0
 
@@ -50,23 +49,24 @@ export function importFromStackprof(stackprofProfile: StackprofProfile): Profile
     }
     const nSamples = raw[i++]
 
-    if (objectMode) {
-      profile.appendSampleWithWeight(stack, nSamples)
-    } else {
-      let sampleDuration = 0
-      for (let j = 0; j < nSamples; j++) {
-        sampleDuration += raw_timestamp_deltas[sampleIndex++]
-      }
-
-      profile.appendSampleWithWeight(stack, sampleDuration)
+    switch (mode) {
+      case 'object':
+        profile.appendSampleWithWeight(stack, nSamples)
+        profile.setValueFormatter(new RawValueFormatter())
+        break
+      case 'cpu':
+        profile.appendSampleWithWeight(stack, nSamples * interval)
+        break
+      default:
+        let sampleDuration = 0
+        for (let j = 0; j < nSamples; j++) {
+          sampleDuration += raw_timestamp_deltas[sampleIndex++]
+        }
+        profile.appendSampleWithWeight(stack, sampleDuration)
     }
 
     prevStack = stack
   }
 
-  if (!objectMode) {
-    profile.setValueFormatter(new TimeFormatter('microseconds'))
-  }
-
   return profile.build()
 }


Test patch:
diff --git a/src/import/__snapshots__/stackprof.test.ts.snap b/src/import/__snapshots__/stackprof.test.ts.snap
index 319f73a..be3158c 100644
--- a/src/import/__snapshots__/stackprof.test.ts.snap
+++ b/src/import/__snapshots__/stackprof.test.ts.snap
@@ -1,5 +1,453 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`importCpuProfileWithProperWeights importFromStackprof cpu mode snapshot 1`] = `
+Object {
+  "frames": Array [
+    Frame {
+      "col": undefined,
+      "file": "sample/programs/ruby/simple.rb",
+      "key": 5352342240,
+      "line": undefined,
+      "name": "<main>",
+      "selfWeight": 0,
+      "totalWeight": 410000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 4530376200,
+      "line": undefined,
+      "name": "<main>",
+      "selfWeight": 0,
+      "totalWeight": 410000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 4530486680,
+      "line": 37,
+      "name": "block in <main>",
+      "selfWeight": 0,
+      "totalWeight": 410000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 5335911080,
+      "line": 4,
+      "name": "Object#a",
+      "selfWeight": 0,
+      "totalWeight": 410000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 5335911040,
+      "line": 12,
+      "name": "Object#b",
+      "selfWeight": 0,
+      "totalWeight": 154000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 5335909920,
+      "line": 24,
+      "name": "Object#d",
+      "selfWeight": 331000,
+      "totalWeight": 331000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 5335910560,
+      "line": 18,
+      "name": "Object#c",
+      "selfWeight": 0,
+      "totalWeight": 177000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "/Users/mcorrea/src/github.com/dalehamel/speedscope/sample/programs/ruby/simple.rb",
+      "key": 5335909880,
+      "line": 32,
+      "name": "Object#e",
+      "selfWeight": 79000,
+      "totalWeight": 79000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "",
+      "key": 1,
+      "line": undefined,
+      "name": "(garbage collection)",
+      "selfWeight": 0,
+      "totalWeight": 79000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "",
+      "key": 5,
+      "line": undefined,
+      "name": "(sweeping)",
+      "selfWeight": 71000,
+      "totalWeight": 71000,
+    },
+    Frame {
+      "col": undefined,
+      "file": "",
+      "key": 3,
+      "line": undefined,
+      "name": "(marking)",
+      "selfWeight": 8000,
+      "totalWeight": 8000,
+    },
+  ],
+  "name": "simple-cpu-stackprof.json",
+  "stacks": Array [
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 5.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 5.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 5.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 4.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(marking) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 5.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 1.00ms",
+    "(garbage collection);(sweeping) 2.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#e 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 4.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#b;Object#b;Object#d;Object#d 2.00ms",
+    "(garbage collection);(sweeping) 1.00ms",
+    "<main>;<main>;block in <main>;Object#a;Object#a;Object#c;Object#c;Object#d;Object#d 3.00ms",
+  ],
+}
+`;
+
+exports[`importCpuProfileWithProperWeights importFromStackprof cpu mode snapshot: indexToView 1`] = `0`;
+
+exports[`importCpuProfileWithProperWeights importFromStackprof cpu mode snapshot: profileGroup.name 1`] = `"simple-cpu-stackprof.json"`;
+
 exports[`importFromStackprof 1`] = `
 Object {
   "frames": Array [
diff --git a/src/import/stackprof.test.ts b/src/import/stackprof.test.ts
index 32624ba..46b9f36 100644
--- a/src/import/stackprof.test.ts
+++ b/src/import/stackprof.test.ts
@@ -1,3 +1,5 @@
+import { readFileSync } from 'fs';
+import { importProfileGroupFromText } from '.'
 import {checkProfileSnapshot} from '../lib/test-utils'
 
 test('importFromStackprof', async () => {
@@ -11,3 +13,26 @@ test('importFromStackprof object mode', async () => {
 test('importFromStackprof when a profile has a frame with no name', async () => {
   await checkProfileSnapshot('./sample/profiles/stackprof/stackprof-last-frame-no-name.json')
 })
+
+describe('importCpuProfileWithProperWeights', () => {
+  test('importFromStackprof cpu mode snapshot', async () => {
+    await checkProfileSnapshot('./sample/profiles/stackprof/simple-cpu-stackprof.json')
+  })
+
+  test('uses samples count for weight when importing cpu profile', async () => {
+
+    const profileFile = readFileSync('./sample/profiles/stackprof/simple-cpu-stackprof.json')
+    const profileGroup = await importProfileGroupFromText('simple-cpu-stackprof.json', profileFile.toString())
+    expect(profileGroup).not.toBeNull()
+
+    if (profileGroup) {
+      const profile = profileGroup.profiles[profileGroup.indexToView]
+      expect(profile).not.toBeNull()
+
+      if (profile) {
+        expect(profile.getWeightUnit()).toBe('microseconds')
+        expect(profile.getTotalWeight()).toBe(489000)
+      }
+    }
+  })
+})