From ebfab599fa659cdef1b27ac6c7b3b827e721db67 Mon Sep 17 00:00:00 2001 From: olivierschirm Date: Thu, 17 May 2018 09:14:24 -0400 Subject: [PATCH] add destruction traces, add lttng channel configuration file, resolve the signed pointer issue by using uintptr_t instead of intptr_t. add some infomations in nitc man page Signed-off-by: olivierschirm --- clib/gc_chooser.h | 1 + clib/traces.c | 6 +++- clib/traces.h | 34 ++++++++++++------ misc/Nit_Compiler.lttng | 69 ++++++++++++++++++++++++++++++++++++ share/man/nitc.md | 20 ++++++++++- src/compiler/separate_compiler.nit | 5 ++- 6 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 misc/Nit_Compiler.lttng diff --git a/clib/gc_chooser.h b/clib/gc_chooser.h index 255e07a..882d310 100644 --- a/clib/gc_chooser.h +++ b/clib/gc_chooser.h @@ -22,5 +22,6 @@ void initialize_gc_option(void); /* Select the wanted GC using envvar `NIT_GC_OP void gc_register_finalizer(void*); /* Tag a pointer for finalization */ void gc_finalize(void*, void*); /* Finalize a pointer, implemented in the generated code. */ +void object_destroy_callback(void*, void*); /* call into an object finalizer to record some traces. */ #endif diff --git a/clib/traces.c b/clib/traces.c index 4b01642..9e3c3ad 100644 --- a/clib/traces.c +++ b/clib/traces.c @@ -1,4 +1,8 @@ #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE -#include "traces.h" +#include "nit.common.h" + +void object_destroy_callback(void *obj, void *cd){ + tracepoint(Nit_Compiler, Object_Destroy, (char*)((val*)(obj))->type->name, (uintptr_t)obj); +} diff --git a/clib/traces.h b/clib/traces.h index 1b88f68..b34af65 100644 --- a/clib/traces.h +++ b/clib/traces.h @@ -8,18 +8,32 @@ #define _TRACES_H #include +#include TRACEPOINT_EVENT( - Nit_Compiler, - Object_Instance, - TP_ARGS( - char*, object_class_arg, - int, object_id_arg - ), - TP_FIELDS( - ctf_string(object_class, object_class_arg) - ctf_integer(int, object_id, object_id_arg) - ) + Nit_Compiler, + Object_Instance, + TP_ARGS( + char*, object_class_arg, + int, object_id_arg + ), + TP_FIELDS( + ctf_string(object_class, object_class_arg) + ctf_integer(int, object_id, object_id_arg) + ) +) + +TRACEPOINT_EVENT( + Nit_Compiler, + Object_Destroy, + TP_ARGS( + char*, object_class_arg, + int, object_id_arg + ), + TP_FIELDS( + ctf_string(object_class, object_class_arg) + ctf_integer(int, object_id, object_id_arg) + ) ) #endif diff --git a/misc/Nit_Compiler.lttng b/misc/Nit_Compiler.lttng new file mode 100644 index 0000000..b21d50a --- /dev/null +++ b/misc/Nit_Compiler.lttng @@ -0,0 +1,69 @@ + + + + Nit_Compiler + + + UST + PER_UID + + + blocking-channel + true + DISCARD + 524288 + 4 + 0 + 0 + MMAP + 0 + 1000000 + 0 + 0 + 0 + + + Nit_Compiler:Object_Instance + true + TRACEPOINT + ALL + + + Nit_Compiler:Object_Destroy + true + TRACEPOINT + ALL + + + + + + + + + JUL + PER_UID + + + + LOG4J + PER_UID + + + + PYTHON + PER_UID + + + + false + + + true + + Put your path here ! + + + + + diff --git a/share/man/nitc.md b/share/man/nitc.md index d29a131..eff6232 100644 --- a/share/man/nitc.md +++ b/share/man/nitc.md @@ -249,7 +249,25 @@ For more debugging-related options, see also `--hardening` and `NIT_GC_OPTION` ### `--trace` Compile with lttng's instrumentation. -Currently add a lttng trace provider and add tracepoint into object instances. +Currently add a lttng trace provider and add tracepoint into object instances and destructions. + +The lttng nit/misc/Nit_Compiler.lttng file is a template that you can use instead of configure channels by yourself. You have to configure the path of the destination tracefile. "your path" + +To create a channel with template : + lttng-sessiond --daemonize + lttng load -i=~/nit/misc/Nit_Compiler.lttng Nit_Compiler +To create a channel without template : + lttng create session_name + lttng enable-event --userspace Nit_Compiler:Object_Instance + lttng enable-event --userspace Nit_Compiler:Object_Destroy +To record some traces : + lttng start + --> run your program + lttng stop +To read some traces : + babeltrace ~/session_name +To destroy your current tracing session : + lttng destroy ## COMPILATION MODES diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index a587c59..15b6f05 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -982,7 +982,10 @@ class SeparateCompiler var alloc = v.nit_alloc("sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t)", mclass.full_name) v.add("{res} = {alloc};") end - if modelbuilder.toolcontext.opt_trace.value then v.add("tracepoint(Nit_Compiler, Object_Instance,\"{mtype}\", (intptr_t)self);") + if modelbuilder.toolcontext.opt_trace.value then + v.add("tracepoint(Nit_Compiler, Object_Instance,\"{mtype}\", (uintptr_t)self);") + v.add("GC_register_finalizer(self, object_destroy_callback, NULL, NULL, NULL);") + end v.add("{res}->type = type;") hardening_live_type(v, "type") v.require_declaration("class_{c_name}") -- 1.7.9.5