Fix import of multithreaded Chrome profiles (#194)
In #160, I wrote code which incorrectly assumed that at most one profile would be active at a time. It turns out this assumption is incorrect because of webworkers! This PR introduces a fix which correctly separates samples taken on the main thread from samples taken on worker threads, and allows viewing both in speedscope. Fixes #171
This commit is contained in:
28
sample/programs/javascript/worker.html
Normal file
28
sample/programs/javascript/worker.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
function banana() {
|
||||
let prod = 1
|
||||
for (let i = 1; i < 1000; i++) {
|
||||
prod *= i
|
||||
}
|
||||
return prod
|
||||
}
|
||||
|
||||
function apple() {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
banana()
|
||||
}
|
||||
}
|
||||
|
||||
let bounces = 0
|
||||
|
||||
const worker = new Worker('./worker.js')
|
||||
|
||||
worker.onmessage = function() {
|
||||
apple()
|
||||
if (bounces++ < 10) {
|
||||
worker.postMessage('ping')
|
||||
}
|
||||
}
|
||||
|
||||
worker.postMessage('ping')
|
||||
</script>
|
||||
18
sample/programs/javascript/worker.js
Normal file
18
sample/programs/javascript/worker.js
Normal file
@@ -0,0 +1,18 @@
|
||||
function gamma() {
|
||||
let prod = 1
|
||||
for (let i = 1; i < 1000; i++) {
|
||||
prod *= i
|
||||
}
|
||||
return prod
|
||||
}
|
||||
|
||||
function alpha() {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
gamma()
|
||||
}
|
||||
}
|
||||
|
||||
onmessage = function(e) {
|
||||
alpha()
|
||||
postMessage('pong')
|
||||
}
|
||||
Reference in New Issue
Block a user