Set default timestamp to elapsedRealtimeNanos
Test: m -j libstatssocket compiles
Change-Id: I62f4c6bb14c3914124a6af25ff46fb0a980204e7
diff --git a/libstats/stats_event.c b/libstats/stats_event.c
index e2f247a..5bccd9b 100644
--- a/libstats/stats_event.c
+++ b/libstats/stats_event.c
@@ -17,6 +17,7 @@
#include "stats_event.h"
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include "include/stats_event_list.h"
#define byte unsigned char
@@ -66,6 +67,13 @@
uint32_t tag;
};
+static int64_t get_elapsed_realtime_ns() {
+ struct timespec t;
+ t.tv_sec = t.tv_nsec = 0;
+ clock_gettime(CLOCK_BOOTTIME, &t);
+ return (int64_t)t.tv_sec * 1000000000LL + t.tv_nsec;
+}
+
struct stats_event* stats_event_obtain() {
struct stats_event* event = malloc(sizeof(struct stats_event));
@@ -77,7 +85,7 @@
event->size = 0;
event->numElements = 0;
event->atomId = 0;
- event->timestampNs = 0;
+ event->timestampNs = get_elapsed_realtime_ns();
event->errors = 0;
event->tag = STATS_EVENT_TAG;
return event;
@@ -87,6 +95,7 @@
free(event); // free is a no-op if event is NULL
}
+// Should only be used for testing
void stats_event_set_timestamp_ns(struct stats_event* event, uint64_t timestampNs) {
if (event) event->timestampNs = timestampNs;
}