【问题标题】:OCaml time profiling on OS XOS X 上的 OCaml 时间分析
【发布时间】:2014-08-03 15:39:40
【问题描述】:

在没有正常工作的 gprof 的情况下,我可以使用其他什么工具在 OS X 上进行分析?

(我知道穷人的方法,但更喜欢不需要手动代码检测的东西)

到目前为止,我一直没有安装完整的 Xcode,并尝试使用 Activity Monitor,但我不确定自己做对了吗?

详情: 我已经设法使用 ocamlbuild 和“.p.native”构建目标编译我的项目以进行时间分析。然后,我在 Mac OS X 10.9 上使用 Activity Monitor 对正在运行的进程进行采样。这提供了大量关于 OCaml 内部的输出,例如垃圾收集,但我没有从我的模块中看到正确注释的函数名称。

输出片段:

Call graph:
    2109 Thread_55861   DispatchQueue_1: com.apple.main-thread  (serial)
      542 .L1099  (in atest.p.native) + 18  [0x101a89956]
      + 210 caml_weak_get  (in atest.p.native) + 278  [0x101ac79e6]
      + ! 87 caml_alloc_small  (in atest.p.native) + 22  [0x101ab75e6]
      + ! : 70 mcount  (in libsystem_c.dylib) + 32,37,...  [0x7fff87545620,0x7fff87545625,...]
      + ! : 10 mcount  (in libsystem_c.dylib) + 59  [0x7fff8754563b]
      + ! : | 10 moncount  (in libsystem_c.dylib) + 0,1,...  [0x7fff8754d3a5,0x7fff8754d3a6,...]
      + ! : 7 DYLD-STUB$$moncount  (in libsystem_c.dylib) + 0  [0x7fff875c549e]
      + ! 68 caml_alloc_small  (in atest.p.native) + 1,128,...  [0x101ab75d1,0x101ab7650,...]
      + ! 46 caml_alloc_small  (in atest.p.native) + 87  [0x101ab7627]
      + ! : 40 caml_minor_collection  (in atest.p.native) + 90  [0x101ab624a]

我在上面看到很多类似于 .L1099 的符号,但几乎没有一个具有 Module-name_function-name_unique-number 类型的专有名称,这是我阅读 OCaml 手册时所期望的。令人困惑的是,确实出现了一些人类可读的符号——但还不够有用。

另一个片段,其中最后一行是我自己模块中的函数

Sort by top of stack, same collapsed (when >= 5):
        mcount  (in libsystem_c.dylib)        617
        caml_weak_get  (in atest.p.native)        256
        caml_alloc_small  (in atest.p.native)        97
        caml_modify  (in atest.p.native)        94
        moncount  (in libsystem_c.dylib)        93
        caml_c_call  (in atest.p.native)        67
        mark_slice  (in atest.p.native)        42
        caml_weak_set  (in atest.p.native)        36
        caml_page_table_lookup  (in atest.p.native)        34
        camlRandom__bits_1038  (in atest.p.native)        30
        sweep_slice  (in atest.p.native)        24
        DYLD-STUB$$mcount  (in atest.p.native)        23
        DYLD-STUB$$moncount  (in libsystem_c.dylib)        18
        compare_val  (in atest.p.native)        16
        .L327  (in atest.p.native)        15
        .L621  (in atest.p.native)        15
        .L1202  (in atest.p.native)        14
        .L1205  (in atest.p.native)        14
        .L1173  (in atest.p.native)        12
        .L1113  (in atest.p.native)        11
        .L1281  (in atest.p.native)        11
        .L1310  (in atest.p.native)        11
        caml_fl_allocate  (in atest.p.native)        11
        caml_oldify_one  (in atest.p.native)        11
        caml_weak_blit  (in atest.p.native)        11
        .L1099  (in atest.p.native)        10
        .L1150  (in atest.p.native)        10
        .L135  (in atest.p.native)        10
        .L149  (in atest.p.native)        10
        .L295  (in atest.p.native)        10
        caml_alloc_shr  (in atest.p.native)        10
        .L148  (in atest.p.native)        9
        .L268  (in atest.p.native)        9
        invert_pointer_at  (in atest.p.native)        9
        .L1135  (in atest.p.native)        8
        .L1154  (in atest.p.native)        8
        .L1278  (in atest.p.native)        8
        allocate_block  (in atest.p.native)        8
        .L1114  (in atest.p.native)        7
        .L1118  (in atest.p.native)        7
        .L1172  (in atest.p.native)        7
        .L131  (in atest.p.native)        7
        camlReact__occurs_1470  (in atest.p.native)        7
        camlReactor__compare_1235  (in atest.p.native)        7

【问题讨论】:

    标签: profiling ocaml


    【解决方案1】:

    一个可用的解决方案是 landmarks 库,它允许手动或自动检测代码并结合 CPU 周期计数器、来自 GC 的分配信息和挂钟计时。在 OS X 上运行良好,并允许在必要时进行细粒度分析。

    【讨论】:

      【解决方案2】:

      Poor man's profiler 根本不需要任何代码检测。看到这个example of usage,虽然是分配分析器,但想法是一样的。

      <shameless plug>也可以使用现成的pmp脚本。</shameless plug>

      【讨论】:

      • 点了。我的意思是手动数据收集 - 为了方便起见,我只想获得一个现成的功能列表以及在其中花费的时间。但也许 bash 脚本实际上是为我做的?
      • 好的,我尝试了 pmp 脚本。由于 os x 或 xcode 中不包含 gdb,因此需要通过 homebrew 安装 gdb,创建证书并对其进行自签名。我关注了this guide。不幸的是,在运行脚本时,找不到 /proc//exe 中的进程信息。 os x 似乎没有使用它。因此,由于 os x 的特殊性,答案似乎不起作用。我还尝试在脚本中用 lldb 替换 gdb,但这需要不同的选项,并且可能还会阻塞 /proc/...
      • 试试不带/proc/$OPT_p/exe,我相信只有在底层二进制被删除时才需要它,通常情况下gdb会找到二进制本身就好了
      • 修复脚本在这种情况下不会失败
      • 感谢您抽出宝贵的时间使其工作。该脚本现在运行并且显然确实找到了二进制文件。但不幸的是,它并没有为我产生可用的输出。标准输出打印类似 30 ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::?? ::??我指定的跟踪文件如下所示: 0x000000010ecbe1d8 in ?? () 线程 1(进程 83698 的线程 0x1603):#0 0x000000010ecbe1d8 in ?? () #1 0x000000010fe26c90 在?? () #2 0x000000010ecc326e 在?? () 等命令行是 pmp -b atest.p.native -k traces -l 50 对我来说似乎 gdb 真的不起作用?
      【解决方案3】:

      由于没有人给出肯定的答案,目前似乎没有可用于在 os x 上对 ocaml 程序进行易于使用的时间分析的工具。

      【讨论】:

      • 如果有,我很乐意接受肯定的回答
      • 现在 ocaml 4.04 中有时空分析器。这实际上可以做到。没有亲自尝试过。
      猜你喜欢
      • 2012-07-11
      • 1970-01-01
      • 2012-10-24
      • 2014-11-21
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多