• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Time tracking through machine sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Time tracking through machine sleep


  • Subject: Re: Time tracking through machine sleep
  • From: Dave Zarzycki <email@hidden>
  • Date: Wed, 15 Oct 2008 13:07:38 -0700

Mark,

gettimeofday() is what you want. There are also timeradd() and timersub () macros for computing deltas.

davez


On Oct 15, 2008, at 1:00 PM, Mark Hanks wrote:

I am looking for a function that behaves like the Win32 GetTickCount function. I have tried mach_absolute_time , Microseconds and UpTime but they all have the same problem, they don't increment while the machine is asleep.

Here is some code for a CoreServices tool that shows the issue.

#include <CoreServices/CoreServices.h>

#include <mach/mach_time.h>

#include <unistd.h>


int main (int argc, const char * argv[])
{
kern_return_t err;
mach_timebase_info_data_t info;
uint32_t millis, seconds;
char outputStr[64];

if ((err = mach_timebase_info(&info)) != KERN_SUCCESS)
{
return 1;
}

while (TRUE)
{
millis = (uint32_t)((mach_absolute_time() * (uint64_t)info.numer / (uint64_t)info.denom) / 1000000);
seconds = millis / 1000;
sprintf(outputStr, "millis = %u; seconds = %u\n", millis, seconds);
fprintf(stdout, outputStr);
fflush(stdout);

sleep(2);
}

return 0;
}



If you run in Terminal you get output that looks like this:

millis = 13528873;    seconds = 13528
millis = 13530874;    seconds = 13530
millis = 13532874;    seconds = 13532
millis = 13534874;    seconds = 13534
millis = 13536874;    seconds = 13536
millis = 13538875;    seconds = 13538
millis = 13540875;    seconds = 13540
millis = 13542875;    seconds = 13542


While it is running put the Mac to sleep, wait a while and then wake it up and you will see no gap in the times reported.


Does anyone know of a timing call that will account for time the machine has been asleep?

Thanks,
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Time tracking through machine sleep
      • From: Brian Mastenbrook <email@hidden>
References: 
 >Time tracking through machine sleep (From: Mark Hanks <email@hidden>)

  • Prev by Date: Time tracking through machine sleep
  • Next by Date: Re: Time tracking through machine sleep
  • Previous by thread: Time tracking through machine sleep
  • Next by thread: Re: Time tracking through machine sleep
  • Index(es):
    • Date
    • Thread