ProfilingFor a given wasm binary. The resulting Profiling needs to be prepared after Wazero module compilation.
(wasm []byte)
| 41 | // ProfilingFor a given wasm binary. The resulting Profiling needs to be |
| 42 | // prepared after Wazero module compilation. |
| 43 | func ProfilingFor(wasm []byte) *Profiling { |
| 44 | r := &Profiling{ |
| 45 | wasm: wasm, |
| 46 | symbols: noopsymbolizer{}, |
| 47 | stackIterator: func(mod api.Module, def api.FunctionDefinition, wasmsi experimental.StackIterator) experimental.StackIterator { |
| 48 | return wasmsi |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | if binCompiledByGo(wasm) { |
| 53 | r.lang = golang |
| 54 | // Those functions are special. They use a different calling |
| 55 | // convention. Their call sites do not update the stack pointer, |
| 56 | // which makes it impossible to correctly walk the stack. |
| 57 | // |
| 58 | // https://github.com/golang/go/blob/7ad92e95b56019083824492fbec5bb07926d8ebd/src/cmd/internal/obj/wasm/wasmobj.go#LL907C18-L930C2 |
| 59 | r.filteredFunctions = map[string]struct{}{ |
| 60 | "_rt0_wasm_js": {}, |
| 61 | "_rt0_wasm_wasip1": {}, |
| 62 | "wasm_export_run": {}, |
| 63 | "wasm_export_resume": {}, |
| 64 | "wasm_export_getsp": {}, |
| 65 | "wasm_pc_f_loop": {}, |
| 66 | "gcWriteBarrier": {}, |
| 67 | "runtime.gcWriteBarrier1": {}, |
| 68 | "runtime.gcWriteBarrier2": {}, |
| 69 | "runtime.gcWriteBarrier3": {}, |
| 70 | "runtime.gcWriteBarrier4": {}, |
| 71 | "runtime.gcWriteBarrier5": {}, |
| 72 | "runtime.gcWriteBarrier6": {}, |
| 73 | "runtime.gcWriteBarrier7": {}, |
| 74 | "runtime.gcWriteBarrier8": {}, |
| 75 | "runtime.wasmDiv": {}, |
| 76 | "runtime.wasmTruncS": {}, |
| 77 | "runtime.wasmTruncU": {}, |
| 78 | "cmpbody": {}, |
| 79 | "memeqbody": {}, |
| 80 | "memcmp": {}, |
| 81 | "memchr": {}, |
| 82 | } |
| 83 | } else if supportedPython(wasm) { |
| 84 | r.lang = python311 |
| 85 | r.onlyFunctions = map[string]struct{}{ |
| 86 | "PyObject_Vectorcall": {}, |
| 87 | // Those functions are also likely candidate for useful profiling. |
| 88 | // We may need to look into them if someone reports missing frames. |
| 89 | // |
| 90 | // "_PyEval_EvalFrameDefault": {}, |
| 91 | // "_PyEvalFramePushAndInit": {}, |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return r |
| 96 | } |
| 97 | |
| 98 | // CPUProfiler constructs a new instance of CPUProfiler using the given time |
| 99 | // function to record the CPU time consumed. |