Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GetTickCount() include time spent suspended or hibernated?

Tags:

winapi

To clarify, I mean time spent while the system is suspended/hibernated, not the calling thread (GetTickCount() returns the number of milliseconds since system boot).

like image 251
Peter Baer Avatar asked Feb 04 '09 20:02

Peter Baer


People also ask

How accurate is GetTickCount?

The GetTickCount function has a precision of one millisecond, but its accuracy is typically much worse, dependent on your timer tick rate, typically 10ms to 55ms.

What is tick count in Windows?

GetTickCount function (sysinfoapi. h) - Win32 apps. Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.


4 Answers

As far as I know, GetTickCount is unrelated to threads and counts the time since the system has started. But it is better to use GetTickCount64 to avoid the 49.7 day roleover.

By the way, to get what you want you need the GetThreadTimes function. It records the creation and exit time and the amount of time the thread has spend in user or kernel space. So you have a nice way to calculate the amount of time spend.

Ok, I missed the "system" part of the question. But that is simple. When in hibernation GetTickCount continues the counting. Because people have suffered from the 49.7 days bug when the computer was in hibernate most of the time. See link text here for more information.

like image 147
Toon Krijthe Avatar answered Sep 23 '22 01:09

Toon Krijthe


Short answer : Yes.

Longer answer: Read the GetTickCount() docs: It's the elapsed time since system startup, and even MS wouldn't suggest that time stands still while your computer is hibernating...

like image 38
Roddy Avatar answered Sep 27 '22 01:09

Roddy


Yes, GetTickCount does include suspend/hibernate time.

In the following python script I call the Sleep API to wait 40 seconds to give me a chance to put the computer into hibernate mode, and I print the time before and after, and the tick count difference after.

import win32api
import time
print time.strftime("%H:%M:%S", time.localtime())
before = win32api.GetTickCount()
print "sleep"
win32api.Sleep(40000)
print time.strftime("%H:%M:%S", time.localtime())
print str(win32api.GetTickCount()-before)

Output:

17:44:08
sleep
17:51:30
442297

If GetTickCount did not include the time during hibernate it would be much less than the time I hibernated for, but it matches the actual time elapsed (7 minutes 22 seconds equals 442 seconds, i.e. 442000 millisecond "ticks").

like image 27
Ben Bryant Avatar answered Sep 25 '22 01:09

Ben Bryant


For any one looking for answer under Windows CE platform, from docs:

http://msdn.microsoft.com/en-us/library/ms885645.aspx

you can read:

For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at 0 on boot and then counts up from there.

like image 40
marcinj Avatar answered Sep 27 '22 01:09

marcinj