pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.639 2007/06/02 04:11:30 mbaehr Exp $ + || $Id: builtin_functions.c,v 1.640 2007/06/10 18:11:12 mast Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin_functions.c:7249:   /*! @decl int gethrvtime (void|int nsec)    *!    *! Return the CPU time that has been consumed by this process or    *! thread. -1 is returned if the system couldn't determine it. The    *! time is normally returned in microseconds, but if the optional    *! argument @[nsec] is nonzero it's returned in nanoseconds.    *!    *! The CPU time includes both user and system time, i.e. it's    *! approximately the same thing you would get by adding together the    *! "utime" and "stime" fields returned by @[System.getrusage] (but -  *! perhaps with better accuracy). It's however system dependent -  *! whether or not it's the time consumed in all threads or in the -  *! current one only; @[System.CPU_TIME_IS_THREAD_LOCAL] tells which. +  *! perhaps with better accuracy).    *! -  +  *! It's however system dependent whether or not it's the time +  *! consumed in all threads or in the current one only; +  *! @[System.CPU_TIME_IS_THREAD_LOCAL] tells which. If both types are +  *! available then thread local time is preferred. +  *!    *! @note    *! The actual accuracy on many systems is significantly less than -  *! milliseconds or nanoseconds. +  *! milliseconds or nanoseconds. See @[System.CPU_TIME_RESOLUTION].    *!    *! @note    *! The garbage collector might run automatically at any time. The    *! time it takes is not included in the figure returned by this    *! function, so that normal measurements aren't randomly clobbered    *! by it. Explicit calls to @[gc] are still included, though.    *!    *! @note    *! The special function @[gauge] is implemented with this function.    *!    *! @seealso -  *! @[System.CPU_TIME_IS_THREAD_LOCAL], @[gauge()], -  *! @[System.getrusage()], @[gethrtime()] +  *! @[System.CPU_TIME_IS_THREAD_LOCAL], @[System.CPU_TIME_RESOLUTION], +  *! @[gauge()], @[System.getrusage()], @[gethrtime()]    */   PMOD_EXPORT void f_gethrvtime(INT32 args)   {    int nsec = 0;    cpu_time_t time = get_cpu_time();       if (time == (cpu_time_t) -1) {    pop_n_elems (args);    push_int (-1);    return;    }    -  /* Don't subtract the gc time at all if we don't know whether it's -  * thread local or not, since if we do it wrong we might end up -  * returning a negative number. */ - #if CPU_TIME_IS_THREAD_LOCAL == PIKE_YES + #ifdef CPU_TIME_MIGHT_BE_THREAD_LOCAL +  if (cpu_time_is_thread_local)    time -= Pike_interpreter.thread_state->auto_gc_time; - #elif CPU_TIME_IS_THREAD_LOCAL == PIKE_NO +  else + #endif +  { + #ifdef CPU_TIME_MIGHT_NOT_BE_THREAD_LOCAL    time -= auto_gc_time;   #endif -  +  }       nsec = args && !UNSAFE_IS_ZERO(Pike_sp-args);       pop_n_elems(args);    if (nsec)    push_int64(time);    else    push_int64(time/1000);   }      /*! @decl int gethrtime (void|int nsec)    *! -  *! Return the real time since some arbitrary event in the past. The -  *! time is normally returned in microseconds, but if the optional -  *! argument @[nsec] is nonzero it's returned in nanoseconds. +  *! Return the high resolution real time since some arbitrary event in +  *! the past. The time is normally returned in microseconds, but if +  *! the optional argument @[nsec] is nonzero it's returned in +  *! nanoseconds.    *! -  +  *! It's system dependent whether or not this time is monotonic, i.e. +  *! if it's unaffected by adjustments of the calendaric clock in the +  *! system. @[System.REAL_TIME_IS_MONOTONIC] tells what it is. Pike +  *! tries to use monotonic time for this function if it's avaiable. +  *!    *! @note    *! The actual accuracy on many systems is significantly less than -  *! milliseconds or nanoseconds. +  *! milliseconds or nanoseconds. See @[System.REAL_TIME_RESOLUTION].    *!    *! @seealso -  +  *! @[System.REAL_TIME_IS_MONOTONIC], @[System.REAL_TIME_RESOLUTION],    *! @[time()], @[System.gettimeofday()], @[gethrvtime()]    */   #ifdef HAVE_GETHRTIME   PMOD_EXPORT void f_gethrtime(INT32 args)   {    int nsec = 0;    nsec = args && !UNSAFE_IS_ZERO(Pike_sp-args);       pop_n_elems(args);    if(nsec)