summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaili Feng <bailif@codeaurora.org>2017-12-05 16:59:41 +0800
committerBaili Feng <bailif@codeaurora.org>2017-12-05 16:59:41 +0800
commitedcf00043593e125ccc798a70fb6ce2c9318444b (patch)
tree44558b815a31d53c55d02f006b8877f8a3b074c1
parent6ccaa83f60d0014b1c6414ef380a7d3a456a678b (diff)
downloadgps-edcf00043593e125ccc798a70fb6ce2c9318444b.tar.gz
Replace wall time
Replace gettimeofday with clock_gettime CRs-fixed: 2144315 Change-Id: Ie8472d2aedcd0e63b86cc5ff100ce9bb28fd670c
-rw-r--r--android/GnssDebug.cpp10
-rw-r--r--core/SystemStatus.h6
-rw-r--r--gnss/GnssAdapter.cpp12
-rw-r--r--utils/loc_log.cpp13
-rw-r--r--utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp9
-rw-r--r--utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h7
-rw-r--r--utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp7
-rw-r--r--utils/platform_lib_abstractions/loc_stub/src/loc_stub_time.cpp8
8 files changed, 34 insertions, 38 deletions
diff --git a/android/GnssDebug.cpp b/android/GnssDebug.cpp
index ff467d3..3d2b8bd 100644
--- a/android/GnssDebug.cpp
+++ b/android/GnssDebug.cpp
@@ -79,13 +79,11 @@ Return<void> GnssDebug::getDebugData(getDebugData_cb _hidl_cb)
data.position.bearingAccuracyDegrees =
reports.mLocation.bearingAccuracyDegrees;
- timeval tv_now, tv_report;
- tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec;
- tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL;
- gettimeofday(&tv_now, NULL);
+ struct timespec tv_now;
+ clock_gettime(CLOCK_MONOTONIC, &tv_now);
data.position.ageSeconds =
- (tv_now.tv_sec - tv_report.tv_sec) +
- (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000;
+ (tv_now.tv_sec - reports.mLocation.mUtcReported.tv_sec) +
+ (float)((tv_now.tv_nsec - reports.mLocation.mUtcReported.tv_nsec)) / 1000000000LL;
}
else {
data.position.valid = false;
diff --git a/core/SystemStatus.h b/core/SystemStatus.h
index 0c9b4b9..4f53c0b 100644
--- a/core/SystemStatus.h
+++ b/core/SystemStatus.h
@@ -70,10 +70,10 @@ public:
static const uint32_t maxItem = 5;
SystemStatusItemBase() {
- timeval tv;
- gettimeofday(&tv, NULL);
+ struct timespec tv;
+ clock_gettime(CLOCK_MONOTONIC, &tv);
mUtcTime.tv_sec = tv.tv_sec;
- mUtcTime.tv_nsec = tv.tv_usec *1000ULL;
+ mUtcTime.tv_nsec = tv.tv_nsec;
mUtcReported = mUtcTime;
};
virtual ~SystemStatusItemBase() { };
diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp
index 7e4c819..0dd773e 100644
--- a/gnss/GnssAdapter.cpp
+++ b/gnss/GnssAdapter.cpp
@@ -2268,9 +2268,9 @@ GnssAdapter::reportNmea(const char* nmea, size_t length)
GnssNmeaNotification nmeaNotification = {};
nmeaNotification.size = sizeof(GnssNmeaNotification);
- struct timeval tv;
- gettimeofday(&tv, (struct timezone *) NULL);
- int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000;
+ struct timespec tv;
+ clock_gettime(CLOCK_MONOTONIC, &tv);
+ int64_t now = tv.tv_sec * 1000LL + tv.tv_nsec / 1000000LL;
nmeaNotification.timestamp = now;
nmeaNotification.nmea = nmea;
nmeaNotification.length = length;
@@ -2317,14 +2317,14 @@ static void* niThreadProc(void *args)
NiSession* pSession = (NiSession*)args;
int rc = 0; /* return code from pthread calls */
- struct timeval present_time;
+ struct timespec present_time;
struct timespec expire_time;
pthread_mutex_lock(&pSession->tLock);
/* Calculate absolute expire time */
- gettimeofday(&present_time, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &present_time);
expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft;
- expire_time.tv_nsec = present_time.tv_usec * 1000;
+ expire_time.tv_nsec = present_time.tv_nsec;
LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec",
__func__, (long)expire_time.tv_sec, pSession->respTimeLeft);
diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp
index 9fad9e6..ca78f15 100644
--- a/utils/loc_log.cpp
+++ b/utils/loc_log.cpp
@@ -165,15 +165,15 @@ RETURN VALUE
===========================================================================*/
char *loc_get_time(char *time_string, size_t buf_size)
{
- struct timeval now; /* sec and usec */
+ struct timespec now; /* sec and usec */
struct tm now_tm; /* broken-down time */
char hms_string[80]; /* HH:MM:SS */
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &now);
localtime_r(&now.tv_sec, &now_tm);
strftime(hms_string, sizeof hms_string, "%H:%M:%S", &now_tm);
- snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_usec / 1000));
+ snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_nsec / 1000000LL));
return time_string;
}
@@ -224,14 +224,13 @@ SIDE EFFECTS
===========================================================================*/
char * get_timestamp(char *str, unsigned long buf_size)
{
- struct timeval tv;
- struct timezone tz;
+ struct timespec tv;
int hh, mm, ss;
- gettimeofday(&tv, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &tv);
hh = tv.tv_sec/3600%24;
mm = (tv.tv_sec%3600)/60;
ss = tv.tv_sec%60;
- snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec);
+ snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_nsec / 1000);
return str;
}
diff --git a/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp b/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp
index 6c183a8..4b35f51 100644
--- a/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp
+++ b/utils/platform_lib_abstractions/elapsed_millis_since_boot.cpp
@@ -28,14 +28,15 @@
#include <stdlib.h>
#include <sys/time.h>
+#include <time.h>
#include "platform_lib_time.h"
int64_t systemTime(int /*clock*/)
{
- struct timeval t;
- t.tv_sec = t.tv_usec = 0;
- gettimeofday(&t, NULL);
- return t.tv_sec*1000000LL + t.tv_usec;
+ struct timespec t;
+ t.tv_sec = t.tv_nsec = 0;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return t.tv_sec*1000000LL + t.tv_nsec/1000LL;
}
diff --git a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
index b896b94..39e33dc 100644
--- a/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
+++ b/utils/platform_lib_abstractions/loc_pla/include/platform_lib_macros.h
@@ -52,14 +52,13 @@ extern "C" {
// LE targets with no logcat support
#define TS_PRINTF(format, x...) \
{ \
- struct timeval tv; \
- struct timezone tz; \
+ struct timespec tv; \
int hh, mm, ss; \
- gettimeofday(&tv, &tz); \
+ clock_gettime(CLOCK_MONOTONIC, &tv); \
hh = tv.tv_sec/3600%24; \
mm = (tv.tv_sec%3600)/60; \
ss = tv.tv_sec%60; \
- fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec,##x); \
+ fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_nsec/1000, ##x); \
}
#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x)
diff --git a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
index 3cb51a3..fb4f2fe 100644
--- a/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
+++ b/utils/platform_lib_abstractions/loc_pla/src/platform_lib_log_util.cpp
@@ -30,14 +30,13 @@
char * get_timestamp(char *str, unsigned long buf_size)
{
- struct timeval tv;
- struct timezone tz;
+ struct timespec tv;
int hh, mm, ss;
- gettimeofday(&tv, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &tv);
hh = tv.tv_sec/3600%24;
mm = (tv.tv_sec%3600)/60;
ss = tv.tv_sec%60;
- snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec);
+ snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_nsec / 1000);
return str;
}
diff --git a/utils/platform_lib_abstractions/loc_stub/src/loc_stub_time.cpp b/utils/platform_lib_abstractions/loc_stub/src/loc_stub_time.cpp
index 48149a6..0db41ca 100644
--- a/utils/platform_lib_abstractions/loc_stub/src/loc_stub_time.cpp
+++ b/utils/platform_lib_abstractions/loc_stub/src/loc_stub_time.cpp
@@ -33,10 +33,10 @@
int64_t systemTime(int /*clock*/)
{
- struct timeval t;
- t.tv_sec = t.tv_usec = 0;
- gettimeofday(&t, NULL);
- return t.tv_sec*1000000LL + t.tv_usec;
+ struct timespec t;
+ t.tv_sec = t.tv_nsec = 0;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return t.tv_sec*1000000LL + t.tv_nsec/1000LL;
}
int64_t elapsedMicrosSinceBoot()