【问题标题】:Perf stat equivalent for Mac OS?Mac OS 的性能统计等效项?
【发布时间】:2020-07-19 00:01:04
【问题描述】:

Mac OS 上是否有等效的性能统计信息?我想对 CLI 命令做同样的事情,而谷歌搜索并没有产生任何结果。

【问题讨论】:

    标签: macos profiling performancecounter perf intel-pmu


    【解决方案1】:

    我对缺少与 perf stat -r 等效的 CLI 感到失望,所以我只写了 https://github.com/cdr/timer

    作品如下:

    $ timer -n 4 -q sleep 1s
    --- config
    command        sleep 1s
    iterations     4
    parallelism    1
    --- percentiles
    0        (fastest)         1.004
    25       (1st quantile)    1.004
    50       (median)          1.006
    75       (3rd quantile)    1.008
    100th    (slowest)         1.008
    --- summary
    mean      1.006
    stddev    0.002
    

    这不包含高级执行计数器,仅包含挂钟统计信息。

    【讨论】:

    • 这只是测量挂钟时间吗?没有性能计数器,甚至没有用户与系统时间?这仅解决了perfperf stat -r 重复计数)的次要功能之一,而不是主要问题(硬件性能事件)
    • 你是对的@PeterCordes。我的特定用例不需要高级计数器。我编辑了帖子以澄清。
    【解决方案2】:

    Mac OS X 中有 Instruments 工具来分析应用程序,包括硬件 PMU。默认是对 CPU 使用率进行采样分析器。一些文档:https://en.wikipedia.org/wiki/Instruments_(software)https://help.apple.com/instruments/mac/current/ 它也有命令行变体:https://help.apple.com/instruments/mac/current/#/devb14ffaa5

    在 /Applications/Utilities 中打开终端。

    instruments -t "Allocations" -D ~/Desktop/YourTraceFileName.trace PathToYourApp
    

    页面https://gist.github.com/loderunner/36724cc9ee8db66db305 提到了工具sample(“包含在标准Mac OS X 安装中”)。

    此外,针对旧版本的 Mac OS X(10.7 之前)和 Xcode 提到了 Shark 工具:https://en.wikipedia.org/wiki/Apple_Developer_Tools#Shark

    使用 Intel CPU,您可以尝试 Intel Vtune 分析器 - https://software.intel.com/en-us/get-started-with-vtune-macos https://software.intel.com/en-us/vtune

    其他更开放的英特尔工具(部分弃用?)是https://github.com/opcm/pcm/,它具有某种 OSX 支持。文档:https://software.intel.com/en-us/articles/intel-performance-counter-monitor。需要自定义 MacMSRDriver 驱动程序 (kext)。

    perf stat 确实计算事件,我不确定如何使用 Instruments 收集计数器。页面https://www.robertpieta.com/counters-in-instruments/ 展示了如何配置 Instruments GUI 以进行事件计数:

    要配置计数器,请从 Instruments 导航菜单中选择 File -> Recording Options。 就本文而言,将选择按时间抽样。使用 + 您可以添加特定事件,计数器可以在当前连接到 Instruments 的特定 CPU 上计数可用。

    因此,您至少可以指示 Instruments 工具随着时间的推移定期记录计数器值。该模式报告了一些问题:http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html

    【讨论】:

      猜你喜欢
      • 2010-11-29
      • 2010-09-05
      • 2011-03-28
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多