[m-rev.] diff: Move sbrk profiling code.
Paul Bone
paul at bone.id.au
Sun Nov 11 11:01:43 AEDT 2012
Move the sbrk profiling code into the mercury_main() function.
The mercury_main() function is used in both standalone and library builds of
Mercury code. However the main function where the code was was only used in
standalone programs. The Mercury compiler is built as a library and
usually liked with main.c in the root directory, this is done so that it can
be used with GCC for the GCC backend. I have moved the sbrk profiling code
into mercury_main so that it will be executed by the compiler. I used this
to generate memory usage information in my thesis.
util/mkinit.c:
As above.
diff --git a/util/mkinit.c b/util/mkinit.c
index 5a46199..1dd8217 100644
--- a/util/mkinit.c
+++ b/util/mkinit.c
@@ -527,6 +527,14 @@ static const char mercury_main_func[] =
"int\n"
"mercury_main(int argc, char **argv)\n"
"{\n"
+ "#ifdef MR_PROFILE_SBRK\n"
+ " void* old_break;\n"
+ " void* new_break;\n"
+ "#endif\n"
+ " int result;\n"
+ "#ifdef MR_PROFILE_SBRK\n"
+ " old_break = sbrk(0);\n"
+ "#endif\n"
/*
** Note that the address we use for the stack base
** needs to be word-aligned (the MPS GC requires this).
@@ -536,7 +544,13 @@ static const char mercury_main_func[] =
" void *dummy;\n"
" mercury_init(argc, argv, &dummy);\n"
" mercury_call_main();\n"
- " return mercury_terminate();\n"
+ " result = mercury_terminate();\n"
+ "#ifdef MR_PROFILE_SBRK\n"
+ " new_break = sbrk(0);\n"
+ " printf(\"sbrk delta: %d\\n\",\n"
+ " (MR_Integer)new_break - (MR_Integer)old_break);\n"
+ "#endif\n"
+ " return result;\n"
"}\n"
"\n"
/*
@@ -617,24 +631,10 @@ static const char main_func[] =
"int\n"
"main(int argc, char **argv)\n"
"{\n"
- "#ifdef MR_PROFILE_SBRK\n"
- " void* old_break;\n"
- " void* new_break;\n"
- "#endif\n"
- " int result;\n"
- "#ifdef MR_PROFILE_SBRK\n"
- " old_break = sbrk(0);\n"
- "#endif\n"
"#ifdef MR_MINGW\n"
" mercury_win32_args(&argc, &argv);\n"
"#endif\n"
- " result = mercury_main(argc, argv);\n"
- "#ifdef MR_PROFILE_SBRK\n"
- " new_break = sbrk(0);\n"
- " printf(\"sbrk delta: %d\\n\",\n"
- " (MR_Integer)new_break - (MR_Integer)old_break);\n"
- "#endif\n"
- " return result;\n"
+ " return mercury_main(argc, argv);\n"
"}\n"
"#endif\n"
;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20121111/8214015b/attachment.sig>
More information about the reviews
mailing list