Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Profiling a function execution
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] Profiling a function execution
Le 25 nov. 03, à 19:05, Xavier Leroy a écrit :

> I haven't looked at other Unix
> kernels, but I suspect that the additional precision made possible by
> the getrusage() syscall is simply not exploited.
I have done tests using the C code appended to this email.

Indeed with the Darwin Kernel 7.0.0 (MacOS X), you don't get extra 
precision with the figures returned by getrusage(). I was mistaken by 
the potential of the data structure described in the man page (there's 
no info about the actual granularity there).

You can remove my wish (id=1937) for getrusage bindings from your 

> your question begs another
> question: why would you need to do distinguish native code from
> bytecode?
I just wanted a quick way to distinguish, on output, my bytecode 
profiles from native ones. This can of course be handled very easily 
with a preprocessor, I was just wondering if I had missed a flag in the 
style of Sys.interactive.

>   We're working hard on removing the last discrepancies
> between the two compilers...
One could argue that since there exists some discrepancies such a flag 
should exist. However I doubt its usefulness in common practice (which 
is why I didn't file a feature wish for that one). Furthermore, if it 
doesn't exist, removing the last discrepancies becomes a must...

Thanks for your answers,


--- test.c ---
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/time.h>
#include <sys/resource.h>

#define NUM_OPS ULONG_MAX / 100

void idle (void)
   unsigned long i;
   int op;

   for (i = 0; i < NUM_OPS; i++) op = 1+1;

void diff_times (void)
   struct tms t1, t2;

   printf("times: %fs user %fs sys\n",
	 (double)(t2.tms_utime-t1.tms_utime) / CLK_TCK,
	 (double)(t2.tms_stime-t1.tms_stime) / CLK_TCK);

void diff_getrusage(void)
   struct rusage t1, t2;

   getrusage(RUSAGE_SELF, &t1);
   getrusage(RUSAGE_SELF, &t2);
   printf("getrusage: %fs user %fs sys\n",
	 (double)t2.ru_utime.tv_sec + (double)t2.ru_utime.tv_usec / 1e6 -
	 ((double)t1.ru_utime.tv_sec + (double)t1.ru_utime.tv_usec / 1e6),
	 (double)t2.ru_stime.tv_sec + (double)t2.ru_stime.tv_usec / 1e6 -
	 ((double)t1.ru_stime.tv_sec + (double)t1.ru_stime.tv_usec / 1e6));

int main(int argc, char **argv)
   return 0;
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: