caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Q: Profiling ocaml using gprof
@ 2008-07-15  1:52 Raj Bandyopadhyay
  2008-07-15  4:09 ` [Caml-list] " Jake Donham
  0 siblings, 1 reply; 5+ messages in thread
From: Raj Bandyopadhyay @ 2008-07-15  1:52 UTC (permalink / raw)
  To: caml-list

Hi all

I am profiling my OCaml program for performance using ocamlprof/ 
gprof. I keep seeing
a particular function which takes up a significant % of time. In the  
gprof profile it shows up
as 'camlPervasives__$5e_136'.

Does anyone have an idea which function this might be?

Thanks!
Raj


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Q: Profiling ocaml using gprof
  2008-07-15  1:52 Q: Profiling ocaml using gprof Raj Bandyopadhyay
@ 2008-07-15  4:09 ` Jake Donham
  2008-07-15  5:42   ` Arthur Chan
  2008-07-15  7:11   ` Vincent Hanquez
  0 siblings, 2 replies; 5+ messages in thread
From: Jake Donham @ 2008-07-15  4:09 UTC (permalink / raw)
  To: Raj Bandyopadhyay; +Cc: caml-list

 On Mon, Jul 14, 2008 at 6:52 PM, Raj Bandyopadhyay <rajb@rice.edu> wrote:
> 'camlPervasives__$5e_136'.

It's the string concatenation function (ASCII 5E is ^).

It allocates a new string and blits the two argument strings into it,
so you can probably do much better with explicit use of the Buffer
module.

Jake


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Q: Profiling ocaml using gprof
  2008-07-15  4:09 ` [Caml-list] " Jake Donham
@ 2008-07-15  5:42   ` Arthur Chan
  2008-07-15  9:12     ` Richard Jones
  2008-07-15  7:11   ` Vincent Hanquez
  1 sibling, 1 reply; 5+ messages in thread
From: Arthur Chan @ 2008-07-15  5:42 UTC (permalink / raw)
  To: Jake Donham; +Cc: Raj Bandyopadhyay, caml-list

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

Is gprof better for profiling ocaml than ocaml's own profilers?

How would you go about figuring out that that particular function stub is
string concat?


On Mon, Jul 14, 2008 at 9:09 PM, Jake Donham <jake@donham.org> wrote:

>  On Mon, Jul 14, 2008 at 6:52 PM, Raj Bandyopadhyay <rajb@rice.edu> wrote:
> > 'camlPervasives__$5e_136'.
>
> It's the string concatenation function (ASCII 5E is ^).
>
> It allocates a new string and blits the two argument strings into it,
> so you can probably do much better with explicit use of the Buffer
> module.
>
> Jake
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



-- 
-----------------------------------------------------------------------
(\__/)
(='.'=)This is Bunny. Copy and paste Bunny into your
(")_(")signature to help him gain world domination.
------------------------------------------------------------------------

[-- Attachment #2: Type: text/html, Size: 1887 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Q: Profiling ocaml using gprof
  2008-07-15  4:09 ` [Caml-list] " Jake Donham
  2008-07-15  5:42   ` Arthur Chan
@ 2008-07-15  7:11   ` Vincent Hanquez
  1 sibling, 0 replies; 5+ messages in thread
From: Vincent Hanquez @ 2008-07-15  7:11 UTC (permalink / raw)
  To: Jake Donham; +Cc: Raj Bandyopadhyay, caml-list

On Mon, Jul 14, 2008 at 09:09:01PM -0700, Jake Donham wrote:
>  On Mon, Jul 14, 2008 at 6:52 PM, Raj Bandyopadhyay <rajb@rice.edu> wrote:
> > 'camlPervasives__$5e_136'.
> 
> It's the string concatenation function (ASCII 5E is ^).
> 
> It allocates a new string and blits the two argument strings into it,
> so you can probably do much better with explicit use of the Buffer
> module.

or the explicit String.concat that can account for multiple
concatenations in one go (allocate once, and blit everything).

-- 
Vincent


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Q: Profiling ocaml using gprof
  2008-07-15  5:42   ` Arthur Chan
@ 2008-07-15  9:12     ` Richard Jones
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Jones @ 2008-07-15  9:12 UTC (permalink / raw)
  To: Arthur Chan; +Cc: Jake Donham, caml-list, Raj Bandyopadhyay

On Mon, Jul 14, 2008 at 10:42:39PM -0700, Arthur Chan wrote:
> Is gprof better for profiling ocaml than ocaml's own profilers?

They are slightly different.  I use 'gprof' all the time because I
tend to only use natively compiled executables.  'gprof' is the
ordinary GNU profiling tool that tells you which function is being run
most often and some limited information about the call path into that
function.  It's pretty useful for simple profiling where you're
looking for obvious problems.

'ocamlprof' is a bit different.  Last time I used it [which was a few
years ago, so maybe it's different now], it only worked on bytecode.
It outputs your original code with annotations telling you how often
each expression was run.  So this isn't time taken (each expression
can take a different amount of time to execute, and this time isn't
shown), but how often a particular path through the code is taken.

> How would you go about figuring out that that particular function stub is
> string concat?

> 'camlPervasives__$5e_136'.

In 'gprof' there's a simple name mangling used to map OCaml function
names to assembler symbols.  Once you understand it, you'll find it
easy to follow.  First of all note that OCaml function names aren't
unique, eg in the following code:

  let f () = printf "this is the first f()\n"
  let f () = printf "this is the second f()\n"; f () ;;
  
  f ()

The assembler symbol is:

  "caml" ^ Modulename ^ "__" ^ functionname ^ "_" ^ uniquenumber

'uniquenumber' is just a counter added to function names by the
compiler to make sure that functions which have the same name will
have different symbols.

So when I compiled the code above in a file called 'test.ml' (hence a
module called Test), in my case I ended up with two symbols called:

  camlTest__f_77
  camlTest__f_78

where '77' and '78' are arbitrary.  You can check this by looking at
the assembler output from the compiler (ocamlopt -S).

If a function name contains an operator symbol (eg. (^) ) then a $xx
hex code is used.

I guess in theory one could write an OCaml symbol filter, similar to
c++filt [http://sourceware.org/binutils/docs/binutils/c_002b_002bfilt.html]

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-07-15  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-15  1:52 Q: Profiling ocaml using gprof Raj Bandyopadhyay
2008-07-15  4:09 ` [Caml-list] " Jake Donham
2008-07-15  5:42   ` Arthur Chan
2008-07-15  9:12     ` Richard Jones
2008-07-15  7:11   ` Vincent Hanquez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).