GetTimeInMicrosenconds

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

GetTimeInMicrosenconds

Postby Slick » Thu May 29, 2014 5:32 pm

I am plugging away to try and get something working on Android. It appears that the GetTimeInMicrosenconds function is returning the same value at different times when I step through code. For example I am getting 6505792571925594113 returned from different calls. Any ideas on what might be happening?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: GetTimeInMicrosenconds

Postby Slick » Thu May 29, 2014 5:51 pm

Hmm I was just looking at the source and dNewton::ResetTimer() and dNewton::GetTimeInMicrosenconds() are ifdef'd out if _MSC_VER is not defined.

It looks like that might be why there is a problem if not on a windows build?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: GetTimeInMicrosenconds

Postby Julio Jerez » Fri May 30, 2014 1:27 pm

do you mean this function
Code: Select all
dLong dNewton::GetTimeInMicrosenconds() const
{
   #ifdef _MSC_VER
      LARGE_INTEGER count;
      QueryPerformanceCounter (&count);
      count.QuadPart -= m_baseCount;
      dLong ticks = count.QuadPart * LONGLONG (1000000) / m_frequency;
      return ticks;
   #endif
/*
   #if (defined (_POSIX_VER) || defined (_POSIX_VER_64))
      timespec ts;
      clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux
      //return unsigned64 (ts.tv_nsec / 1000) - baseCount;
      
      return unsigned64 (ts.tv_sec) * 1000000 + ts.tv_nsec / 1000 - baseCount;
   #endif


   #ifdef _MACOSX_VER
      timeval tp;
      gettimeofday(&tp, NULL);
      unsigned64 microsecunds =  unsigned64 (tp.tv_sec) * 1000000 + tp.tv_usec;
      return microsecunds - baseCount;
   #endif
*/
}


I think all you need to do is comment the other parts, that function is identical to thsi one which has being test on other platforms.
Code: Select all
unsigned64 dGetTimeInMicrosenconds()
{
#ifdef _MSC_VER
      LARGE_INTEGER count;
      QueryPerformanceCounter (&count);
      count.QuadPart -= baseCount.QuadPart;
      unsigned64 ticks = unsigned64 (count.QuadPart * LONGLONG (1000000) / frequency.QuadPart);
      return ticks;

   #endif

   #if (defined (_POSIX_VER) || defined (_POSIX_VER_64))
      timespec ts;
      clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux
      //return unsigned64 (ts.tv_nsec / 1000) - baseCount;
      
      return unsigned64 (ts.tv_sec) * 1000000 + ts.tv_nsec / 1000 - baseCount;
   #endif


   #ifdef _MACOSX_VER
      timeval tp;
      gettimeofday(&tp, NULL);
      unsigned64 microsecunds =  unsigned64 (tp.tv_sec) * 1000000 + tp.tv_usec;
      return microsecunds - baseCount;
   #endif
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: GetTimeInMicrosenconds

Postby Slick » Fri May 30, 2014 3:41 pm

Yes that is the function. Thanks for the other link. From googling I had already got it working I think.

I have another problem that I will post in a separate thread.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Re: GetTimeInMicrosenconds

Postby arkeon » Fri Apr 24, 2015 4:52 am

Hi

I ran into the same probleme.

using gcc with android NDK _POSIX_VER is not even recognized when I uncomment it
an include or something must be missing

Code: Select all
[ 88%] Building CXX object packages/CMakeFiles/dNewton.dir/dNewton/dNewton.cpp.o
D:\dev\scol-technologies\trunk\dependencies\newton-dynamics\packages\dNewton\dNewton.cpp: In member function 'long long int dNewton::GetTimeInMicrosenconds() const':
D:\dev\scol-technologies\trunk\dependencies\newton-dynamics\packages\dNewton\dNewton.cpp:271:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: GetTimeInMicrosenconds

Postby Julio Jerez » Fri Apr 24, 2015 11:07 am

what define is this NDK _POSIX_VER ?
newton does not has that. you have to use _POSIX_VER or _POSIX_VER_64
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: GetTimeInMicrosenconds

Postby arkeon » Fri Apr 24, 2015 3:09 pm

this is not only the problem.

yes a #ifdef ANDROID_NDK could work but why other part of this code have been commented ?
what code should I use for android ?

note there is also errors on some "dlong (..)" should be replaced by "(dlong)(...)"
I don't remember where exactly.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron