Skip to content

Commit

Permalink
lj_auditlog.c: Add "nanotime" timestamp to events
Browse files Browse the repository at this point in the history
Timestamps are based on CLOCK_MONOTONIC i.e. suitable for calculating
the time delta from one event to the next.
  • Loading branch information
lukego committed Mar 29, 2018
1 parent d0dcc75 commit b0cbca7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lj_auditlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define lj_auditlog_c

#include <stdio.h>
#include <time.h>

#include "lj_trace.h"
#include "lj_auditlog.h"
Expand Down Expand Up @@ -78,10 +79,13 @@ static void log_mem(const char *type, void *ptr, unsigned int size) {
}

static void log_event(const char *type, int nattributes) {
lua_assert(nattributes <= 253);
fixmap(nattributes+2);
str_16("type"); /* = */ str_16("event");
str_16("event"); /* = */ str_16(type);
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
lua_assert(nattributes <= 252);
fixmap(nattributes+3);
str_16("nanotime"); /* = */ uint_64(ts.tv_sec * 1000000000LL + ts.tv_nsec);
str_16("type"); /* = */ str_16("event");
str_16("event"); /* = */ str_16(type);
/* Caller fills in the further nattributes... */
}

Expand Down

0 comments on commit b0cbca7

Please sign in to comment.