Skip to content

Commit

Permalink
lj_auditlog: Add "event" object
Browse files Browse the repository at this point in the history
Log both "events" (new) and "memory" (already had this.)

The "event" and "memory" log messages are complementary. First we log
objects in memory, as detailed context, and then we log events, which
can refer to those objects.

For example, when a trace stops (i.e. is successfully recorded and
assembled), then we first log the GCtrace object in memory:

    {
        "type": "memory",
        "hint": "GCtrace",
        "address": 139883362546248,
        "data": <bin of size 120>
    }

and then later we log a "trace_stop" event that refers to this memory:

    {
        "type": "event",
        "event": "trace_stop",
        "GCtrace": 139883362546248
    }

So the "memory" messages are effectively providing context for later
"events".
  • Loading branch information
lukego committed May 24, 2017
1 parent 76be283 commit b302c6e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/lj_auditlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ static void bin_32(void *ptr, int n) {
/* -- low-level object logging API ---------------------------------------- */

/* Ensure that the log file is open. */
static void ensure_log_open()
{
static void ensure_log_open() {
if (!fp) {
fp = fopen("audit.log", "w");
lua_assert(fp != NULL);
}
}

/* Log a snapshot of an object in memory. */
static void log(const char *type, void *ptr, unsigned int size)
{
static void log_mem(const char *type, void *ptr, unsigned int size) {
ensure_log_open();
fixmap(4);
str_16("type"); /* = */ str_16("memory");
Expand All @@ -61,16 +59,24 @@ static void log(const char *type, void *ptr, unsigned int size)
str_16("data"); /* = */ bin_32(ptr, 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);
/* Caller fills in the further nattributes... */
}

/* -- high-level LuaJIT object logging ------------------------------------ */

/* Log a trace that has just been compiled. */
void lj_auditlog_trace_stop(jit_State *J, GCtrace *T)
{
/* Log the memory containing the GCtrace object and other important
memory that it references. */
log("GCtrace", T, sizeof(*T));
log("MCode[]", T->mcode, T->szmcode);
log("SnapShot[]", T->snap, T->nsnap * sizeof(*T->snap));
log("SnapEntry[]", T->snapmap, T->nsnapmap * sizeof(*T->snapmap));
log_mem("GCtrace", T, sizeof(*T));
log_mem("MCode[]", T->mcode, T->szmcode);
log_mem("SnapShot[]", T->snap, T->nsnap * sizeof(*T->snap));
log_mem("SnapEntry[]", T->snapmap, T->nsnapmap * sizeof(*T->snapmap));
log_event("trace_stop", 1);
str_16("GCtrace"); /* = */ uint_64((uint64_t)T);
}

0 comments on commit b302c6e

Please sign in to comment.