Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CPU and memory usage on per-component execution spans #2933

Open
calebschoepp opened this issue Nov 22, 2024 · 5 comments
Open

Expose CPU and memory usage on per-component execution spans #2933

calebschoepp opened this issue Nov 22, 2024 · 5 comments

Comments

@calebschoepp
Copy link
Collaborator

It would be nice if we could see the amount of memory and CPU that was used when a component is executed.

I believe exposing CPU time requires a CallHook which means we'll probably want to put it behind a feature flag or benchmark it to make sure it doesn't regress performance.

@calebschoepp
Copy link
Collaborator Author

@jovermier
Copy link

Instead of CPU time what would be even better is CPU cycles. Cycles is more accurate as a CPU can have efficiency cores and performance cores. They can be in a boost mode or a low power mode. Cycles is actual usage where time has too many variables.

@lann
Copy link
Collaborator

lann commented Nov 25, 2024

We might consider making the calculation of this metric pluggable. There isn't really any one great metric to represent "CPU usage" across different applications and platforms; lots of performance counters are manufacturer-specific and require careful interpretation to be useful for decision making anyway. Further, there will be some (small, probably, but dependent on the exact metric) performance overhead to cpu measurements and we would generally need to track them on every context switch to/from a guest application to account for host overhead and async task switching.

@calebschoepp
Copy link
Collaborator Author

Making it pluggable would be cool. At what level do you imagine it being pluggable? Compile Spin with special feature flags? Pass a flag to spin when running it to turn it on? Something else?

@lann
Copy link
Collaborator

lann commented Nov 25, 2024

I was thinking of something similar to Config::call_hook (which would itself probably be used by this feature). Maybe something very roughly like:

trait CpuUsageHook {
    // Called every time the guest is entered; implementations might record
    // some baseline counter value here.
    fn enter_guest(&mut self);

    // Called every time the guest exits. Implementations are expected to
    // record the "usage" measured since the last call to `enter_guest`.
    fn exit_guest(&mut self) -> u64;
}

spin_core_config.set_cpu_usage_hook(MyIntelCpuPerformanceCounterUsageHook);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants