diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index ef8c41d..880e128 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -756,7 +756,14 @@ internal class Vala.CCodeMethodModule : CCodeStructModule { var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init")); thread_init_call.line = cmain.line; thread_init_call.add_argument (new CCodeConstant ("NULL")); - main_block.add_statement (new CCodeExpressionStatement (thread_init_call)); + main_block.add_statement (new CCodeExpressionStatement (thread_init_call)); + } + + if (context.mem_profile) { + var mem_profile_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable")); + mem_profile_init_call.line = cmain.line; + mem_profile_init_call.add_argument (new CCodeConstant ("glib_mem_profiler_table")); + main_block.add_statement (new CCodeExpressionStatement (mem_profile_init_call)); } var type_init_call = new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init"))); diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index bddaa1f..6b9f81f 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -55,6 +55,7 @@ class Vala.Compiler { static string output; static bool debug; static bool thread; + static bool mem_profile; static bool disable_assert; static bool enable_checking; static bool deprecated; @@ -100,6 +101,7 @@ class Vala.Compiler { { "output", 'o', 0, OptionArg.FILENAME, ref output, "Place output in file FILE", "FILE" }, { "debug", 'g', 0, OptionArg.NONE, ref debug, "Produce debug information", null }, { "thread", 0, 0, OptionArg.NONE, ref thread, "Enable multithreading support", null }, + { "mem_profile", 0, 0, OptionArg.NONE, ref mem_profile, "Enable GLib Memory statistics support", null }, { "define", 'D', 0, OptionArg.STRING_ARRAY, ref defines, "Define SYMBOL", "SYMBOL..." }, { "main", 0, 0, OptionArg.STRING, ref entry_point, "Use SYMBOL as entry point", "SYMBOL..." }, { "disable-assert", 0, 0, OptionArg.NONE, ref disable_assert, "Disable assertions", null }, @@ -235,6 +237,7 @@ class Vala.Compiler { } context.debug = debug; context.thread = thread; + context.mem_profile = mem_profile; context.save_temps = save_temps; if (profile == "posix") { context.profile = Profile.POSIX; diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index e9e694d..9812ab4 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -119,6 +119,11 @@ public class Vala.CodeContext { public bool thread { get; set; } /** + * Enable g_mem_profile support. + */ + public bool mem_profile { get; set; } + + /** * Specifies the optional module initialization method. */ public Method module_init_method { get; set; }