anol
anol

Reputation: 8953

OCaml binary compiled with profiling information

Given a binary file compiled with OCaml, is there a way to find out if it has been compiled with profiling information (either using ocamlcp/ocamloptp, or with gprof-specific data via ocamlopt -p)?

Upvotes: 4

Views: 152

Answers (2)

anol
anol

Reputation: 8953

Note: the old profiling flag (ocamlopt -p) produces gprof-specific information and does not produce camlProfiling symbols as in Jeffrey's answer. But using ocamloptp, his solution works.

If you need the "old" method, as indicated in this website, a somewhat reliable way to identify if a binary has been compiled with gprof support is to check for the presence of symbol mcount:

nm <native binary> | grep mcount

Only programs compiled with -p should contain the mcount symbol:

U mcount@@GLIBC_2.2.5

Otherwise, the program has not been compiled using the -p flag.

Upvotes: 1

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66808

If you run ocamlobjinfo on a profiled bytecode file, it shows Profiling as one of the imported interfaces:

$ ocamlcp -c my.ml
$ ocamlobjinfo my.cmo
File my.cmo
Unit name: My
Interfaces imported:
        720848e0b508273805ef38d884a57618    Array
        d7e1aaf95ba3578d33efe347aefa6c49    My
        db723a1798b122e08919a2bfed062514    Pervasives
        6a6248bae49664a0bb530dd3f0c15b79    Profiling
Uses unsafe features: no
$ 

Update

On my system (OS X) A profiled native executable contains a definition of camlProfiling and related symbols:

$ ocamlopt -o my my.ml
$ nm my | grep camlProfiling
$ ocamloptp -o my my.ml
$ nm my | grep camlProfiling
000000010003e240 D _camlProfiling
000000010003e2e0 d _camlProfiling__1
000000010003e300 d _camlProfiling__2
000000010003e318 d _camlProfiling__3
000000010003e268 d _camlProfiling__4
000000010003e280 d _camlProfiling__5
000000010003e2a0 d _camlProfiling__6
000000010003e2c0 d _camlProfiling__7
0000000100003760 T _camlProfiling__code_begin
0000000100003ac7 T _camlProfiling__code_end
000000010003e238 D _camlProfiling__data_begin
000000010003e328 D _camlProfiling__data_end
00000001000038d0 T _camlProfiling__dump_counters_1014
0000000100003a40 T _camlProfiling__entry
000000010003e32c D _camlProfiling__frametable
0000000100003770 T _camlProfiling__fun_1046
0000000100003800 T _camlProfiling__fun_1048
0000000100003890 T _camlProfiling__incr_1010

It seems very likely this will work on every system that supports nm.

Upvotes: 2

Related Questions