koute / not-perf

A sampling CPU profiler for Linux
Apache License 2.0
871 stars 41 forks source link

RAII API for profiling sections of code #10

Open matklad opened 5 years ago

matklad commented 5 years ago

Hi!

I am looking for a profiling tool for rust-analyzer, and I wonder if not-perf could be of help. I have some very specific requirements, but I am not a profiling expert, so I don't know if what I ask is at all possible, hence this feature-request/support issue :) Feel free to just close with "out of scope" if I ask for something silly!

rust-analyzer relies heavily on incremental computation, and I'd love to profile the incremental case. The interesting benchmark looks like this:

load_data_from_disk(); // 200ms of IO
compute_completion(); // triggers initial analysis, 10 seconds
{
    change_single_file();
    compute_completion(); // re computation after a change, 300 ms
}

I am only interested in profiling the block. Although the running-time of the benchmark is dominated by initial analysis, I explicitly don't care much about its performance.

So, what I like is to do

Is this possible at least in theory (ie, are there sampling tools than can give such data)? Could not-perf be of help here? My dream API would look like this:

load_data_from_disk();
compute_completion();
{
    let _p = not_perf::record("~/tmp/profile_data.perf")
        .append(); // append to the data file, so that I can run this in a loop
    change_single_file();
    compute_completion();
    // stops profiling on Drop
}
matklad commented 5 years ago

Oh, I must say that currently I try to use https://github.com/AtheMathmo/cpuprofiler and it kinda can do this, but has heavy C deps and lacks convenient APi