Time tracking through machine sleep
Time tracking through machine sleep
- Subject: Time tracking through machine sleep
- From: Mark Hanks <email@hidden>
- Date: Wed, 15 Oct 2008 14:00:31 -0600
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