diff options
author | Baili Feng <bailif@codeaurora.org> | 2017-12-05 16:59:41 +0800 |
---|---|---|
committer | Baili Feng <bailif@codeaurora.org> | 2017-12-05 16:59:41 +0800 |
commit | edcf00043593e125ccc798a70fb6ce2c9318444b (patch) | |
tree | 44558b815a31d53c55d02f006b8877f8a3b074c1 /utils/loc_log.cpp | |
parent | 6ccaa83f60d0014b1c6414ef380a7d3a456a678b (diff) | |
download | gps-edcf00043593e125ccc798a70fb6ce2c9318444b.tar.gz |
Replace wall time
Replace gettimeofday with clock_gettime
CRs-fixed: 2144315
Change-Id: Ie8472d2aedcd0e63b86cc5ff100ce9bb28fd670c
Diffstat (limited to 'utils/loc_log.cpp')
-rw-r--r-- | utils/loc_log.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
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; } |