[m-rev.] diff: deep profiler documentation and cleanup

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jul 13 17:31:47 AEST 2001


I will commit this now. I will do more documentation and cleanup over the
weekend. I think it is best if any review waits until that is all done.
(This diff changes mostly unreviewed code anyway.)

Zoltan.

Misc cleanups and documentation of various aspects of the deep profiler.
More will come later.

deep_profiler/startup.m:
	Fix a bug in the algorithm that we used to compensate for zeroing.
	The new algorithm is documented in the paper.

deep_profiler/profile.m:
deep_profiler/startup.m:
deep_profiler/query.m:
	Switch the names we use for the data structures used in that algorithm
	to match the names in the paper.

deep_profiler/query.m:
	Fix an off-by-one bug.

deep_profiler/interface.m:
	Document this module.

deep_profiler/interface.m:
deep_profiler/mdprof_cgi.m:
	Move some code in interface.m that was used only in mdprof_cgi.m to
	mdprof_cgi.m.

cvs diff: Diffing .
Index: interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/interface.m,v
retrieving revision 1.3
diff -u -b -r1.3 interface.m
--- interface.m	2001/07/03 08:16:18	1.3
+++ interface.m	2001/07/12 17:00:42
@@ -6,24 +6,54 @@
 %
 % Author: zs.
 %
-% This module defines the type of the commands that the CGI program
-% (mdprof_cgi.m) passes to the deep profiling server (mdprof_server.m),
-% as well as utility predicates for manipulating commands and responses.
+% This module defines interface between the CGI program (mdprof_cgi.m)
+% and the deep profiling server (mdprof_server.m).
+%
+% The interface consists of queries (sent from the CGI program to the server)
+% and responses (sent back from the server to the CGI program), and shared
+% knowledge of how to derive the names of some files from the name of the
+% profiling data file being explored.
+%
+% A query consists of three components, a command, a set of preferences, and
+% the name of the profiling data file. The command tells the server what
+% information the user wants displayed. The preferences tell the server how the
+% user wants data displayed; they persist across queries unless the user
+% changes them.
+%
+% This module defines the types of commands and preferences. It provides
+% mechanisms for converting queries to URLs and URLs to queries, but it
+% does not expose the encoding. The encoding is compositional; each component
+% of the query (say x) has a x_to_string function to convert it to the URL form
+% and a string_to_x predicate to try to convert an URL fragment back to it.
+% The function/predicate pairs are adjacent to make it easy to update both at
+% the same time. This is essential, because we have no other mechanism to
+% ensure that the URLs we embed in the HTML pages we generate will be
+% recognized and correctly parsed by the CGI program.
 
 :- module interface.
 
 :- interface.
 
-:- import_module std_util, io.
+:- import_module std_util.
 
+	% These functions derive the names of auxiliary files from the name of
+	% the profiling data file being explored. The auxiliary files are:
+	%
+	% - the name of the named pipe for transmitting queries to the server;
+	% - the name of the named pipe for transmitting responses back to the
+	%   CGI program;
+	% - the name of the file containing the output of the server program,
+	%   which prints statistics about its own performance at startup
+	%   (and if invoked with the --debug option, debugging information
+	%   during its execution)
+	% - the name of the file containing contour exclusion information
+	%   (see exclude.m).
+
 :- func to_server_pipe_name(string) = string.
 :- func from_server_pipe_name(string) = string.
 :- func server_startup_name(string) = string.
 :- func contour_file_name(string) = string.
 
-:- pred to(string::in, cmd_pref::in, io__state::di, io__state::uo) is det.
-:- pred from(string::in, resp::out, io__state::di, io__state::uo) is det.
-
 :- type resp
 	--->	html(string).
 
@@ -68,8 +98,12 @@
 	;	self_and_desc.
 
 :- type display_limit
-	--->	rank_range(int, int)
-	;	threshold(float).
+	--->	rank_range(int, int)	% rank_range(M, N): display procedures
+					% with rank M to N, both inclusive.
+	;	threshold(float).	% threshold(Percent): display
+					% procedures whose cost is at least
+					% Fraction% of the whole program's
+					% cost.
 
 :- type preferences
 	--->	preferences(
@@ -179,7 +213,7 @@
 
 :- func cmd_pref_to_url(string, string, cmd, preferences) = string.
 :- func url_component_to_cmd(string) = maybe(cmd).
-:- func url_component_to_preferences(string) = maybe(preferences).
+:- func url_component_to_pref(string) = maybe(preferences).
 
 %-----------------------------------------------------------------------------%
 
@@ -263,32 +297,6 @@
 
 %-----------------------------------------------------------------------------%
 
-to(Where, CmdPref) -->
-	io__tell(Where, Res),
-	( { Res = ok } ->
-		io__write(CmdPref),
-		io__write_string(".\n"),
-		io__told
-	;
-		{ error("mdprof to: couldn't open pipe") }
-	).
-
-from(Where, Resp) -->
-	io__see(Where, Res0),
-	( { Res0 = ok } ->
-		io__read(Res1),
-		( { Res1 = ok(Resp0) } ->
-			{ Resp = Resp0 }
-		;
-			{ error("mdprof from: read failed") }
-		),
-		io__seen
-	;
-		{ error("mdprof from: couldn't open pipe") }
-	).
-
-%-----------------------------------------------------------------------------%
-
 cmd_pref_to_url(Machine, DataFileName, Cmd, Preferences) =
 	"http://" ++
 	Machine ++
@@ -480,7 +488,7 @@
 		MaybeCmd = no
 	).
 
-url_component_to_preferences(QueryString) = MaybePreferences :-
+url_component_to_pref(QueryString) = MaybePreferences :-
 	split(QueryString, ('+'), Pieces),
 	(
 		Pieces = [FieldsStr, BoxStr, ColourStr, MaybeAncestorLimitStr,
Index: mdprof_cgi.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/mdprof_cgi.m,v
retrieving revision 1.2
diff -u -b -r1.2 mdprof_cgi.m
--- mdprof_cgi.m	2001/07/03 08:16:18	1.2
+++ mdprof_cgi.m	2001/07/12 17:01:45
@@ -129,7 +129,7 @@
 	{ MaybeCmd = url_component_to_cmd(CmdStr) },
 	{
 		MaybePrefStr = yes(PrefStr),
-		MaybePref = url_component_to_preferences(PrefStr)
+		MaybePref = url_component_to_pref(PrefStr)
 	;
 		MaybePrefStr = no,
 		MaybePref = yes(default_preferences)
@@ -140,4 +140,34 @@
 		io__write_string(Page)
 	;
 		io__write_string("mdprof: unknown URL format")
+	).
+
+	% Send a query to the server.
+:- pred to(string::in, cmd_pref::in, io__state::di, io__state::uo) is det.
+
+to(ToServerPipeName, CmdPref) -->
+	io__tell(ToServerPipeName, Res),
+	( { Res = ok } ->
+		io__write(CmdPref),
+		io__write_string(".\n"),
+		io__told
+	;
+		{ error("mdprof_cgi to: couldn't open pipe") }
+	).
+
+	% Read a response from the server.
+:- pred from(string::in, resp::out, io__state::di, io__state::uo) is det.
+
+from(FromServerPipeName, Resp) -->
+	io__see(FromServerPipeName, Res0),
+	( { Res0 = ok } ->
+		io__read(Res1),
+		( { Res1 = ok(Resp0) } ->
+			{ Resp = Resp0 }
+		;
+			{ error("mdprof_cgi from: read failed") }
+		),
+		io__seen
+	;
+		{ error("mdprof_cgi from: couldn't open pipe") }
 	).
Index: profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/profile.m,v
retrieving revision 1.3
diff -u -b -r1.3 profile.m
--- profile.m	2001/07/03 08:16:18	1.3
+++ profile.m	2001/07/12 02:22:19
@@ -87,13 +87,13 @@
 			% Additional propagated timing info to solve the
 			% problem of undetected recursion through higher order
 			% calls, which is caused by our use of zeroing.
-		pd_zero_total_map	:: array(zero_total_map),
-		csd_zero_total_map	:: array(zero_total_map),
+		pd_comp_table		:: array(compensation_table),
+		csd_comp_table		:: array(compensation_table),
 			% Information about modules.
 		module_data		:: map(string, module_data)
 	).
 
-:- type zero_total_map == map(proc_static_ptr, inherit_prof_info).
+:- type compensation_table == map(proc_static_ptr, inherit_prof_info).
 
 :- type module_data
 	--->	module_data(
@@ -292,10 +292,10 @@
 	call_site_static_ptr::in, own_prof_info::out) is det.
 :- pred lookup_css_desc(array(inherit_prof_info)::in,
 	call_site_static_ptr::in, inherit_prof_info::out) is det.
-:- pred lookup_pd_zero_map(array(zero_total_map)::in,
-	proc_dynamic_ptr::in, zero_total_map::out) is det.
-:- pred lookup_csd_zero_map(array(zero_total_map)::in,
-	call_site_dynamic_ptr::in, zero_total_map::out) is det.
+:- pred lookup_pd_comp_table(array(compensation_table)::in,
+	proc_dynamic_ptr::in, compensation_table::out) is det.
+:- pred lookup_csd_comp_table(array(compensation_table)::in,
+	call_site_dynamic_ptr::in, compensation_table::out) is det.
 
 :- pred deep_lookup_call_site_dynamics(deep::in, call_site_dynamic_ptr::in,
 	call_site_dynamic::out) is det.
@@ -321,10 +321,10 @@
 	map(proc_static_ptr, list(call_site_dynamic_ptr))::out) is det.
 :- pred deep_lookup_proc_dynamic_sites(deep::in, proc_dynamic_ptr::in,
 	array(call_site_array_slot)::out) is det.
-:- pred deep_lookup_pd_zero_map(deep::in, proc_dynamic_ptr::in,
-	zero_total_map::out) is det.
-:- pred deep_lookup_csd_zero_map(deep::in, call_site_dynamic_ptr::in,
-	zero_total_map::out) is det.
+:- pred deep_lookup_pd_comp_table(deep::in, proc_dynamic_ptr::in,
+	compensation_table::out) is det.
+:- pred deep_lookup_csd_comp_table(deep::in, call_site_dynamic_ptr::in,
+	compensation_table::out) is det.
 
 :- pred deep_lookup_pd_own(deep::in, proc_dynamic_ptr::in,
 	own_prof_info::out) is det.
@@ -379,10 +379,10 @@
 	inherit_prof_info::in, deep::out) is det.
 :- pred deep_update_pd_own(deep::in, proc_dynamic_ptr::in,
 	own_prof_info::in, deep::out) is det.
-:- pred deep_update_pd_zero_map(deep::in, proc_dynamic_ptr::in,
-	zero_total_map::in, deep::out) is det.
-:- pred deep_update_csd_zero_map(deep::in, call_site_dynamic_ptr::in,
-	zero_total_map::in, deep::out) is det.
+:- pred deep_update_pd_comp_table(deep::in, proc_dynamic_ptr::in,
+	compensation_table::in, deep::out) is det.
+:- pred deep_update_csd_comp_table(deep::in, call_site_dynamic_ptr::in,
+	compensation_table::in, deep::out) is det.
 
 :- pred extract_pd_sites(proc_dynamic::in, array(call_site_array_slot)::out)
 	is det.
@@ -646,20 +646,20 @@
 		error("lookup_css_desc: bounds error")
 	).
 
-lookup_pd_zero_map(PDZeroMaps, PDPtr, ZeroMap) :-
+lookup_pd_comp_table(PDCompTables, PDPtr, CompTable) :-
 	PDPtr = proc_dynamic_ptr(PDI),
-	( PDI > 0, array__in_bounds(PDZeroMaps, PDI) ->
-		array__lookup(PDZeroMaps, PDI, ZeroMap)
+	( PDI > 0, array__in_bounds(PDCompTables, PDI) ->
+		array__lookup(PDCompTables, PDI, CompTable)
 	;
-		error("lookup_pd_zero_map: bounds error")
+		error("lookup_pd_comp_table: bounds error")
 	).
 
-lookup_csd_zero_map(CSDZeroMaps, CSDPtr, ZeroMap) :-
+lookup_csd_comp_table(CSDCompTables, CSDPtr, CompTable) :-
 	CSDPtr = call_site_dynamic_ptr(CSDI),
-	( CSDI > 0, array__in_bounds(CSDZeroMaps, CSDI) ->
-		array__lookup(CSDZeroMaps, CSDI, ZeroMap)
+	( CSDI > 0, array__in_bounds(CSDCompTables, CSDI) ->
+		array__lookup(CSDCompTables, CSDI, CompTable)
 	;
-		error("lookup_csd_zero_map: bounds error")
+		error("lookup_csd_comp_table: bounds error")
 	).
 
 %-----------------------------------------------------------------------------%
@@ -703,11 +703,11 @@
 	deep_lookup_proc_dynamics(Deep, PDPtr, PD),
 	PDSites = PD ^ pd_sites.
 
-deep_lookup_pd_zero_map(Deep, PDPtr, ZeroMap) :-
-	lookup_pd_zero_map(Deep ^ pd_zero_total_map, PDPtr, ZeroMap).
+deep_lookup_pd_comp_table(Deep, PDPtr, CompTable) :-
+	lookup_pd_comp_table(Deep ^ pd_comp_table, PDPtr, CompTable).
 
-deep_lookup_csd_zero_map(Deep, CSDPtr, ZeroMap) :-
-	lookup_csd_zero_map(Deep ^ csd_zero_total_map, CSDPtr, ZeroMap).
+deep_lookup_csd_comp_table(Deep, CSDPtr, CompTable) :-
+	lookup_csd_comp_table(Deep ^ csd_comp_table, CSDPtr, CompTable).
 
 %-----------------------------------------------------------------------------%
 
@@ -804,15 +804,15 @@
 	array__set(u(Deep0 ^ pd_own), PDI, PDOwn, PDOwns),
 	Deep = Deep0 ^ pd_own := PDOwns.
 
-deep_update_pd_zero_map(Deep0, PDPtr, ZeroMap, Deep) :-
+deep_update_pd_comp_table(Deep0, PDPtr, CompTable, Deep) :-
 	PDPtr = proc_dynamic_ptr(PDI),
-	array__set(u(Deep0 ^ pd_zero_total_map), PDI, ZeroMap, PDZeroMaps),
-	Deep = Deep0 ^ pd_zero_total_map := PDZeroMaps.
+	array__set(u(Deep0 ^ pd_comp_table), PDI, CompTable, PDCompTables),
+	Deep = Deep0 ^ pd_comp_table := PDCompTables.
 
-deep_update_csd_zero_map(Deep0, CSDPtr, ZeroMap, Deep) :-
+deep_update_csd_comp_table(Deep0, CSDPtr, CompTable, Deep) :-
 	CSDPtr = call_site_dynamic_ptr(CSDI),
-	array__set(u(Deep0 ^ csd_zero_total_map), CSDI, ZeroMap, CSDZeroMaps),
-	Deep = Deep0 ^ csd_zero_total_map := CSDZeroMaps.
+	array__set(u(Deep0 ^ csd_comp_table), CSDI, CompTable, CSDCompTables),
+	Deep = Deep0 ^ csd_comp_table := CSDCompTables.
 
 %-----------------------------------------------------------------------------%
 
Index: query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/query.m,v
retrieving revision 1.2
diff -u -b -r1.2 query.m
--- query.m	2001/07/13 04:40:04	1.2
+++ query.m	2001/07/13 04:41:03
@@ -1186,8 +1186,8 @@
 	deep_lookup_csd_desc(Deep, CSDPtr, CSDDesc),
 	add_own_to_own(Own0, CSDOwn) = Own,
 	add_inherit_to_inherit(Desc0, CSDDesc) = Desc1,
-	deep_lookup_csd_zero_map(Deep, CSDPtr, ZeroMapArray),
-	( map__search(ZeroMapArray, CallerPSPtr, InnerTotal) ->
+	deep_lookup_csd_comp_table(Deep, CSDPtr, CompTableArray),
+	( map__search(CompTableArray, CallerPSPtr, InnerTotal) ->
 		Desc = subtract_inherit_from_inherit(InnerTotal, Desc1)
 	;
 		Desc = Desc1
@@ -1597,8 +1597,8 @@
 			[i(NumLines), s(Parent), s(WrappedProcName),
 			i(BunchSize)])
 	;
-		First = BunchNum * BunchSize + 1,
-		Last0 = (BunchNum + 1) * BunchSize,
+		First = (BunchNum - 1) * BunchSize + 1,
+		Last0 = (BunchNum) * BunchSize,
 		( Last0 > NumLines ->
 			Last = NumLines
 		;
@@ -1766,17 +1766,17 @@
 			CalleeCliquePtr),
 		deep_lookup_clique_members(Deep, CalleeCliquePtr,
 			CalleeCliquePDPtrs),
-		list__foldl(compensate_for_zero_map(Deep, CallerPSPtr),
+		list__foldl(compensate_using_comp_table(Deep, CallerPSPtr),
 			CalleeCliquePDPtrs, Desc1, Desc)
 	).
 
-:- pred compensate_for_zero_map(deep::in, proc_static_ptr::in,
+:- pred compensate_using_comp_table(deep::in, proc_static_ptr::in,
 	proc_dynamic_ptr::in, inherit_prof_info::in, inherit_prof_info::out)
 	is det.
 
-compensate_for_zero_map(Deep, CallerPSPtr, PDPtr, Desc0, Desc) :-
-	deep_lookup_pd_zero_map(Deep, PDPtr, ZeroMapArray),
-	( map__search(ZeroMapArray, CallerPSPtr, InnerTotal) ->
+compensate_using_comp_table(Deep, CallerPSPtr, PDPtr, Desc0, Desc) :-
+	deep_lookup_pd_comp_table(Deep, PDPtr, CompTableArray),
+	( map__search(CompTableArray, CallerPSPtr, InnerTotal) ->
 		Desc = subtract_inherit_from_inherit(InnerTotal, Desc0)
 	;
 		Desc = Desc0
Index: startup.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/startup.m,v
retrieving revision 1.4
diff -u -b -r1.4 startup.m
--- startup.m	2001/07/03 08:16:19	1.4
+++ startup.m	2001/07/12 02:32:59
@@ -173,8 +173,8 @@
 	{ array__init(NPSs, zero_inherit_prof_info, PSDesc0) },
 	{ array__init(NCSSs, zero_own_prof_info, CSSOwn0) },
 	{ array__init(NCSSs, zero_inherit_prof_info, CSSDesc0) },
-	{ array__init(NPDs, map__init, PDZeroMap0) },
-	{ array__init(NCSDs, map__init, CSDZeroMap0) },
+	{ array__init(NPDs, map__init, PDCompTable0) },
+	{ array__init(NCSDs, map__init, CSDCompTable0) },
 
 	{ ModuleData = map__map_values(initialize_module_data, ModuleProcs) },
 	{ Deep0 = deep(InitStats, Machine, DataFileName, Root,
@@ -183,7 +183,7 @@
 		ProcCallers, CallSiteStaticMap, CallSiteCalls,
 		PDOwn, PDDesc0, CSDDesc0,
 		PSOwn0, PSDesc0, CSSOwn0, CSSDesc0,
-		PDZeroMap0, CSDZeroMap0, ModuleData) },
+		PDCompTable0, CSDCompTable0, ModuleData) },
 
 	{ array_foldl_from_1(propagate_to_clique, Cliques, Deep0, Deep1) },
 	io__format(StdErr, "  Done.\n", []),
@@ -543,7 +543,7 @@
 	PSDescArray0 = Deep0 ^ ps_desc,
 	array_foldl2_from_1(
 		summarize_proc_dynamic(Deep0 ^ pd_own, Deep0 ^ pd_desc,
-			Deep0 ^ pd_zero_total_map),
+			Deep0 ^ pd_comp_table),
 		Deep0 ^ proc_dynamics,
 		copy(PSOwnArray0), PSOwnArray,
 		copy(PSDescArray0), PSDescArray),
@@ -552,20 +552,20 @@
 		^ ps_desc := PSDescArray).
 
 :- pred summarize_proc_dynamic(array(own_prof_info)::in,
-	array(inherit_prof_info)::in, array(zero_total_map)::in,
+	array(inherit_prof_info)::in, array(compensation_table)::in,
 	int::in, proc_dynamic::in,
 	array(own_prof_info)::array_di, array(own_prof_info)::array_uo,
 	array(inherit_prof_info)::array_di, array(inherit_prof_info)::array_uo)
 	is det.
 
-summarize_proc_dynamic(PDOwnArray, PDDescArray, PDZeroMapArray, PDI, PD,
+summarize_proc_dynamic(PDOwnArray, PDDescArray, PDCompTableArray, PDI, PD,
 		PSOwnArray0, PSOwnArray, PSDescArray0, PSDescArray) :-
 	PSPtr = PD ^ pd_proc_static,
 	PDPtr = proc_dynamic_ptr(PDI),
 	lookup_pd_own(PDOwnArray, PDPtr, PDOwn),
 	lookup_pd_desc(PDDescArray, PDPtr, PDDesc0),
-	lookup_pd_zero_map(PDZeroMapArray, PDPtr, PDZeroMap),
-	( map__search(PDZeroMap, PSPtr, InnerTotal) ->
+	lookup_pd_comp_table(PDCompTableArray, PDPtr, PDCompTable),
+	( map__search(PDCompTable, PSPtr, InnerTotal) ->
 		PDDesc = subtract_inherit_from_inherit(InnerTotal, PDDesc0)
 	;
 		PDDesc = PDDesc0
@@ -588,7 +588,7 @@
 		summarize_call_site_dynamic(
 			Deep0 ^ call_site_static_map,
 			Deep0 ^ call_site_statics, Deep0 ^ csd_desc,
-			Deep0 ^ csd_zero_total_map),
+			Deep0 ^ csd_comp_table),
 		Deep0 ^ call_site_dynamics,
 		copy(CSSOwnArray0), CSSOwnArray,
 		copy(CSSDescArray0), CSSDescArray),
@@ -598,13 +598,13 @@
 
 :- pred summarize_call_site_dynamic(call_site_static_map::in,
 	call_site_statics::in, array(inherit_prof_info)::in,
-	array(zero_total_map)::in, int::in, call_site_dynamic::in,
+	array(compensation_table)::in, int::in, call_site_dynamic::in,
 	array(own_prof_info)::array_di, array(own_prof_info)::array_uo,
 	array(inherit_prof_info)::array_di, array(inherit_prof_info)::array_uo)
 	is det.
 
 summarize_call_site_dynamic(CallSiteStaticMap, CallSiteStatics,
-		CSDDescs, CSDZeroMapArray, CSDI, CSD,
+		CSDDescs, CSDCompTableArray, CSDI, CSD,
 		CSSOwnArray0, CSSOwnArray, CSSDescArray0, CSSDescArray) :-
 	CSDPtr = call_site_dynamic_ptr(CSDI),
 	lookup_call_site_static_map(CallSiteStaticMap, CSDPtr, CSSPtr),
@@ -612,9 +612,9 @@
 	( CSSI > 0 ->
 		CSDOwn = CSD ^ csd_own_prof,
 		lookup_csd_desc(CSDDescs, CSDPtr, CSDDesc0),
-		lookup_csd_zero_map(CSDZeroMapArray, CSDPtr, CSDZeroMap),
+		lookup_csd_comp_table(CSDCompTableArray, CSDPtr, CSDCompTable),
 		lookup_call_site_statics(CallSiteStatics, CSSPtr, CSS),
-		( map__search(CSDZeroMap, CSS ^ css_container, InnerTotal) ->
+		( map__search(CSDCompTable, CSS ^ css_container, InnerTotal) ->
 			CSDDesc = subtract_inherit_from_inherit(InnerTotal,
 				CSDDesc0)
 		;
@@ -667,8 +667,9 @@
 
 propagate_to_clique(CliqueNumber, Members, Deep0, Deep) :-
 	array__lookup(Deep0 ^ clique_parents, CliqueNumber, ParentCSDPtr),
-	list__foldl2(propagate_to_proc_dynamic(CliqueNumber, ParentCSDPtr),
-		Members, Deep0, Deep1, map__init, CSDZeroMap),
+	list__foldl3(propagate_to_proc_dynamic(CliqueNumber, ParentCSDPtr),
+		Members, Deep0, Deep1, map__init, SumTable,
+		map__init, OverrideMap),
 	( valid_call_site_dynamic_ptr(Deep1, ParentCSDPtr) ->
 		deep_lookup_call_site_dynamics(Deep1, ParentCSDPtr, ParentCSD),
 		ParentOwn = ParentCSD ^ csd_own_prof,
@@ -676,34 +677,38 @@
 		subtract_own_from_inherit(ParentOwn, ParentDesc0) =
 			ParentDesc,
 		deep_update_csd_desc(Deep1, ParentCSDPtr, ParentDesc, Deep2),
-		deep_update_csd_zero_map(Deep2, ParentCSDPtr, CSDZeroMap, Deep)
+		CSDCompTable = apply_override(OverrideMap, SumTable),
+		deep_update_csd_comp_table(Deep2, ParentCSDPtr, CSDCompTable,
+			Deep)
 	;
 		Deep = Deep1
 	).
 
 :- pred propagate_to_proc_dynamic(int::in, call_site_dynamic_ptr::in,
 	proc_dynamic_ptr::in, deep::in, deep::out,
-	zero_total_map::in, zero_total_map::out) is det.
+	compensation_table::in, compensation_table::out,
+	compensation_table::in, compensation_table::out) is det.
 
 propagate_to_proc_dynamic(CliqueNumber, ParentCSDPtr, PDPtr, Deep0, Deep,
-		CSDZeroMap0, CSDZeroMap) :-
+		SumTable0, SumTable, OverrideTable0, OverrideTable) :-
 	flat_call_sites(Deep0 ^ proc_dynamics, PDPtr, CSDPtrs),
 	list__foldl2(propagate_to_call_site(CliqueNumber, PDPtr),
-		CSDPtrs, Deep0, Deep1, map__init, PDZeroMap),
-	deep_update_pd_zero_map(Deep1, PDPtr, PDZeroMap, Deep2),
+		CSDPtrs, Deep0, Deep1, map__init, PDCompTable),
+	deep_update_pd_comp_table(Deep1, PDPtr, PDCompTable, Deep2),
 
 	deep_lookup_pd_desc(Deep2, PDPtr, ProcDesc),
 	deep_lookup_pd_own(Deep2, PDPtr, ProcOwn),
 	ProcTotal = add_own_to_inherit(ProcOwn, ProcDesc),
 
-	CSDZeroMap1 = add_zero_maps(CSDZeroMap0, PDZeroMap),
+	SumTable = add_comp_tables(SumTable0, PDCompTable),
 	deep_lookup_proc_dynamics(Deep2, PDPtr, PD),
 	PSPtr = PD ^ pd_proc_static,
 	deep_lookup_proc_statics(Deep2, PSPtr, PS),
 	( PS ^ ps_is_zeroed = zeroed ->
-		CSDZeroMap = add_to_zero_map(CSDZeroMap1, PSPtr, ProcTotal)
+		OverrideTable = add_to_override(OverrideTable0,
+			PSPtr, ProcTotal)
 	;
-		CSDZeroMap = CSDZeroMap1
+		OverrideTable = OverrideTable0
 	),
 
 	( valid_call_site_dynamic_ptr(Deep1, ParentCSDPtr) ->
@@ -716,10 +721,10 @@
 
 :- pred propagate_to_call_site(int::in, proc_dynamic_ptr::in,
 	call_site_dynamic_ptr::in, deep::in, deep::out,
-	zero_total_map::in, zero_total_map::out) is det.
+	compensation_table::in, compensation_table::out) is det.
 
 propagate_to_call_site(CliqueNumber, PDPtr, CSDPtr, Deep0, Deep,
-		PDZeroMap0, PDZeroMap) :-
+		PDCompTable0, PDCompTable) :-
 	deep_lookup_call_site_dynamics(Deep0, CSDPtr, CSD),
 	CalleeOwn = CSD ^ csd_own_prof,
 	CalleePDPtr = CSD ^ csd_callee,
@@ -731,37 +736,58 @@
 		CalleeTotal = add_own_to_inherit(CalleeOwn, CalleeDesc),
 		ProcDesc = add_inherit_to_inherit(ProcDesc0, CalleeTotal),
 		deep_update_pd_desc(Deep0, PDPtr, ProcDesc, Deep),
-		deep_lookup_csd_zero_map(Deep, CSDPtr, CSDZeroMap),
-		PDZeroMap = add_zero_maps(PDZeroMap0, CSDZeroMap)
+		deep_lookup_csd_comp_table(Deep, CSDPtr, CSDCompTable),
+		PDCompTable = add_comp_tables(PDCompTable0, CSDCompTable)
 	;
 		% We don't propagate profiling measurements
 		% along intra-clique calls.
 		Deep = Deep0,
-		PDZeroMap = PDZeroMap0
+		PDCompTable = PDCompTable0
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- func add_zero_maps(zero_total_map, zero_total_map) = zero_total_map.
+:- func add_comp_tables(compensation_table, compensation_table)
+	= compensation_table.
 
-add_zero_maps(ZeroMap1, ZeroMap2) = ZeroMap :-
-	( map__is_empty(ZeroMap1) ->
-		ZeroMap = ZeroMap2
-	; map__is_empty(ZeroMap2) ->
-		ZeroMap = ZeroMap1
+add_comp_tables(CompTable1, CompTable2) = CompTable :-
+	( map__is_empty(CompTable1) ->
+		CompTable = CompTable2
+	; map__is_empty(CompTable2) ->
+		CompTable = CompTable1
 	;
-		ZeroMap = map__union(add_inherit_to_inherit,
-			ZeroMap1, ZeroMap2)
+		CompTable = map__union(add_inherit_to_inherit,
+			CompTable1, CompTable2)
 	).
 
-:- func add_to_zero_map(zero_total_map, proc_static_ptr, inherit_prof_info) =
-	zero_total_map.
+:- func apply_override(compensation_table, compensation_table)
+	= compensation_table.
 
-add_to_zero_map(ZeroMap0, PSPtr, PDTotal) = ZeroMap :-
-	% Even if the map already contained an entry for PSPtr, the costs
-	% incurred by the calls represented by that entry have already been
-	% propagated to PDTotal.
-	map__set(ZeroMap0, PSPtr, PDTotal, ZeroMap).
+apply_override(CompTable1, CompTable2) = CompTable :-
+	( map__is_empty(CompTable1) ->
+		CompTable = CompTable2
+	; map__is_empty(CompTable2) ->
+		CompTable = CompTable1
+	;
+		CompTable = map__union(select_override_comp,
+			CompTable1, CompTable2)
+	).
+
+:- func select_override_comp(inherit_prof_info, inherit_prof_info)
+	= inherit_prof_info.
+
+select_override_comp(OverrideComp, _) = OverrideComp.
+
+:- func add_to_override(compensation_table,
+	proc_static_ptr, inherit_prof_info) = compensation_table.
+
+add_to_override(CompTable0, PSPtr, PDTotal) = CompTable :-
+	( map__search(CompTable0, PSPtr, Comp0) ->
+		Comp = add_inherit_to_inherit(Comp0, PDTotal),
+		map__det_update(CompTable0, PSPtr, Comp, CompTable)
+	;
+		map__det_insert(CompTable0, PSPtr, PDTotal, CompTable)
+	).
 
 %-----------------------------------------------------------------------------%
 
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list