【问题标题】:Linux perf tools - How to simultaniously profiling multiple processes? How to extract Percentage of CPU cycles?Linux perf 工具 - 如何同时分析多个进程?如何提取 CPU 周期百分比?
【发布时间】:2017-10-21 04:51:14
【问题描述】:

我正在尝试分析我的 CPU 上的一组进程。为了非常精确,我想使用perf stat 命令查看我的进程使用了​​多少 CPU 周期。 这与顶部不同,在顶部,我只看到快照中使用的 CPU 百分比。

很遗憾,我没有找到同时分析多个进程的方法。这可能吗?

第二个问题:是否不仅可以查看使用的 CPU 周期,还可以查看同一时间间隔内使用的 CPU 周期总量(或百分比)?

【问题讨论】:

    标签: linux command-line profiling perf


    【解决方案1】:

    您可以尝试为您想要的每个 pid 运行 perf stat -p PID1,PID2,PID3(使用 pidof、pgrep 等获取它们)http://man7.org/linux/man-pages/man1/perf-stat.1.html

     -p, --pid=<pid>
        stat events on existing process id (comma separated list)
    

    还有有用的-I msecs 选项可以启用定期打印,--per-thread 可以分隔线程。

    还可以尝试使用-A 或一些--per-* 选项在系统范围内使用perf stat -ahttp://man7.org/linux/man-pages/man1/perf-stat.1.html

       -a, --all-cpus
           system-wide collection from all CPUs (default if no target is
           specified)
       -A, --no-aggr
           Do not aggregate counts across all monitored CPUs.
    
       --per-socket
           Aggregate counts per processor socket for system-wide mode
           measurements. This is a useful mode to detect imbalance between
           sockets. To enable this mode, use --per-socket in addition to -a.
           (system-wide). The output includes the socket number and the
           number of online processors on that socket. This is useful to
           gauge the amount of aggregation.
    
       --per-core
           Aggregate counts per physical processor for system-wide mode
           measurements. This is a useful mode to detect imbalance between
           physical cores. To enable this mode, use --per-core in addition
           to -a. (system-wide). The output includes the core number and the
           number of online logical processors on that physical processor.
    
       --per-thread
           Aggregate counts per monitored threads, when monitoring threads
           (-t option) or processes (-p option).
    

    【讨论】:

    • 我也在寻找类似的东西,因为我的案例中的线程被固定在核心上,我可以一起使用 --per-core-A 来获得每个核心的分解。
    • 我想--per-thread 需要tid,这在运行可执行文件之前是未知的
    猜你喜欢
    • 1970-01-01
    • 2011-12-07
    • 2023-02-04
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    相关资源
    最近更新 更多