user3240588
user3240588

Reputation: 1252

OCaml time profiling on OS X

In the absence of a working gprof, what other tool can I use to profile on OS X?

(I know about the poor man's approach but would prefer something that does not require manual code instrumentation)

I have so far refrained from installing the full Xcode and tried using Activity Monitor but I am not sure I am doing things right?

Details: I have managed to compile my project for time profiling using ocamlbuild and the ".p.native" build target. I then use Activity Monitor on Mac OS X 10.9 to sample the running process. This gives a whole lot of output about OCaml internals such as garbage collection but I am not seeing properly annotated function names from my module.

A fragment of the output:

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]

I see a lot of symbols similar to .L1099 above but almost none that have a proper name of the type Module-name_function-name_unique-number which is what I expect from reading the OCaml manual. Confusingly a few symbols do appear that are human readable - but not enough to be useful.

Another fragment in which the very last line is a function from my own module

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

Upvotes: 2

Views: 501

Answers (3)

user3240588
user3240588

Reputation: 1252

A usable solution is the landmarks library which allows manual or automatic instrumentation of code and incorporates CPU cycle counters, allocation info from the GC and wall clock timing. Works fine on OS X and allows fine-grained profiling where necessary.

Upvotes: 3

user3240588
user3240588

Reputation: 1252

since nobody came up with a positive answer, it seems that there is currently no tool available for easy-to-use time profiling of ocaml programs on os x.

Upvotes: 1

ygrek
ygrek

Reputation: 6697

Poor man's profiler doesn't require any code instrumentation at all. See this example of usage, albeit for allocation profiler but the idea is the same.

<shameless plug>You can also use ready-made pmp script.</shameless plug>

Upvotes: 1

Related Questions