namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
3.03k stars 444 forks source link

failed to set --notrace filter #1975

Open Anton-4 opened 12 hours ago

Anton-4 commented 12 hours ago

Hi,

Thanks for this amazing project, this could really improve my debugging workflow :heart:

I would like to --notrace all functions that do not start with roc_, I've tried several variations of my filter but could not get any of them to work.

This is my output:

❯ uftrace replay -f none --notrace '^(?!roc).*'
Usage: failed to set filter or trigger: !^(?!roc).*
roc::main() {
  roc_tracing::setup_tracing() {
    std::env::var() {
      _<&T as core..convert..AsRef<U>>::as_ref() {
        std::ffi::os_str::_<impl core..convert..AsRef<std..ffi..os_str..OsStr> for str>::as_ref();
      } /* _<&T as core..convert..AsRef<U>>::as_ref */
    } /* std::env::var */

How can I specify my desired filter?

namhyung commented 2 hours ago

Hi, thanks for using uftrace and for your encouraging comment!

The -N/--notrace option disables tracing for the given function and its children. So you won't see anything if you apply it to the top-level function.

Instead, if you just want to hide some function but to see its children, you can use hide trigger. Also uftrace use POSIX extended regular expression (regcomp(..., REG_EXTENDED)). So PCRE syntax like (?!roc) won't work but you can use [^...] to match character other than the pattern.

# hide functions don't start with 'r' or 'ro' or 'roc'
$ uftrace replay -T '^[^r]|^r[^o]|^ro[^c]@hide'

On the other hand, I thought it can be also achieved if it starts with tracing disabled and apply a trigger to display desired functions only. The intended trigger action is trace but it doesn't seem to work on replay. (This could be a good contribution item.)

# this doesn't work for replay yet
$ uftrace replay --trace=off -T '^roc@trace'

Unfortunately the trace action is only works with time filter for now. You can try it with a insanely high threshold (like 100m) but it'd show the parent function as well (it'd probably be ok though).

# this would work (and show parent functions too)
$ uftrace replay -t 100m -T '^roc@trace'