caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Unix module troubles & Time functions
@ 2006-07-18 10:10 Julien Michel
  2006-07-18 11:59 ` [Caml-list] " Jean-Christophe Filliatre
  2006-07-18 15:33 ` William D. Neumann
  0 siblings, 2 replies; 4+ messages in thread
From: Julien Michel @ 2006-07-18 10:10 UTC (permalink / raw)
  To: caml-list

Hi all,
I would like to measure the time a function spends inside a Caml program, for
performance purpose.
I need a function with an accuracy of at least 1us.
I usually use \"gettimeofday\" to achieve this kind of measures with Unix.

So I would like to use the Unix.gettimeofday() function which I expect to have
the same accuracy than the unix one.

I work on an embedded system and I had to specially compile ocamlrun for this
target.

I first tried to compile the sources from my developpement plateform this way:
ocamlc -o main unix.cma *.ml...

then I executed the generated byecode on my embedded target ad got the following
error:
Fatal error: cannot load shared library dllunix
Reason: /usr/local/lib/ocaml/stublibs/dllunix.so: cannot open shared object
file: No such file or directory

whereas, \"dllunix.so\" exists well and the path to raise it is good too!


if I try to compile this way:
ocamlc -o main -cclib -lunix unix.cma *ml
I get the same error as in the message above.


and trying to compile this way:
ocamlc -custom -o main unix.cma *ml
returns this error while executing on my target:
Fatal error: unknown C primitive `unix_dup\'

What can be wrong with my system so that I cannot use the Unix.module?
The Gettimeofday unix function usually works well on my target, is there another
way for having access to it with Caml?

Or generally speaking, does any other function exists to achieve such a
measurement (accuracy about 1 us) ?


Thanks to all

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


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

* Re: [Caml-list] Unix module troubles & Time functions
  2006-07-18 10:10 Unix module troubles & Time functions Julien Michel
@ 2006-07-18 11:59 ` Jean-Christophe Filliatre
  2006-07-18 13:27   ` Julien Michel
  2006-07-18 15:33 ` William D. Neumann
  1 sibling, 1 reply; 4+ messages in thread
From: Jean-Christophe Filliatre @ 2006-07-18 11:59 UTC (permalink / raw)
  To: Julien Michel; +Cc: caml-list


Julien Michel writes:
 > I would like to measure the time a function spends inside a Caml
 > program, for performance purpose.
 > I need a function with an accuracy of at least 1us.
 > [...]
 > Or generally speaking, does any other function exists to achieve such a
 > measurement (accuracy about 1 us) ?

To do such a measurement, I'm using the Unix.times function, as
follows:

======================================================================
open Unix
  
let utime f x =                                                   
  let u = (times()).tms_utime in                                  
  let y = f x in
  let ut = (times()).tms_utime -. u in
  (y,ut)

let print_utime f x = 
  let (y,ut) = utime f x in
  Printf.printf "user time: %2.2f\n" ut;
  y
======================================================================

Hope this helps,
-- 
Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr)


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

* Re: [Caml-list] Unix module troubles & Time functions
  2006-07-18 11:59 ` [Caml-list] " Jean-Christophe Filliatre
@ 2006-07-18 13:27   ` Julien Michel
  0 siblings, 0 replies; 4+ messages in thread
From: Julien Michel @ 2006-07-18 13:27 UTC (permalink / raw)
  To: Jean-Christophe Filliatre; +Cc: caml-list

Quoting Jean-Christophe Filliatre <filliatr@lri.fr>:


> To do such a measurement, I'm using the Unix.times function, as
> follows:
>
> ======================================================================
> open Unix
>
> let utime f x =
>   let u = (times()).tms_utime in
>   let y = f x in
>   let ut = (times()).tms_utime -. u in
>   (y,ut)
>
> let print_utime f x =
>   let (y,ut) = utime f x in
>   Printf.printf "user time: %2.2f\n" ut;
>   y
> ======================================================================
>

Thanks for this piece of advice.
Yet, I work on standalone bytcode files, executed with "ocamlrun" on the target.

So I can not use Unix functions just writing "open Unix" and calling some of the
functions it provides us.

The problem remains the same: for the moment I am still not able to use the Unix
module.

Any idea to fix that point?

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



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

* Re: [Caml-list] Unix module troubles & Time functions
  2006-07-18 10:10 Unix module troubles & Time functions Julien Michel
  2006-07-18 11:59 ` [Caml-list] " Jean-Christophe Filliatre
@ 2006-07-18 15:33 ` William D. Neumann
  1 sibling, 0 replies; 4+ messages in thread
From: William D. Neumann @ 2006-07-18 15:33 UTC (permalink / raw)
  To: Julien Michel; +Cc: caml-list

On Tue, 18 Jul 2006, Julien Michel wrote:

> and trying to compile this way:
> ocamlc -custom -o main unix.cma *ml
> returns this error while executing on my target:
> Fatal error: unknown C primitive `unix_dup\'
>
> What can be wrong with my system so that I cannot use the Unix.module?

Well, you don't have the dup functionality available.  Possibly other 
things are missing as well.  You cauld look into how the Unix build is 
configured and modify it to skip the functionality you don't have (or 
better yet raise an exception).  But that might be more work than you 
need.

> The Gettimeofday unix function usually works well on my target, is there another
> way for having access to it with Caml?

Yes.  You can write your own interface to the gettimeofday function 
(that's all the Unix module's function is).

timer.c
====================================================================

#include <sys/time.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>

CAMLprim value my_gettimeofday(value unit)
{
   struct timeval tp;
   if (gettimeofday(&tp, NULL) == -1) caml_failwith("gettimeofday: 
failure");
   return copy_double((double) tp.tv_sec + (double) tp.tv_usec / 1e6);
}

====================================================================

timer.ml
====================================================================

external timeofday : unit -> float = "my_gettimeofday"

let _ =
   let t1 = timeofday ()
   and t2 = Unix.gettimeofday () in
   Printf.printf "mytime: %f, utime: %f\n" t1 t2;;

====================================================================

[414]  9:24AM% ocamlc timer.c 
[415]  9:29AM% ocamlc -custom -o timer.bc timer.o unix.cma timer.ml 
[416]  9:29AM% ./timer.bc 
mytime: 1153236588.033843, utime: 1153236588.033860

(Note, you won't have the Unix module, so you don't need the unix.cma part 
when you compile your use of the new timeofday function, I just neede it 
to compare to the Unix.gettimeofday function)

Read chapter 18 of the OCaml manual for more info on interfacing OCaml 
with C.

William D. Neumann

---

"There's just so many extra children, we could just feed the
children to these tigers.  We don't need them, we're not doing 
anything with them.

Tigers are noble and sleek; children are loud and messy."

         -- Neko Case

Life is unfair.  Kill yourself or get over it.
 	-- Black Box Recorder


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

end of thread, other threads:[~2006-07-18 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-18 10:10 Unix module troubles & Time functions Julien Michel
2006-07-18 11:59 ` [Caml-list] " Jean-Christophe Filliatre
2006-07-18 13:27   ` Julien Michel
2006-07-18 15:33 ` William D. Neumann

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).