wasmi-labs / wasmi

WebAssembly (Wasm) interpreter.

Home Page:https://wasmi-labs.github.io/wasmi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Wasmi execution profiling

Robbepop opened this issue · comments

Currently there is no out-of-the-box way to profile Wasm executions via Wasmi.

One way this could look like is to collect information during Wasm executions such as total number of Wasmi instructions executed, total number of branches taken, total time spent in host functions, total instruction dispatch time, and for each instruction number of its execution and total execution time.

We could collect all this information in a singular struct during execution.
In order to not compromise performance we must put this functionality behind a crate feature profiling. This functionality must not degrade performance when not enabled. Ideally it would not even significantly degrade performance when enabled but this is probably a pipedream.

The Wasmi CLI should expose this functionality to its users.
This data enables Wasmi users and developers alike to better understand performance issues in their Wasm blobs or the Wasmi engine itself and to optimize for specific use cases.

Since the Wasmi bytecode enum is extremely large it might be a good idea to write a proc. macro to generate the associated profiling struct type from it to simplify keeping everything in sync.

After a Wasmi execution the profiler then outputs its collected data to the user. This could be formatted as JSON or something similar.

{
    "dispatch": {
        "time": "1.52s",
    },
    "host": {
        "time": "0.71s",
    },
    "instructions": {
        "i32.add": {
            "count": 3948,
            "time": "0.5us",
        },
        "branch": {
            "count": 995,
            "time": "0.1us",
        },
        etc ...
    }
}
commented

Might be related: wasmerio/wasmer#4381