[m-dev.] diff: improve memory profiling
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Sep 24 16:19:55 AEST 1999
Here's another diff along the same theme.
----------
Estimated hours taken: 0.75
More improvements to memory profiling.
runtime/mercury_tags.h:
Add `_msg' versions of MR_list_cons() and MR_list_empty().
these record the allocations in the memory profile.
runtime/mercury_heap.h:
Add `_msg' versions of create1(), create2(), and create3(),
for use by MR_list_cons_msg() and MR_list_empty_msg().
Also delete create2_fb() and create2_bf() since they are not used.
library/io.m:
library/string.m:
library/store.m:
library/std_util.m:
Change calls to MR_list_cons() to instead call MR_list_cons_msg()
so that these allocations will get included in the memory profile.
Likewise for MR_list_empty().
Workspace: /home/mercury0/fjh/mercury
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.182
diff -u -r1.182 io.m
--- io.m 1999/09/24 05:47:05 1.182
+++ io.m 1999/09/24 06:04:03
@@ -3226,9 +3226,10 @@
[will_not_call_mercury, thread_safe], "
/* convert mercury_argv from a vector to a list */
{ int i = mercury_argc;
- Args = MR_list_empty();
+ Args = MR_list_empty_msg(mercury__io__command_line_arguments_3_0);
while (--i >= 0) {
- Args = MR_list_cons((Word) mercury_argv[i], Args);
+ Args = MR_list_cons_msg((Word) mercury_argv[i], Args,
+ mercury__io__command_line_arguments_3_0);
}
}
update_io(IO0, IO);
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.156
diff -u -r1.156 std_util.m
--- std_util.m 1999/09/24 05:47:06 1.156
+++ std_util.m 1999/09/24 06:06:19
@@ -2728,7 +2728,7 @@
Arity = info.arity;
/* Build argument list */
- Arguments = MR_list_empty();
+ Arguments = MR_list_empty_msg(mercury__std_util__deconstruct_4_0);
i = info.arity;
while (--i >= 0) {
@@ -2739,7 +2739,8 @@
""std_util:univ/0"");
/* Join the argument to the front of the list */
- Arguments = MR_list_cons(Argument, Arguments);
+ Arguments = MR_list_cons_msg(Argument, Arguments,
+ mercury__std_util__deconstruct_4_0);
/* Fill in the arguments */
arg_pseudo_type_info = info.type_info_vector[i];
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.114
diff -u -r1.114 string.m
--- string.m 1999/09/24 05:47:07 1.114
+++ string.m 1999/09/24 06:04:40
@@ -1608,10 +1608,11 @@
:- pragma c_code(string__to_int_list(Str::in, IntList::out),
[will_not_call_mercury, thread_safe], "{
const char *p = Str + strlen(Str);
- IntList = MR_list_empty();
+ IntList = MR_list_empty_msg(mercury__string__to_int_list_2_0);
while (p > Str) {
p--;
- IntList = MR_list_cons((UnsignedChar) *p, IntList);
+ IntList = MR_list_cons_msg((UnsignedChar) *p, IntList,
+ mercury__string__to_int_list_2_0);
}
}").
Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.11
diff -u -r1.11 mercury_heap.h
--- mercury_heap.h 1999/09/24 05:47:14 1.11
+++ mercury_heap.h 1999/09/24 06:15:11
@@ -133,24 +133,24 @@
#endif /* not CONSERVATIVE_GC */
#ifdef PROFILE_MEMORY
- #define tag_incr_hp_msg(dest, tag, count, proclabel, type) \
+ #define MR_maybe_record_allocation(count, proclabel, type) \
+ MR_record_allocation((count), ENTRY(proclabel), \
+ MR_STRINGIFY(proclabel), (type))
+#else
+ #define MR_maybe_record_allocation(count, proclabel, type) \
+ ((void) 0)
+#endif
+
+#define tag_incr_hp_msg(dest, tag, count, proclabel, type) \
( \
- MR_record_allocation((count), ENTRY(proclabel), \
- MR_STRINGIFY(proclabel), (type)), \
+ MR_maybe_record_allocation((count), proclabel, (type)), \
tag_incr_hp((dest), (tag), (count)) \
)
- #define tag_incr_hp_atomic_msg(dest, tag, count, proclabel, type) \
+#define tag_incr_hp_atomic_msg(dest, tag, count, proclabel, type) \
( \
- MR_record_allocation((count), ENTRY(proclabel), \
- MR_STRINGIFY(proclabel), (type)), \
+ MR_maybe_record_allocation((count), proclabel, (type)), \
tag_incr_hp_atomic((dest), (tag), (count)) \
)
-#else /* not PROFILE_MEMORY */
- #define tag_incr_hp_msg(dest, tag, count, proclabel, type) \
- tag_incr_hp((dest), (tag), (count))
- #define tag_incr_hp_atomic_msg(dest, tag, count, proclabel, type) \
- tag_incr_hp_atomic((dest), (tag), (count))
-#endif /* not PROFILE_MEMORY */
/*
** The incr_hp*() macros are defined in terms of the tag_incr_hp*() macros.
@@ -174,8 +174,7 @@
** gcc's expression statements in the code below.
*/
-/* used only by the hand-written example programs */
-/* not by the automatically generated code */
+/* used only by hand-written code not by the automatically generated code */
#define create1(w1) \
( \
hp_alloc(1), \
@@ -184,8 +183,7 @@
/* return */ (Word) (MR_hp - 1) \
)
-/* used only by the hand-written example programs */
-/* not by the automatically generated code */
+/* used only by hand-written code not by the automatically generated code */
#define create2(w1, w2) \
( \
hp_alloc(2), \
@@ -195,8 +193,7 @@
/* return */ (Word) (MR_hp - 2) \
)
-/* used only by the hand-written example programs */
-/* not by the automatically generated code */
+/* used only by hand-written code not by the automatically generated code */
#define create3(w1, w2, w3) \
( \
hp_alloc(3), \
@@ -206,24 +203,36 @@
/* return */ (Word) (MR_hp - 3) \
)
-/* used only by the hand-written example programs */
-/* not by the automatically generated code */
-#define create2_bf(w1) \
- ( \
- MR_hp = MR_hp + 2, \
- MR_hp[-2] = (Word) (w1), \
- heap_overflow_check(), \
- /* return */ (Word) (MR_hp - 2) \
+/* used only by hand-written code not by the automatically generated code */
+#define MR_create1_msg(w1,proclabel,type) \
+ ( \
+ MR_maybe_record_allocation(1, proclabel, (type)), \
+ hp_alloc(1), \
+ MR_hp[-1] = (Word) (w1), \
+ debugcr1(MR_hp[-1], MR_hp), \
+ /* return */ (Word) (MR_hp - 1) \
)
-/* used only by the hand-written example programs */
-/* not by the automatically generated code */
-#define create2_fb(w2) \
- ( \
- MR_hp = MR_hp + 2, \
- MR_hp[-1] = (Word) (w2), \
- heap_overflow_check(), \
- /* return */ (Word) (MR_hp - 2) \
+/* used only by hand-written code not by the automatically generated code */
+#define MR_create2_msg(w1, w2, proclabel, type) \
+ ( \
+ MR_maybe_record_allocation(2, proclabel, (type)), \
+ hp_alloc(2), \
+ MR_hp[-2] = (Word) (w1), \
+ MR_hp[-1] = (Word) (w2), \
+ debugcr2(MR_hp[-2], MR_hp[-1], MR_hp), \
+ /* return */ (Word) (MR_hp - 2) \
+ )
+
+/* used only by hand-written code not by the automatically generated code */
+#define MR_create3_msg(w1, w2, w3, proclabel, type) \
+ ( \
+ MR_maybe_record_allocation(3, proclabel, (type)), \
+ hp_alloc(3), \
+ MR_hp[-3] = (Word) (w1), \
+ MR_hp[-2] = (Word) (w2), \
+ MR_hp[-1] = (Word) (w3), \
+ /* return */ (Word) (MR_hp - 3) \
)
/*
Index: runtime/mercury_tags.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tags.h,v
retrieving revision 1.6
diff -u -r1.6 mercury_tags.h
--- mercury_tags.h 1999/07/13 05:05:47 1.6
+++ mercury_tags.h 1999/09/24 06:14:03
@@ -92,6 +92,12 @@
#define MR_list_empty() ((Word) MR_mkword(MR_TAG_NIL, MR_mkbody(0)))
#define MR_list_cons(head,tail) ((Word) MR_mkword(MR_TAG_CONS, \
create2((head),(tail))))
+#define MR_list_empty_msg(proclabel) \
+ ((Word) MR_mkword(MR_TAG_NIL, MR_mkbody(0)))
+#define MR_list_cons_msg(head,tail,proclabel) \
+ ((Word) MR_mkword(MR_TAG_CONS, \
+ MR_create2_msg((head),(tail), \
+ proclabel, "list:list/1")))
#else
@@ -104,6 +110,15 @@
#define MR_list_cons(head,tail) ((Word) MR_mkword(MR_mktag(0), \
create3(MR_RAW_TAG_CONS, \
(head), (tail))))
+#define MR_list_empty_msg(proclabel) \
+ ((Word) MR_mkword(MR_mktag(0), \
+ MR_create1_msg(MR_RAW_TAG_NIL, \
+ proclabel, "list:list/1")))
+#define MR_list_cons_msg(head,tail,proclabel) \
+ ((Word) MR_mkword(MR_mktag(0), \
+ MR_create3_msg(MR_RAW_TAG_CONS, \
+ (head), (tail), \
+ proclabel, "list:list/1")))
#endif
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list