size
bytes with the low_level nit_alloc
C functionThis method can be redefined to inject statistic or tracing code.
tag
if any, is used to mark the class of the allocated object.
# Allocate `size` bytes with the low_level `nit_alloc` C function
#
# This method can be redefined to inject statistic or tracing code.
#
# `tag` if any, is used to mark the class of the allocated object.
fun nit_alloc(size: String, tag: nullable String): String
do
return "nit_alloc({size})"
end
src/compiler/abstract_compiler.nit:1377,2--1385,4
redef fun nit_alloc(size, tag)
do
if not compiler.modelbuilder.toolcontext.opt_trace_memory.value then return super
# Log time each 10ms (ie 1e7ns)
var tw = get_name("mtw")
add_decl("struct timespec {tw};")
add("clock_gettime(CLOCK_MONOTONIC, &{tw});")
add("if(mlog_last.tv_sec < {tw}.tv_sec || mlog_last.tv_nsec + 1e7 < {tw}.tv_nsec) \{")
add("mlog_last = {tw};")
add("fprintf(mlog, \"# %f\\n\", 1000.0*{tw}.tv_sec + 1e-6*{tw}.tv_nsec - (1000.0*mlog_time0.tv_sec + 1e-6*mlog_time0.tv_nsec));")
add("\}")
# Print size and tag the mlog
var str = "\"+\\t%d\\t%s\\n\", {size}, \"{tag or else "?"}\""
add("fprintf(mlog, {str});")
return super
end
src/compiler/memory_logger.nit:57,2--75,4