bytecodealliance / bytecodealliance/wasmtime

Measure thread-local CPU usage in guest profiler

Open
#7,667 0 comments 0 reactions 0 assignees View on GitHub
enhancement wasmtime
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

#### Feature

We record the wall-clock time when each call-stack sample was taken in the guest profiler, but the Firefox profiler format also allows us to record how much CPU time was used since the last sample.

#### Benefit

This should change the profile viewer’s output format to offer total time in various places, not just number of samples. That's generally easier for people to understand.

#### Implementation

On POSIX platforms, the clock to use is `rustix::time::clock_gettime(ClockId::ThreadCPUTime)`. I don't know how to do this on Windows.

In `GuestProfiler::sample`, the call to `self.profile.add_sample` currently passes `CpuDelta::ZERO` and should instead pass the difference between two queries of the above clock.

I'm not sure if this would work correctly for an embedder who time-slices between different guests on the same OS thread. I don't know if we can detect when the current guest is swapped out or back in without some kind of magic attached to the current wasmtime-fibers code for swapping thread-local storage.

#### Alternatives

The profiler is usable without this CPU time metric.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.