tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.29k stars 99 forks source link

Dont panic for 0 frequence #182

Open arilou opened 1 year ago

arilou commented 1 year ago

Make 0 frequency a valid option.

YangKeao commented 1 year ago

Thanks for your contribution :beers:.

If the interval is 0, the timer is stopped. I don't think it's intuitive for users. Could we return the error to the user?

Actually, panic is not that bad :thinking:. Could you give more explanation on why you want to avoid the panic?

arilou commented 1 year ago

Hi @YangKeao, yes I can give you the scenario where this found me, I have integrated pprof-rs to an application I'm writing, so first of all thank it's a great crate and it helped find some nice places that required additional optimizations.

As for the scenario, the application I'm writing has a server listening thread which accepts commands, for example one of the command is to start the profiling.

I have added another command which collects the backtraces of all the threads in the application using your crate, basically what I do is set the frequency to 0, and then tkill I can send a SIGPROF to each thread, once I'm done sending the SIGPROF to each thread I collect the backtraces from the Profiler.

I thought about contributing that piece of code as well but it's very platform specific (only Linux) and it's not really a profiling scenario.

Thanks, -- Jon.