Skip to content

Commit

Permalink
Add lj_auditlog (very preliminary)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed May 21, 2017
1 parent ca49220 commit cb132d1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
lj_asm.o lj_trace.o lj_gdbjit.o \
lj_asm.o lj_trace.o lj_gdbjit.o lj_auditlog.o \
lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
lj_carith.o lj_clib.o lj_cparse.o \
lj_lib.o lj_alloc.o lib_aux.o \
Expand Down
40 changes: 40 additions & 0 deletions src/lj_auditlog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
** Audit log. Records JIT/runtime events for offline analysis.
*/

#define lj_auditlog_c

#include <stdio.h>

#include "lj_auditlog.h"

FILE *fp;

/* Ensure that the log file is 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)
{
ensure_log_open();
fprintf(fp, "type=%s address=%p size=%d data:\n", type, ptr, size);
fwrite(ptr, size, 1, fp);
}

/* 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));
}

16 changes: 16 additions & 0 deletions src/lj_auditlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
** Audit log. Records JIT/runtime events for offline analysis.
*/

#ifndef _LJ_AUDITLOG_H
#define _LJ_AUDITLOG_H

#include "lj_jit.h"

void lj_auditlog_trace_flush(jit_State *J);
void lj_auditlog_trace_start(jit_State *J);
void lj_auditlog_trace_stop(jit_State *J, GCtrace *T);
void lj_auditlog_trace_abort(jit_State *J);
void lj_auditlog_trace_record_bytecode(jit_State *J);

#endif
3 changes: 3 additions & 0 deletions src/lj_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lj_obj.h"


#include "lj_auditlog.h"
#include "lj_gc.h"
#include "lj_err.h"
#include "lj_debug.h"
Expand All @@ -28,6 +29,7 @@
#include "lj_dispatch.h"
#include "lj_vm.h"
#include "lj_target.h"
#include "lj_auditlog.h"

/* -- Error handling ------------------------------------------------------ */

Expand Down Expand Up @@ -122,6 +124,7 @@ static void trace_save(jit_State *J, GCtrace *T)
setgcrefp(J->trace[T->traceno], T);
lj_gc_barriertrace(J2G(J), T->traceno);
lj_gdbjit_addtrace(J, T);
lj_auditlog_trace_stop(J, T);
}

void lj_trace_free(global_State *g, GCtrace *T)
Expand Down

0 comments on commit cb132d1

Please sign in to comment.