Granulate / gprofiler

gProfiler is a system-wide profiler, combining multiple sampling profilers to produce unified visualization of what your CPU is spending time on.
https://profiler.granulate.io
Apache License 2.0
743 stars 54 forks source link

perf: Run perf with timeout as a protection mechanism #785

Closed Jongy closed 1 year ago

Jongy commented 1 year ago

We run perf in continuous mode, where it samples non-stop and aggregates samples in a single file. Every interval, gprofiler signals perf, to "switch output" to a new file, while gprofiler is consuming the old one.

This becomes a problem if gProfiler gets stuck, for example. We don't want perf to run wild. For this reason we need a timeout placed on perf, such that it disables itself / cleans its output files to refrain from writing more and more data. We have similar protections for other components (for example, for async-profiler it was added here: https://github.com/Granulate/gprofiler/pull/265).

The solution I chose is to force perf to write output files every set interval, even if it is not signaled by gprofiler. perf will write the files and rotate a single copy. I chose this solution because it was the simplest one to apply on perf's code; ideally we'd like perf to "pause" until it gets signaled again, but I couldn't think of a simple implementation for that. It is not possible to simply "pause". See the perf change here: https://github.com/Granulate/linux/commit/aa689e9b55c7b5ba8d399bc2560d36ef98436150

Closes: https://github.com/Granulate/gprofiler/issues/782

Testing done