Reputation: 151
Assume I have a harness binary which could spawn different benchmarks according to command line option. I am really interested in sampling these benchmarks.
I have 3 options:
change the harness binary to spawn a perf record
child process which run the benchmarks and do the sampling
just do perf record $harness-binary
hoping it will sample the child process too.
perf record -a $harness-binary
which would do a "System-wide collection from all CPUs.". This requires root access, therefore not feasible in my case.
Approach #2 is clean if perf-record really samples the child process. Can somebody help to confirm if this is the case? Pointers to documents or perf code would be highly appreciated.
If approach #2 is feasible and the benchmarks is much more CPU-intensive than the harness, I think the quality of the benchmark sampling should be reasonably good, right?
Thanks
Upvotes: 12
Views: 8394
Reputation: 94235
perf record
without -a
option record all processes, forked (and threads cloned) from target process after starting of record. With perf record ./program
it will profile all child processes too, and with perf record -p $PID
with attaching to already running $PID it will profile target process and all child processes started after attaching. Profiling inheritance is enabled by default (code as required: attr->inherit = !opts->no_inherit;
& no_inherit) and can be disabled with -i
option and also disabled by -t
and --per-thread
.
This inheritance is like in perf stat
: https://perf.wiki.kernel.org/index.php/Tutorial
Counting and inheritance
By default, perf stat counts for all threads of the process and subsequent child processes and threads. This can be altered using the -i option. It is not possible to obtain a count breakdown per-thread or per-process.
And -i
option is there for perf record
too: http://man7.org/linux/man-pages/man1/perf-record.1.html
-i, --no-inherit Child tasks do not inherit counters.
perf report
can filter events from some PID from collected combined perf.data file.
Upvotes: 17