Merge "Replace wall time"

This commit is contained in:
Linux Build Service Account 2017-12-25 08:03:44 -08:00 committed by Gerrit - the friendly Code Review server
commit d519abf0c1
8 changed files with 34 additions and 38 deletions

View file

@ -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;

View file

@ -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() { };

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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)

View file

@ -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;
}

View file

@ -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()