basic-profiler-1.js (3369B)
1 // |jit-test| skip-if: !WasmHelpers.isSingleStepProfilingEnabled 2 3 // Test profiling of JS PI -- typical use case. 4 5 const { 6 assertEqImpreciseStacks, 7 } = WasmHelpers; 8 9 var compute_delta = async (i) => Promise.resolve(i / 100 || 1); 10 11 var suspending_compute_delta = new WebAssembly.Suspending( 12 compute_delta 13 ); 14 var ins = wasmEvalText(`(module 15 (import "js" "compute_delta" 16 (func $compute_delta (param i32) (result f64))) 17 18 (global $state (mut f64) (f64.const 0)) 19 20 (func (export "update_state_export") (param i32) (result f64) 21 (global.set $state (f64.add 22 (global.get $state) (call $compute_delta (local.get 0)))) 23 (global.get $state) 24 ) 25 )`, { 26 js: { 27 compute_delta: suspending_compute_delta, 28 }, 29 }); 30 31 var update_state = WebAssembly.promising( 32 ins.exports.update_state_export 33 ); 34 35 enableGeckoProfiling(); 36 37 enableSingleStepProfiling(); 38 39 function wb(s) { 40 var p = s.split(","); 41 p[0] = "<"; 42 var t = p.join(","); 43 return [t, s, t]; 44 } 45 46 var res = update_state(4); 47 var tasks = res.then((r) => { 48 assertEq(r, .04); 49 const stacks = disableSingleStepProfiling(); 50 assertEqImpreciseStacks(stacks, 51 [ 52 "", 53 ">", 54 "1,>", // enter $promising.exported 55 ...wb("CreateSuspender,1,>"), 56 "1,>", 57 ...wb("CreatePromisingPromise,1,>"), 58 "1,>", 59 ...wb("#ref.func function,1,>"), // ref to $promising.trampoline 60 "1,>", 61 ...wb("#update suspender state util,1,>"), 62 "1,>", 63 "2,1,>", // enter $promising.trampoline 64 "1,2,1,>", // enter "update_state_export" 65 "1,1,2,1,>", // enter $suspending.exported 66 ...wb("CurrentSuspender,1,1,2,1,>"), 67 "1,1,2,1,>", 68 ...wb("#ref.func function,1,1,2,1,>"), // ref to $suspending.trampoline 69 "1,1,2,1,>", 70 ...wb("#update suspender state util,1,1,2,1,>"), 71 "1,1,2,1,>", 72 "1,>", // stack switched 73 "2,1,>", // enter $suspending.trampoline 74 "<,2,1,>", // $suspending.wrappedfn 75 "2,1,>", 76 ...wb("#ref.func function,2,1,>"), // ref to $suspending.continue-on-suspendable 77 "2,1,>", 78 ...wb("AddPromiseReactions,2,1,>"), 79 "2,1,>", 80 "1,>", 81 ...wb("#update suspender state util,1,>"), 82 "1,>", // exiting $promising.exported 83 ">", 84 "", 85 ">", 86 "3,>", // enter $suspending.continue-on-suspendable 87 "3,1,2,3,>", // back to "update_state_export" 88 "1,1,2,3,>", // back to $suspending.exported 89 ...wb("#update suspender state util,1,1,2,3,>"), 90 "1,1,2,3,>", 91 ...wb("GetSuspendingPromiseResult,1,1,2,3,>"), 92 "1,1,2,3,>", 93 "1,2,3,>", // exiting from "update_state_export" 94 "2,3,>", // at $promising.trampoline 95 ...wb("SetPromisingPromiseResults,2,3,>"), 96 "2,3,>", 97 "3,>", 98 ...wb("#update suspender state util,3,>"), 99 "3,>", // exiting $suspending.continue-on-suspendable 100 ">", 101 "" 102 ] 103 ); 104 105 disableGeckoProfiling(); 106 });