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.640 2007/06/10 18:11:12 mast Exp $ + || $Id: builtin_functions.c,v 1.641 2007/06/10 19:03:11 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:7258:    *! "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. 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. See @[System.CPU_TIME_RESOLUTION]. +  *! microseconds 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.    *!
pike.git/src/builtin_functions.c:7298:   #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) +  +  if (nsec) {    push_int64(time); -  else -  push_int64(time/1000); + #ifndef LONG_CPU_TIME +  push_int (1000000000 / CPU_TIME_TICKS); +  o_multiply(); + #endif    } -  +  else { + #if CPU_TIME_TICKS > 1000000 +  push_int64(time / (CPU_TIME_TICKS / 1000000)); + #else +  push_int64 (time); +  push_int (1000000 / CPU_TIME_TICKS); +  o_multiply(); + #endif +  } + }      /*! @decl int gethrtime (void|int nsec)    *!    *! 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. See @[System.REAL_TIME_RESOLUTION]. +  *! microseconds 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); +  cpu_time_t time = get_real_time();    -  pop_n_elems(args); -  if(nsec) -  push_int64(gethrtime()); -  else -  push_int64(gethrtime()/1000); +  if (time == (cpu_time_t) -1) { +  pop_n_elems (args); +  push_int (-1); +  return;    } - #else - PMOD_EXPORT void f_gethrtime(INT32 args) - { -  int nsec = 0; +     nsec = args && !UNSAFE_IS_ZERO(Pike_sp-args);       pop_n_elems(args); -  GETTIMEOFDAY(&current_time); - #ifdef INT64 -  if(nsec) -  push_int64((((INT64)current_time.tv_sec * 1000000) + current_time.tv_usec)*1000); -  else -  push_int64(((INT64)current_time.tv_sec * 1000000) + current_time.tv_usec); - #else /* !INT64 */ -  if(nsec) -  push_int64(((current_time.tv_sec * 1000000) + current_time.tv_usec)*1000); -  else -  push_int64((current_time.tv_sec * 1000000) + current_time.tv_usec); - #endif /* INT64 */ +  if (nsec) { +  push_int64(time); + #ifndef LONG_CPU_TIME +  push_int (1000000000 / CPU_TIME_TICKS); +  o_multiply(); + #endif    } - #endif /* HAVE_GETHRTIME */ +  else { + #if CPU_TIME_TICKS > 1000000 +  push_int64(time / (CPU_TIME_TICKS / 1000000)); + #else +  push_int64 (time); +  push_int (1000000 / CPU_TIME_TICKS); +  o_multiply(); + #endif +  } + }      #ifdef PROFILING   /*! @decl array(int|mapping(string:array(int))) @    *! get_profiling_info(program prog)    *!    *! Get profiling information.    *!    *! @returns    *! Returns an array with two elements.    *! @array