--- /dev/null
+#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 <lttng/tracepoint.h>
+
+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 <lttng/tracepoint-event.h>
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
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
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)
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
self.header.add_decl("#endif")
self.header.add_decl("#include <inttypes.h>\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 <TargetConditionals.h>")
self.header.add_decl(" #include <syslog.h>")
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}")