本文介绍了可以“记录"或“性能记录"样本子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个线束二进制文件,可以根据命令行选项生成不同的基准.我对抽样这些基准非常感兴趣.

我有3种选择:

  1. 更改工具二进制文件以生成性能记录"子进程,该子进程运行基准并进行采样

  2. 只需执行"perf record $ harness-binary",希望它也会对子进程进行采样.

  3. 性能记录-a $ harness-binary",它将执行从所有CPU进行系统范围的收集".这需要root访问,因此在我的情况下不可行.

如果性能记录确实对子进程进行采样,则方法2是干净的.有人可以帮助确认是否是这种情况吗?高度赞赏指向文档或性能代码的指针.

如果方法2是可行的,并且基准测试比测试工具要消耗更多的CPU资源,我认为基准采样的质量应该相当不错,对吧?

谢谢

解决方案

perf记录(不带 -a 选项)记录所有从目标进程分叉(和克隆的线程)的进程开始记录后.使用 perf record ./program ,它也会配置所有子进程,而使用 perf record -p $ PID ,并附加到已经运行的$ PID上,它将配置目标进程和所有附加后启动子进程.默认情况下,分析继承处于启用状态(所需代码如下: attr-> inherit =!opts-> no_inherit; & no_inherit ),可以使用 -i 选项禁用,也可以通过> -t -每线程.

此继承类似于 perf stat 中的内容: https://perf.wiki.kernel.org/index.php/Tutorial

还有 -i 选项也用于 perf记录: http://man7.org/linux/man-pages/man1/perf-record.1.html

性能报告可以从收集的组合perf.data文件中的某些PID中过滤事件.

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

解决方案

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

And -i option is there for perf record too: http://man7.org/linux/man-pages/man1/perf-record.1.html

perf report can filter events from some PID from collected combined perf.data file.

这篇关于可以“记录"或“性能记录"样本子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 06:40