Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can "perf record" or "perf-record" sample child processes?

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:

  1. change the harness binary to spawn a "perf record" child process which run the benchmarks and do the sampling

  2. just do "perf record $harness-binary" hoping it will sample the child process too.

  3. "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

like image 333
abemaw Avatar asked Jul 02 '17 01:07

abemaw


1 Answers

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.

like image 91
osgx Avatar answered Sep 28 '22 16:09

osgx