summaryrefslogtreecommitdiffstats
path: root/logd/LogBuffer.h
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-12-28 15:33:01 -0800
committerMark Salyzyn <salyzyn@google.com>2015-12-29 11:34:29 -0800
commit10b82b683405e9ccd0cc162fa44a2ec6a9f26448 (patch)
treeb0e78abff45b56ca1c0611973d6aab7ac4b4c8a9 /logd/LogBuffer.h
parentb5e821316da31d2f4d06c3dea74ed57098b69033 (diff)
downloadsystem_core-10b82b683405e9ccd0cc162fa44a2ec6a9f26448.tar.gz
system_core-10b82b683405e9ccd0cc162fa44a2ec6a9f26448.tar.bz2
system_core-10b82b683405e9ccd0cc162fa44a2ec6a9f26448.zip
logd: isMonotonic improvements
Use 1972 as a right delineation. Otherwise use half way point between the monotonic and realtime. Treat correction factor as unsigned, ensure that any wrapping to a negative value is dropped or set to EPOCH. Acknowledge that we can get a more accurate time track by acquiring the time rather than relying on healthd timestamp. Bug: 26331432 Change-Id: I09075fca58676a30cf7d87baf2d4b0f53795abaa
Diffstat (limited to 'logd/LogBuffer.h')
-rw-r--r--logd/LogBuffer.h36
1 files changed, 31 insertions, 5 deletions
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 0243749f9..2667e7828 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -33,16 +33,42 @@
#include "LogWhiteBlackList.h"
//
-// We are either in 1970ish (MONOTONIC) or 2015+ish (REALTIME) so to
-// differentiate without prejudice, we use 1980 to delineate, earlier
-// is monotonic, later is real.
+// We are either in 1970ish (MONOTONIC) or 2016+ish (REALTIME) so to
+// differentiate without prejudice, we use 1972 to delineate, earlier
+// is likely monotonic, later is real. Otherwise we start using a
+// dividing line between monotonic and realtime if more than a minute
+// difference between them.
//
namespace android {
static bool isMonotonic(const log_time &mono) {
- static const uint32_t EPOCH_PLUS_10_YEARS = 10 * 1461 / 4 * 24 * 60 * 60;
+ static const uint32_t EPOCH_PLUS_2_YEARS = 2 * 24 * 60 * 60 * 1461 / 4;
+ static const uint32_t EPOCH_PLUS_MINUTE = 60;
- return mono.tv_sec < EPOCH_PLUS_10_YEARS;
+ if (mono.tv_sec >= EPOCH_PLUS_2_YEARS) {
+ return false;
+ }
+
+ log_time now(CLOCK_REALTIME);
+
+ /* Timezone and ntp time setup? */
+ if (now.tv_sec >= EPOCH_PLUS_2_YEARS) {
+ return true;
+ }
+
+ /* no way to differentiate realtime from monotonic time */
+ if (now.tv_sec < EPOCH_PLUS_MINUTE) {
+ return false;
+ }
+
+ log_time cpu(CLOCK_MONOTONIC);
+ /* too close to call to differentiate monotonic times from realtime */
+ if ((cpu.tv_sec + EPOCH_PLUS_MINUTE) >= now.tv_sec) {
+ return false;
+ }
+
+ /* dividing line half way between monotonic and realtime */
+ return mono.tv_sec < ((cpu.tv_sec + now.tv_sec) / 2);
}
}