Esempio n. 1
0
void
run_test (const char *name,
          void (*func) (void))
{
   struct timeval begin;
   struct timeval end;
   struct timeval diff;
   double format;

   TEST_RESULT = "PASS";

   fprintf(stdout, "%-42s : ", name);
   fflush(stdout);
   bson_gettimeofday(&begin);
   func();
   bson_gettimeofday(&end);
   fprintf(stdout, "%s", TEST_RESULT);

   diff.tv_sec = end.tv_sec - begin.tv_sec;
   diff.tv_usec = end.tv_usec - begin.tv_usec;

   if (diff.tv_usec < 0) {
      diff.tv_sec -= 1;
      diff.tv_usec = diff.tv_usec + 1000000;
   }

   format = diff.tv_sec + (diff.tv_usec / 1000000.0);
   fprintf(stdout, " : %lf\n", format);
}
Esempio n. 2
0
int64_t
bson_get_monotonic_time (void)
{
#if defined(BSON_HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
   struct timespec ts;
   clock_gettime (CLOCK_MONOTONIC, &ts);
   return ((ts.tv_sec * 1000000UL) + (ts.tv_nsec / 1000UL));
#elif defined(__APPLE__)
   static mach_timebase_info_data_t info = { 0 };
   static double ratio = 0.0;

   if (!info.denom) {
      // the value from mach_absolute_time () * info.numer / info.denom
      // is in nano seconds. So we have to divid by 1000.0 to get micro seconds
      mach_timebase_info (&info);
      ratio = (double)info.numer / (double)info.denom / 1000.0;
   }

   return mach_absolute_time () * ratio;
#elif defined(_WIN32)
   /* Despite it's name, this is in milliseconds! */
   int64_t ticks = GetTickCount64 ();
   return (ticks * 1000L);
#else
# warning "Monotonic clock is not yet supported on your platform."
   struct timeval tv;

   bson_gettimeofday (&tv, NULL);
   return (tv.tv_sec * 1000000UL) + tv.tv_usec;
#endif
}
Esempio n. 3
0
static double
dtimeofday (void)
{
    struct timeval timeval;
    bson_gettimeofday(&timeval);
    return (timeval.tv_sec + timeval.tv_usec * 0.000001);
}
Esempio n. 4
0
double
dtimeofday ()
{
   struct timeval tv;
   bson_gettimeofday (&tv);
   return tv.tv_sec + 0.000001 * tv.tv_usec;
}
Esempio n. 5
0
void
mongoc_log_default_handler (mongoc_log_level_t  log_level,
                            const char         *log_domain,
                            const char         *message,
                            void               *user_data)
{
   struct timeval tv;
   struct tm tt;
   time_t t;
   FILE *stream;
   char nowstr[32];
   int pid;

   bson_gettimeofday(&tv, NULL);
   t = tv.tv_sec;

#ifdef _WIN32
#  ifdef _MSC_VER
     localtime_s(&tt, &t);
#  else
     tt = *(localtime(&t));
#  endif
#else
   localtime_r(&t, &tt);
#endif

   strftime (nowstr, sizeof nowstr, "%Y/%m/%d %H:%M:%S", &tt);

   switch (log_level) {
   case MONGOC_LOG_LEVEL_ERROR:
   case MONGOC_LOG_LEVEL_CRITICAL:
   case MONGOC_LOG_LEVEL_WARNING:
      stream = stderr;
      break;
   case MONGOC_LOG_LEVEL_MESSAGE:
   case MONGOC_LOG_LEVEL_INFO:
   case MONGOC_LOG_LEVEL_DEBUG:
   case MONGOC_LOG_LEVEL_TRACE:
   default:
      stream = stdout;
   }

#ifdef __linux__
   pid = syscall (SYS_gettid);
#elif defined(_WIN32)
   pid = (int)_getpid ();
#else
   pid = (int)getpid ();
#endif

   fprintf (stream,
            "%s.%04ld: [%5d]: %8s: %12s: %s\n",
            nowstr,
            tv.tv_usec / 1000L,
            pid,
            mongoc_log_level_str(log_level),
            log_domain,
            message);
}