According to Android Developer Reference uptimeMillis()
returns the number of milliseconds since boot, not counting time spent in deep sleep. I checked the implementation of
uptimeMillis()
in my code and it is roughly like this-
struct timespec t;
t.tv_sec = t.tv_nsec = 0;
clock_gettime(CLOCK_MONOTONIC, &t);
return (int64_t)(t.tv_sec)*1000000000LL + t.tv_nsec;
As far as I know CLOCK_MONOTONIC
counts from some unspecified point linearly including sleep time.
Here are my doubts-
If
CLOCK_MONOTONIC
includes sleep time, how comeuptimeMillis()
doesn't take it into account? If my understanding is wrong andCLOCK_MONOTONIC
doesn't take sleep into account, then what should I use to get system uptime including sleep?What is deep sleep? Is the CPU idling referred as deep sleep?
What is the value of unspecified point in Linux? Can you kindly point out in code where this clock is started?