From: olivierschirm Date: Wed, 9 May 2018 20:09:22 +0000 (-0400) Subject: add the trace system with a first test which is instance tracing X-Git-Url: http://nitlanguage.org add the trace system with a first test which is instance tracing Signed-off-by: olivierschirm --- diff --git a/clib/traces.c b/clib/traces.c new file mode 100644 index 0000000..4b01642 --- /dev/null +++ b/clib/traces.c @@ -0,0 +1,4 @@ +#define TRACEPOINT_CREATE_PROBES +#define TRACEPOINT_DEFINE + +#include "traces.h" diff --git a/clib/traces.h b/clib/traces.h new file mode 100644 index 0000000..1b88f68 --- /dev/null +++ b/clib/traces.h @@ -0,0 +1,27 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER Nit_Compiler + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./traces.h" + +#if !defined(_TRACES_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACES_H + +#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) + ) +) + +#endif + +#include diff --git a/share/man/nitc.md b/share/man/nitc.md index 243c83a..d29a131 100644 --- a/share/man/nitc.md +++ b/share/man/nitc.md @@ -246,6 +246,11 @@ Also preserves the source-files directory for C-debuggers. 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. + ## COMPILATION MODES ### `nitc` includes distinct compilation modes. diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index ea4adde..cff93bd 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -75,6 +75,8 @@ redef class ToolContext var opt_release = new OptionBool("Compile in release mode and finalize application", "--release") # -g var opt_debug = new OptionBool("Compile in debug mode (no C-side optimization)", "-g", "--debug") + # --trace + var opt_trace = new OptionBool("Compile with lttng's instrumentation", "--trace") redef init do @@ -87,6 +89,7 @@ redef class ToolContext self.option_context.add_option(self.opt_release) self.option_context.add_option(self.opt_max_c_lines, self.opt_group_c_files) self.option_context.add_option(self.opt_debug) + self.option_context.add_option(self.opt_trace) opt_no_main.hidden = true end @@ -233,6 +236,16 @@ class MakefileToolchain compiler.files_to_copy.add "{clib}/gc_chooser.c" compiler.files_to_copy.add "{clib}/gc_chooser.h" + # Add lttng traces provider to external bodies + if toolcontext.opt_trace.value then + #-I. is there in order to make the TRACEPOINT_INCLUDE directive in clib/traces.h refer to the directory in which gcc was invoked. + var traces = new ExternCFile("traces.c", "-I.") + traces.pkgconfigs.add "lttng-ust" + compiler.extern_bodies.add(traces) + compiler.files_to_copy.add "{clib}/traces.c" + compiler.files_to_copy.add "{clib}/traces.h" + end + # FFI for m in compiler.mainmodule.in_importation.greaters do compiler.finalize_ffi_for_module(m) @@ -376,6 +389,8 @@ LDFLAGS ?= LDLIBS ?= -lm {{{linker_options.join(" ")}}} \n""" + if self.toolcontext.opt_trace.value then makefile.write "LDLIBS += -llttng-ust -ldl\n" + makefile.write "\n# SPECIAL CONFIGURATION FLAGS\n" if platform.supports_libunwind then if toolcontext.opt_no_stacktrace.value then @@ -706,6 +721,7 @@ abstract class AbstractCompiler self.header.add_decl("#endif") self.header.add_decl("#include \n") self.header.add_decl("#include \"gc_chooser.h\"") + if modelbuilder.toolcontext.opt_trace.value then self.header.add_decl("#include \"traces.h\"") self.header.add_decl("#ifdef __APPLE__") self.header.add_decl(" #include ") self.header.add_decl(" #include ") diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index 8fd3f61..a587c59 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -982,6 +982,7 @@ 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);") v.add("{res}->type = type;") hardening_live_type(v, "type") v.require_declaration("class_{c_name}")