Exemplo n.º 1
0
double timer()
{
	static bool running = false;
	static _timeb start, end;

	if (!running)
	{
#ifdef USING_VISUAL_2005
		_ftime_s(&start);
#else
		_ftime(&start);
#endif //USING_VISUAL_2005
		running = true;
		return 0.0;
	}
	else
	{
#ifdef USING_VISUAL_2005
		_ftime_s(&end);
#else
		_ftime(&end);
#endif //USING_VISUAL_2005
		running = false;
		return (end.time-start.time)+(end.millitm-start.millitm)/1000.0;
	}
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
TimeTag TimeTag::getCurrentTime()
{
	uint32_t retSeconds;
	uint32_t retFraction;

#ifdef WIN32
	_timeb currentTime;

	_ftime_s(&currentTime);

	//2208988800 = Num. seconds from 1900 to 1970, where _ftime starts from.
	retSeconds = 2208988800 + static_cast<uint32_t>(currentTime.time);
	//Correct for timezone.
	retSeconds -= static_cast<uint32_t>(60 * currentTime.timezone);
	//Correct for daylight savings time.
	if(currentTime.dstflag)
		retSeconds += static_cast<uint32_t>(3600);

	retFraction = static_cast<uint32_t>(currentTime.millitm);
	//Fill up all 32 bits...
	retFraction *= static_cast<uint32_t>(static_cast<float>(1<<31)/1000000.0f);
#else
	retSeconds = 0;
	retFraction = 0;
#endif

	return TimeTag(retSeconds, retFraction);
}
Exemplo n.º 3
0
// Must be outside the namespace for obvious reasons
//
int main (int argc, char** argv)
{
#ifdef _MSC_VER
    {
        // Work around for https://svn.boost.org/trac/boost/ticket/10657
        // Reported against boost version 1.56.0.  If an application's
        // first call to GetTimeZoneInformation is from a coroutine, an
        // unhandled exception is generated.  A workaround is to call
        // GetTimeZoneInformation at least once before launching any
        // coroutines.  At the time of this writing the _ftime call is
        // used to initialize the timezone information.
        struct _timeb t;
    #ifdef _INC_TIME_INL
            _ftime_s (&t);
    #else
            _ftime (&t);
    #endif
    }
    ripple::sha512_deprecatedMSVCWorkaround();
#endif

#if defined(__GNUC__) && !defined(__clang__)
    auto constexpr gccver = (__GNUC__ * 100 * 100) +
                            (__GNUC_MINOR__ * 100) +
                            __GNUC_PATCHLEVEL__;

    static_assert (gccver >= 50100,
        "GCC version 5.1.0 or later is required to compile rippled.");
#endif

    //
    // These debug heap calls do nothing in release or non Visual Studio builds.
    //

    // Checks the heap at every allocation and deallocation (slow).
    //
    //beast::Debug::setAlwaysCheckHeap (false);

    // Keeps freed memory blocks and fills them with a guard value.
    //
    //beast::Debug::setHeapDelayedFree (false);

    // At exit, reports all memory blocks which have not been freed.
    //
#if RIPPLE_DUMP_LEAKS_ON_EXIT
    beast::Debug::setHeapReportLeaks (true);
#else
    beast::Debug::setHeapReportLeaks (false);
#endif

    atexit(&google::protobuf::ShutdownProtobufLibrary);

    std::set_terminate(ripple::terminateHandler);

    auto const result (ripple::run (argc, argv));

    beast::basic_seconds_clock_main_hook();

    return result;
}
Exemplo n.º 4
0
int gettimeofday(struct timeval* t, void* timezone) {
  struct _timeb timebuffer;
  _ftime_s(&timebuffer);
  t->tv_sec = (long)timebuffer.time;
  t->tv_usec = 1000 * timebuffer.millitm;
  return 0;
}
Exemplo n.º 5
0
gpr_timespec gpr_now(gpr_clock_type clock) {
  gpr_timespec now_tv;
  LONGLONG diff;
  struct _timeb now_tb;
  LARGE_INTEGER timestamp;
  double now_dbl;
  now_tv.clock_type = clock;
  switch (clock) {
    case GPR_CLOCK_REALTIME:
      _ftime_s(&now_tb);
      now_tv.tv_sec = (int64_t)now_tb.time;
      now_tv.tv_nsec = now_tb.millitm * 1000000;
      break;
    case GPR_CLOCK_MONOTONIC:
    case GPR_CLOCK_PRECISE:
      QueryPerformanceCounter(&timestamp);
      diff = timestamp.QuadPart - g_start_time.QuadPart;
      now_dbl = (double)diff * g_time_scale;
      now_tv.tv_sec = (int64_t)now_dbl;
      now_tv.tv_nsec = (int32_t)((now_dbl - (double)now_tv.tv_sec) * 1e9);
      break;
    case GPR_TIMESPAN:
      abort();
      break;
  }
  return now_tv;
}
Exemplo n.º 6
0
static uint64_t
gettime() {
	uint64_t t;
#if defined(_WIN32) || defined(_WIN64)
	struct _timeb timebuffer;
	_ftime_s(&timebuffer);
	t = timebuffer.time * 100;
	t += timebuffer.millitm / 10;
#elif !defined(__APPLE__)

#ifdef CLOCK_MONOTONIC_RAW
#define CLOCK_TIMER CLOCK_MONOTONIC_RAW
#else
#define CLOCK_TIMER CLOCK_MONOTONIC
#endif

	struct timespec ti;
	clock_gettime(CLOCK_TIMER, &ti);
	t = (uint64_t)ti.tv_sec * 100;
	t += ti.tv_nsec / 10000000;
#else
	struct timeval tv;
	gettimeofday(&tv, NULL);
	t = (uint64_t)tv.tv_sec * 100;
	t += tv.tv_usec / 10000;
#endif
	return t;
}
Exemplo n.º 7
0
int _tthread_timespec_get(struct timespec *ts, int base)
{
#if defined(_TTHREAD_WIN32_)
  struct _timeb tb;
#elif !defined(CLOCK_REALTIME)
  struct timeval tv;
#endif

  if (base != TIME_UTC)
  {
    return 0;
  }

#if defined(_TTHREAD_WIN32_)
  _ftime_s(&tb);
  ts->tv_sec = (time_t)tb.time;
  ts->tv_nsec = 1000000L * (long)tb.millitm;
#elif defined(CLOCK_REALTIME)
  base = (clock_gettime(CLOCK_REALTIME, ts) == 0) ? base : 0;
#else
  gettimeofday(&tv, NULL);
  ts->tv_sec = (time_t)tv.tv_sec;
  ts->tv_nsec = 1000L * (long)tv.tv_usec;
#endif

  return base;
}
Exemplo n.º 8
0
TIMELIB_API __int64 TIMELIB_CALL tlCurrentTimestamp(bool in_local_time)
{
    __int64     result = 0;

    #ifdef _WIN32
    struct _timeb   now;

    _ftime_s(&now);

    result = (now.time * I64C(1000000)) + (now.millitm * 1000);
    #else
    struct timeval  tv;

    if (gettimeofday(&tv, NULL) == 0)
    {
        result = (tv.tv_sec * I64C(1000000)) + tv.tv_usec;
    }
    #endif

    if (in_local_time)
    {
        result += (static_cast<__int64>(tlLocalTimeZoneOffset()) * I64C(1000000));
    }

    return result;
}
Exemplo n.º 9
0
inline nanospan nanotime()
{

#if defined(HAVE_CLOCK_GETTIME_FUNC)
  timespec ts;
  if ( -1 == clock_gettime(CLOCK_MONOTONIC, &ts) )
    return nanospan();
  return nanospan(ts.tv_sec, ts.tv_nsec);
#elif defined(HAVE_GETTIMEOFDAY_FUNC)
  timeval tv;
  ::gettimeofday(&tv, 0);
  return nanospan(tv.tv_sec, tv.tv_usec*1000L);
#elif defined(HAVE__FTIME_S_FUNC)
  struct _timeb timebuffer;
  _ftime_s( &timebuffer );
  return millispan(static_cast<xsec_t>(timebuffer.time), static_cast<xsec_t>(timebuffer.millitm) );
#elif defined(HAVE__FTIME_FUNC)
  struct _timeb timebuffer;
  _ftime( &timebuffer );
  return millispan(static_cast<xsec_t>(timebuffer.time), static_cast<xsec_t>(timebuffer.millitm) );
#elif defined(HAVE_FTIME_FUNC)
	struct timeb timebuffer;
	ftime( &timebuffer );
	return millispan(static_cast<xsec_t>(timebuffer.time), static_cast<xsec_t>(timebuffer.millitm) );
#else
#error FAIL
#endif //HAVE_CLOCK_GETTIME_FUNC
  return nanospan(0, 0);
}
Exemplo n.º 10
0
int gettimeofday(struct timeval *tv, struct timezone *tz) {
	struct _timeb t;

	_ftime_s(&t);
	tv->tv_sec = t.time;
	tv->tv_usec = t.millitm * 1000;
	return 0;
}
Exemplo n.º 11
0
void gettimeofday(struct mytimeval *a)
/* only accurate to milliseconds, instead of microseconds */
{
    struct _timeb tstruct;
    _ftime_s(&tstruct);

    a->tv_sec = tstruct.time;
    a->tv_usec = tstruct.millitm * 1000;
}
Exemplo n.º 12
0
/* Get random data.
*/
void
get_random_data(unsigned char *data, const size_t len)
{
    uint32_t    i;
#ifdef WIN32
	int				rnum;
	struct _timeb	tb;

	_ftime_s(&tb);

	srand((uint32_t)(tb.time*1000)+tb.millitm);

	for(i=0; i<len; i++)
	{
		rnum = rand();
        *(data+i) = rnum % 0xff;
	}
#else
	FILE           *rfd;
    struct timeval  tv;
    int             do_time = 0;
    size_t          amt_read;

    /* Attempt to read seed data from /dev/urandom.  If that does not
     * work, then fall back to a time-based method (less secure, but
     * probably more portable).
    */
    if((rfd = fopen(RAND_FILE, "r")) == NULL)
    {
        do_time = 1;
    }
    else
    {
        /* Read seed from /dev/urandom
        */
        amt_read = fread(data, len, 1, rfd);
        fclose(rfd);

        if (amt_read != 1)
            do_time = 1;
    }

    if (do_time)
    {
        /* Seed based on time (current usecs).
        */
        gettimeofday(&tv, NULL);
        srand(tv.tv_usec);

        for(i=0; i<len; i++)
            *(data+i) = rand() % 0xff;
    }

#endif

}
Exemplo n.º 13
0
int
gettimeofday (struct timeval *tv, void *tz)
{
  struct _timeb timebuf;
  _ftime_s(&timebuf);
  tv->tv_sec = timebuf.time;
  tv->tv_usec = timebuf.millitm * 1000;

  return 0;
}
Exemplo n.º 14
0
	void OilFieldMonitor::startSimulation() {
		startup();

		//Get start time
		_ftime_s(&tStruct);	
		//Calc next output time
		double thisTime = tStruct.time + (((double)(tStruct.millitm)) / 1000.0);
		double outputTime = thisTime + 5.0;

		int hit;     // key hit flag
		char keyPressed;     // character key which was hit

		while (!shutdown) {
			//Get the current time
			_ftime_s(&tStruct);
			thisTime = tStruct.time + (((double) (tStruct.millitm)) / 1000.0); 

			//Check for 5 second interval to print status to screen
			if (thisTime >= outputTime) {

				//Do stuff here
				print();

				//Set time for next 5 second interval
				outputTime += 5.0; 
			}

			hit = _kbhit(); //See if a key has been pressed
			if (hit) {
				keyPressed = _getch();	// Get the key pressed

				if (keyPressed == 'q' || keyPressed == 'Q') {
					//Time to quit
					shutdown = true;
				} else {
					//Print Menu
					menu(keyPressed);
				}

			} //End if hit
		} //END while ! shutdown
	} //END startSimulation()
Exemplo n.º 15
0
int wc_util_timeofday(struct timeval *tv)
{
	if (tv) {
		struct _timeb tb = { 0 };
		_ftime_s(&tb);
		tv->tv_sec = (long)tb.time;
		tv->tv_usec = (long)tb.millitm * 1000;
		return 0;
	}
	return -1;
}
Exemplo n.º 16
0
//==============================================================================
int64 Time::currentTimeMillis() noexcept
{
   #if JUCE_WINDOWS && ! JUCE_MINGW
    struct _timeb t;
    _ftime_s (&t);
    return ((int64) t.time) * 1000 + t.millitm;
   #else
    struct timeval tv;
    gettimeofday (&tv, nullptr);
    return ((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
   #endif
}
Exemplo n.º 17
0
	uint64_t CTimerThread::GetMilSec()
	{
#ifdef HAVE_WINDOWS
		struct _timeb tb;
		_ftime_s(&tb);
		return tb.time * 1000 + tb.millitm;
#elif defined HAVE_LINUX
		struct timeval currentTv;
		gettimeofday(&currentTv, NULL);
		return (currentTv.tv_sec * 1000 + currentTv.tv_usec / 1000);
#endif
	}
Exemplo n.º 18
0
string  GetNowTime()
{
	struct tm now;
	struct _timeb tb;
	_ftime_s(&tb);
	localtime_s(&now, &tb.time);
	char pAddrB[30];
	sprintf_s(pAddrB, 30, "%04d-%02d-%02d %02d:%02d:%02d.%03d", now.tm_year + 1900,
		now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, tb.millitm);
	string stime(pAddrB);
	return stime;

}
Exemplo n.º 19
0
// internal function
void dnm_ucli_printfTimestamp_v(const char *format, va_list arg)
{
#ifdef WIN32
   // Print Windows time
   struct _timeb t;
   struct tm     locTime;
   _ftime_s(&t);
   localtime_s(&locTime, &(t.time));
   dnm_ucli_printf("(%02d:%02d:%02d.%03d) ", locTime.tm_hour, locTime.tm_min, locTime.tm_sec, t.millitm);
#endif
   dnm_ucli_printf("%6u : ", OSTimeGet());   // TODO change to print sec.msec
   dnm_ucli_printf_v(format, arg);
}
Exemplo n.º 20
0
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
#if 0 // another potential solution to this problem
   SYSTEMTIME sysTime;
   GetLocalTime(&sysTime);
#else
   struct _timeb timebuffer;
   _ftime_s(&timebuffer);

   tv->tv_sec = (long)timebuffer.time;
   tv->tv_usec = 1000 * timebuffer.millitm;
#endif
   return 0;
}
/* Catches calls to the POSIX gettimeofday and converts them to a related WIN32 version. */
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
	struct _timeb timeptr;

	_ftime_s (&timeptr);

	tv->tv_sec = timeptr.time;
	tv->tv_usec = timeptr.millitm * 1000;

	tz->tz_dsttime = timeptr.dstflag;
	tz->tz_dsttime = timeptr.timezone;

	return 0;
}
Exemplo n.º 22
0
/*----------------------------------------------------------------------
|   NPT_System::GetCurrentTimeStamp
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now)
{
    struct _timeb time_stamp;

#if defined(_MSC_VER) && (_MSC_VER >= 1400)
    _ftime_s(&time_stamp);
#else
    _ftime(&time_stamp);
#endif
    now.SetNanos(((NPT_UInt64)time_stamp.time)     * 1000000000UL +
                  ((NPT_UInt64)time_stamp.millitm) * 1000000);

    return NPT_SUCCESS;
}
Exemplo n.º 23
0
//==============================================================================
int64 Time::currentTimeMillis() noexcept
{
  #if JUCE_WINDOWS
    struct _timeb t;
   #ifdef _INC_TIME_INL
    _ftime_s (&t);
   #else
    _ftime (&t);
   #endif
    return ((int64) t.time) * 1000 + t.millitm;
  #else
    struct timeval tv;
    gettimeofday (&tv, nullptr);
    return ((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
  #endif
}
Exemplo n.º 24
0
static void aeGetTime(PORT_LONG *seconds, PORT_LONG *milliseconds)
{
#ifdef _WIN32
    struct _timeb tb;

    memset(&tb, 0, sizeof(struct _timeb));
    _ftime_s(&tb);
    (*seconds) = tb.time;
    (*milliseconds) = tb.millitm;
#else
    struct timeval tv;

    gettimeofday(&tv, NULL);
    *seconds = tv.tv_sec;
    *milliseconds = tv.tv_usec/1000;
#endif
}
Exemplo n.º 25
0
static int logBase(LogLevel level, const char * format, va_list ap)
{
  struct _timeb timebuffer;
  struct tm tm;
  char strTmp[60];

  if (level > logLevel)
  {
    return 0;
  }

  _ftime_s(&timebuffer);
  localtime_s(&tm, &timebuffer.time);
  strftime(strTmp, 60, "%Y-%m-%d %H:%M:%S", &tm);
  fprintf(stderr, "%s %s,%3.3d [%s] ", logLevels[level], strTmp, timebuffer.millitm, progName);

  return vfprintf(stderr, format, ap);
}
Exemplo n.º 26
0
// centisecond: 1/100 second
static void
systime(uint32_t *sec, uint32_t *cs) {
#if defined(_WIN32) || defined(_WIN64)
	struct _timeb timebuffer;
	_ftime_s(&timebuffer);
	*sec = (uint32_t)timebuffer.time;
	*cs = timebuffer.millitm / 10;
#elif !defined(__APPLE__)
	struct timespec ti;
	clock_gettime(CLOCK_REALTIME, &ti);
	*sec = (uint32_t)ti.tv_sec;
	*cs = (uint32_t)(ti.tv_nsec / 10000000);
#else
	struct timeval tv;
	gettimeofday(&tv, NULL);
	*sec = tv.tv_sec;
	*cs = tv.tv_usec / 10000;
#endif
}
Exemplo n.º 27
0
double my_floattime() {
#ifdef _WIN32
#if _MSC_VER == 1310
  struct _timeb t;
  _ftime(&t);
  return (double)t.time + (double)t.millitm * (double)0.001;
#else
  struct _timeb t;
  if (_ftime_s(&t)==0) {
    return (double)t.time + (double)t.millitm * (double)0.001;
  }
  else {
    return 0.0;
  }
#endif
#else
  struct timeval t;
  if (gettimeofday(&t, (struct timezone *)NULL) == 0)
    return (double)t.tv_sec + t.tv_usec*0.000001;
  else
    return 0.0;
#endif
}
Exemplo n.º 28
0
//==============================================================================
int64 Time::currentTimeMillis() noexcept
{
    static uint32 lastCounterResult = 0xffffffff;
    static int64 correction = 0;

    const uint32 now = getMillisecondCounter();

    // check the counter hasn't wrapped (also triggered the first time this function is called)
    if (now < lastCounterResult)
    {
        // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
        if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
        {
            // get the time once using normal library calls, and store the difference needed to
            // turn the millisecond counter into a real time.
          #if JUCE_WINDOWS
            struct _timeb t;
           #ifdef USE_NEW_SECURE_TIME_FNS
            _ftime_s (&t);
           #else
            _ftime (&t);
           #endif
            correction = (((int64) t.time) * 1000 + t.millitm) - now;
          #else
            struct timeval tv;
            struct timezone tz;
            gettimeofday (&tv, &tz);
            correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
          #endif
        }
    }

    lastCounterResult = now;

    return correction + now;
}
Exemplo n.º 29
0
bool MsgLogger::Log(const char* msg, int level) {
    if (level > m_maxLevel)
        return true;

    size_t msgLen = 0;
    string oldMsg;
    if (m_hasMsgModifier) {
        oldMsg = msg;
        string newMsg;
        for(list<MsgModifier*>::iterator it = m_msgModifiers.begin(); it != m_msgModifiers.end(); ++it) {
            MsgModifier* msgModifier = *it;
            if (!msgModifier->ModifyMsg(oldMsg, newMsg))
                return false;
            oldMsg.swap(newMsg);
            newMsg.clear();
        }
        msg = oldMsg.c_str();
        msgLen = oldMsg.size();
    } else {
        msgLen = strlen(msg);
    }

    WaitForSingleObject(m_mutex, INFINITE);

    _timeb tbNow;
    _ftime_s(&tbNow);
    time_t ttNow = tbNow.time;
    time_t ttNowAdj = ttNow + TZ_ADJUST;
    time_t day = ttNowAdj / (24 * 3600);
    int timeOfDay = ttNowAdj % (24 * 3600);
    int hour = timeOfDay / 3600;
    int timeOfHour = timeOfDay % 3600;
    int min = timeOfHour / 60;
    int sec = timeOfHour % 60;

    bool dayChanged = (day != m_ttLogDay);
    if (dayChanged) {
        m_ttLogDay = day;

        tm tmNow;
        localtime_s(&tmNow, &ttNow);
        char strLogDay[256];
        strftime(strLogDay, 256, "%Y-%m-%d", &tmNow);
        m_strLogDay = strLogDay;
    }

    int tid = GetCurrentThreadId();

    char title[256];
    size_t titleLen = _snprintf_s(title, 256, _TRUNCATE, "%s %02d:%02d:%02d.%03d%s%s%s%d%s", m_strLogDay.c_str(), hour, min, sec, (int)tbNow.millitm, m_sep.c_str(), m_levels[level], m_sep.c_str(), tid, m_sep.c_str());

    if (m_printToScreen) {
        if (level >= LOG_INFO)
            printf("%s%s\n", title, msg);
        else
            fprintf(stderr, "%s%s\n", title, msg);
    }

    if (m_failed) {
        if (GetMonotonicTime() >= m_lastFailTime + 1.0) {
            m_failed = false;
            m_lastFailTime = 0.0;
        }
    }

    bool succ;
    if (m_failed) {
        succ = false;
    } else {
        succ = true;
        if (m_logFile == NULL) {
            succ = DoDivide();
        } else if (m_fileLen > m_maxFileLen || dayChanged) {
            Close();
            succ = DoDivide();
        }

        if (succ) {
            size_t logLineLen = titleLen + msgLen + 2;
            succ = ((int)logLineLen == fprintf(m_logFile, "%s%s\r\n", title, msg));
            m_fileLen += logLineLen;
        }

        if (succ)
            succ = (0 == fflush(m_logFile));

        if (!succ) {
            Close();

            m_failed = true;
            m_lastFailTime = GetMonotonicTime();
        }
    }

    ReleaseMutex(m_mutex);

    return succ;
}
Exemplo n.º 30
0
int32_t WelsGetTimeOfDay(SWelsTime * pTp)
{
	return _ftime_s(pTp);
}