mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
Branches: main
Implement a new form of memory profiling, which tells the user what memory
is being retained during a program run. This is done by allocating an extra
word before each cell, which is used to "attribute" the cell to an
allocation site. The attribution, or "allocation id", is an address to an
MR_AllocSiteInfo structure generated by the Mercury compiler, giving the
procedure, filename and line number of the allocation, and the type
constructor and arity of the cell that it allocates.
The user must manually instrument the program with calls to
`benchmarking.report_memory_attribution', which forces a GC and summarises
the live objects on the heap using the attributions. The mprof tool is
extended with a new mode to parse and present that data.
Objects which are unattributed (e.g. by hand-written C code which hasn't
been updated) are still accounted for, but show up in profiles as "unknown".
Currently this profiling mode only works in conjunction with the Boehm
garbage collector, though in principle it can work with any memory allocator
for which we can access a list of the live objects. Since term size
profiling relies on the same technique of using an extra word per memory
cell, the two profiling modes are incompatible.
The output from `mprof -s' looks like this:
------ [1] some label ------
cells words cumul procedure / type (location)
14150 38872 total
* 1949/ 13.8% 4872/ 12.5% 12.5% <predicate `parser.parse_rest/7' mode 0>
975/ 6.9% 1950/ 5.0% list.list/1 (parser.m:502)
487/ 3.4% 1948/ 5.0% term.term/1 (parser.m:501)
487/ 3.4% 974/ 2.5% term.const/0 (parser.m:501)
* 1424/ 10.1% 4272/ 11.0% 23.5% <predicate `parser.parse_simple_term_2/6' mode 0>
708/ 5.0% 2832/ 7.3% term.term/1 (parser.m:643)
708/ 5.0% 1416/ 3.6% term.const/0 (parser.m:643)
...
boehm_gc/alloc.c:
boehm_gc/include/gc.h:
boehm_gc/misc.c:
boehm_gc/reclaim.c:
Add a callback function to be called for every live object after a GC.
Add a function to write out the GC_size_map array.
compiler/layout.m:
Define the alloc_site_info type which is equivalent to the
MR_AllocSiteInfo C structure.
Add alloc_site_array as a kind of "layout" array.
compiler/llds.m:
Add allocation sites to `cfile' structure.
Replace TypeMsg argument (which was also for profiling) on `incr_hp'
instructions by an allocation site identifier.
Add a new foreign_proc_component for allocation site ids.
compiler/code_info.m:
compiler/global_data.m:
compiler/proc_gen.m:
Keep the set of allocation sites in the code_info and global_data
structures.
compiler/unify_gen.m:
Add allocation sites to LLDS allocation instructions.
compiler/layout_out.m:
compiler/llds_out_file.m:
compiler/llds_out_instr.m:
Output MR_AllocSiteInfo arrays in generated C files.
Output code to register the MR_AllocSiteInfo array with the Mercury
runtime.
Output allocation site ids for memory allocation instructions.
compiler/llds_out_util.m:
Add allocation sites to llds_out_info.
compiler/pragma_c_gen.m:
compiler/ml_foreign_proc_gen.m:
Generate a macro MR_ALLOC_ID which resolves to an allocation site
structure, for every foreign_proc whose C code contains the string
"MR_ALLOC_ID". This is to be used by hand-written C code which
allocates memory.
MR_PROC_LABELs are retained for backwards compatibility. Though
they were introduced for profiling, they seem to have been co-opted
for printf-debugging since then.
compiler/ml_global_data.m:
Add allocation site structures to the MLDS global data.
compiler/mlds.m:
compiler/ml_unify_gen.m:
Add allocation site id to `new_object' instruction.
compiler/mlds_to_c.m:
Output allocation site arrays and allocation ids in high-level C code.
Output a call to register the allocation site array with the Mercury
runtime.
Delete an unused predicate.
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
Conform to changes.
compiler/pickle.m:
compiler/prog_event.m:
compiler/timestamp.m:
Conform to changes in memory allocation macros.
library/benchmarking.m:
Add the `report_memory_attribution' instrumentation predicates.
Conform to changes to MR_memprof_record.
library/array.m:
library/bit_buffer.m:
library/bitmap.m:
library/construct.m:
library/deconstruct.m:
library/dir.m:
library/io.m:
library/mutvar.m:
library/store.m:
library/string.m:
library/thread.semaphore.m:
library/version_array.m:
Use attributed memory allocation throughout the standard library so
that objects don't show up in the memory profile as "unknown".
Replace MR_PROC_LABEL by MR_ALLOC_ID.
mdbcomp/program_representation.m:
mdbcomp/rtti_access.m:
Replace MR_PROC_LABEL by MR_ALLOC_ID.
profiler/Mercury.options:
profiler/globals.m:
profiler/mercury_profile.m:
profiler/options.m:
profiler/output.m:
profiler/snapshots.m:
Add a new mode to `mprof' to parse and present the data from
`Prof.Snapshots' files.
Add options for the new profiling mode.
profiler/process_file.m:
Fix a typo.
runtime/mercury_conf_param.h:
#define MR_MPROF_PROFILE_MEMORY_ATTRIBUTION if memory profiling
is enabled and we are using Boehm GC.
runtime/mercury.h:
Make MR_new_object take an allocation id argument.
Conform to changes in memory allocation macros.
runtime/mercury_memory.c:
runtime/mercury_memory.h:
runtime/mercury_types.h:
Define MR_AllocSiteInfo.
Add memory allocation functions and macros which take into the
account the additional word necessary for the new profiling mode.
These should be used in preferences to the raw memory allocation
functions wherever possible so that objects do not show up in the
profile as "unknown".
Add analogues of realloc/free which take into account the offset
introduced by the attribution word.
Add function versions of the MR_new_object macros, which can't be
written in standard C. They are only used when necessary.
Add built-in allocation site ids, to be used in the runtime and
other hand-written code when context-specific ids are unavailable.
runtime/mercury_heap.h:
Make MR_tag_offset_incr_hp_msg and MR_tag_offset_incr_hp_atomic_msg
allocate an extra word when memory attribution is desired, and store
the allocation id there.
Similarly for MR_create{1,2,3}_msg.
Replace proclabel arguments in allocation macros by alloc_id
arguments.
Replace MR_hp_alloc_atomic by MR_hp_alloc_atomic_msg. It was only
used for boxing floats.
Conform to change to MR_new_object macro.
runtime/mercury_bootstrap.h:
Delete obsolete macro hp_alloc_atomic.
runtime/mercury_heap_profile.c:
runtime/mercury_heap_profile.h:
Add the code to summarise the live objects on the Boehm GC heap and
writes out the data to `Prof.Snapshots', for display by mprof.
Don't store the procedure name in MR_memprof_record: the procedure
address is enough and faster to compare.
runtime/mercury_prof.c:
Finish and close the `Prof.Snapshots' file when the program
terminates.
Conform to changes in MR_memprof_record.
runtime/mercury_misc.h:
Add a macro to expand to the name of the allocation sites array
in LLDS grades.
runtime/mercury_bitmap.c:
runtime/mercury_bitmap.h:
Pass allocation id through bitmap allocation functions.
Delete unused function MR_string_to_bitmap.
runtime/mercury_string.h:
Add MR_make_aligned_string_copy_msg.
Make string allocation macros take allocation id arguments.
runtime/mercury.c:
runtime/mercury_array_macros.h:
runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_dlist.c:
runtime/mercury_engine.c:
runtime/mercury_float.h:
runtime/mercury_hash_table.c:
runtime/mercury_ho_call.c:
runtime/mercury_label.c:
runtime/mercury_prof_mem.c:
runtime/mercury_stacks.c:
runtime/mercury_stm.c:
runtime/mercury_string.c:
runtime/mercury_thread.c:
runtime/mercury_trace_base.c:
runtime/mercury_trail.c:
runtime/mercury_type_desc.c:
runtime/mercury_type_info.c:
runtime/mercury_wsdeque.c:
Use attributed memory allocation throughout the runtime so that
objects don't show up in the profile as "unknown".
runtime/mercury_memory_zones.c:
Attribute memory zones to the Mercury runtime.
runtime/mercury_tabling.c:
runtime/mercury_tabling.h:
Use attributed memory allocation macros for tabling structures.
Delete unused MR_table_realloc_* and MR_table_copy_bytes macros.
runtime/mercury_deep_copy_body.h:
Try to retain the original attribution word when copying values.
runtime/mercury_ml_expand_body.h:
Conform to changes in memory allocation macros.
runtime/mercury_tags.h:
Replace proclabel arguments by alloc_id arguments in allocation macros.
runtime/mercury_wrapper.c:
If memory attribution is enabled, tell Boehm GC that pointers may be
displaced by an extra word.
trace/mercury_trace.c:
trace/mercury_trace_tables.c:
Conform to changes in memory allocation macros.
extras/net/tcp.m:
extras/solver_types/library/any_array.m:
extras/trailed_update/tr_array.m:
Conform to changes in memory allocation macros.
doc/user_guide.texi:
Document the new profiling mode.
doc/reference_manual.texi:
Update a commented out example.
367 lines
13 KiB
Mathematica
367 lines
13 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1995-1997,2000, 2004-2006, 2011 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: process_file.m
|
|
% Main author: petdr.
|
|
%
|
|
% Process the files that contain the label declarations, label counts and
|
|
% the caller-callee pairs, also builds the dynamic call graph if the option
|
|
% set.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module process_file.
|
|
:- interface.
|
|
|
|
:- import_module prof_info.
|
|
|
|
:- import_module digraph.
|
|
:- import_module io.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred process_profiling_data_files(prof::out, digraph(string)::out,
|
|
io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module read.
|
|
:- import_module globals.
|
|
:- import_module options.
|
|
|
|
:- import_module bool.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module map.
|
|
:- import_module maybe.
|
|
:- import_module require.
|
|
:- import_module string.
|
|
:- import_module unit.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
process_profiling_data_files(Prof, DynamicCallGraph, !IO) :-
|
|
globals.io_lookup_bool_option(very_verbose, VVerbose, !IO),
|
|
globals.io_lookup_string_option(declfile, DeclFile, !IO),
|
|
globals.io_lookup_string_option(countfile, CountFile, !IO),
|
|
globals.io_lookup_string_option(pairfile, PairFile, !IO),
|
|
% globals.io_lookup_string_option(libraryfile, LibFile, !IO),
|
|
globals.io_lookup_bool_option(dynamic_cg, Dynamic, !IO),
|
|
|
|
% process the decl file
|
|
maybe_write_string(VVerbose, "\n\t% Processing ", !IO),
|
|
maybe_write_string(VVerbose, DeclFile, !IO),
|
|
maybe_write_string(VVerbose, "...", !IO),
|
|
process_addr_decl(AddrDeclMap0, ProfNodeMap0, !IO),
|
|
maybe_write_string(VVerbose, " done.\n", !IO),
|
|
|
|
% process the timing counts file
|
|
maybe_write_string(VVerbose, "\t% Processing ", !IO),
|
|
maybe_write_string(VVerbose, CountFile, !IO),
|
|
maybe_write_string(VVerbose, "...", !IO),
|
|
process_addr(ProfNodeMap0, ProfNodeMap1, WhatToProfile, Scale, Units,
|
|
TotalCounts, !IO),
|
|
maybe_write_string(VVerbose, " done.\n", !IO),
|
|
|
|
% Process the call pair counts file.
|
|
maybe_write_string(VVerbose, "\t% Processing ", !IO),
|
|
maybe_write_string(VVerbose, PairFile, !IO),
|
|
maybe_write_string(VVerbose, "...", !IO),
|
|
process_addr_pair(ProfNodeMap1, ProfNodeMap,
|
|
AddrDeclMap0, AddrDeclMap, DynamicCallGraph, !IO),
|
|
maybe_write_string(VVerbose, " done.\n", !IO),
|
|
|
|
map.init(CycleMap),
|
|
prof_set_entire(Scale, Units, TotalCounts, AddrDeclMap,
|
|
ProfNodeMap, CycleMap, Prof),
|
|
globals.io_get_globals(Globals0, !IO),
|
|
globals.set_what_to_profile(WhatToProfile, Globals0, Globals),
|
|
globals.io_set_globals(Globals, !IO),
|
|
|
|
(
|
|
Dynamic = no
|
|
% maybe_write_string(VVerbose, "\t% Processing "),
|
|
% maybe_write_string(VVerbose, LibFile),
|
|
% maybe_write_string(VVerbose, "..."),
|
|
% process_library_callgraph(_, _),
|
|
% maybe_write_string(VVerbose, " done.\n"),
|
|
;
|
|
Dynamic = yes
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% process_addr_decl(AddrDeclMap, ProfNodeMap, !IO):
|
|
%
|
|
% Reads in the Prof.Decl file.
|
|
% Builds the addrdecl map which associates label names(key)
|
|
% with label addresses.
|
|
% Also builds the prof_node_map which associates label addresses
|
|
% with the prof_node structure. Initialises and inserts the label name
|
|
% into the structure at the same time.
|
|
%
|
|
:- pred process_addr_decl(addrdecl::out, prof_node_map::out,
|
|
io::di, io::uo) is det.
|
|
|
|
process_addr_decl(AddrDeclMap, ProfNodeMap, !IO) :-
|
|
globals.io_lookup_string_option(declfile, DeclFile, !IO),
|
|
io.see(DeclFile, Result, !IO),
|
|
(
|
|
Result = ok,
|
|
process_addr_decl_2(map.init, AddrDeclMap, map.init, ProfNodeMap, !IO),
|
|
io.seen(!IO)
|
|
;
|
|
Result = error(Error),
|
|
ErrorStr = "error opening declaration file `" ++ DeclFile ++
|
|
"': " ++ io.error_message(Error) ++ "\n",
|
|
error(ErrorStr)
|
|
).
|
|
|
|
:- pred process_addr_decl_2(addrdecl::in, addrdecl::out, prof_node_map::in,
|
|
prof_node_map::out, io::di, io::uo) is det.
|
|
|
|
process_addr_decl_2(!AddrDecl, !ProfNodeMap, !IO) :-
|
|
maybe_read_label_addr(MaybeLabelAddr, !IO),
|
|
(
|
|
MaybeLabelAddr = yes(LabelAddr),
|
|
read_label_name(LabelName, !IO),
|
|
ProfNode = prof_node_init(LabelName),
|
|
map.det_insert(LabelName, LabelAddr, !AddrDecl),
|
|
|
|
% Labels with different names but the same addresses.
|
|
( map.insert(LabelAddr, ProfNode, !ProfNodeMap) ->
|
|
true
|
|
;
|
|
lookup_addr(LabelAddr, ProfNode0, !AddrDecl, !ProfNodeMap),
|
|
prof_node_concat_to_name_list(LabelName, ProfNode0, NewProfNode),
|
|
map.det_update(LabelAddr, NewProfNode, !ProfNodeMap)
|
|
),
|
|
process_addr_decl_2(!AddrDecl, !ProfNodeMap, !IO)
|
|
;
|
|
MaybeLabelAddr = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% process_addr(!ProfNodeMap, WhatToProfile, Scale, Units, TotalCounts,
|
|
% !IO):
|
|
%
|
|
% Reads in the Prof.Counts file and stores all the counts in the prof_node
|
|
% structure. Also sums the total counts at the same time.
|
|
%
|
|
:- pred process_addr(prof_node_map::in, prof_node_map::out,
|
|
what_to_profile::out, float::out, string::out, int::out,
|
|
io::di, io::uo) is det.
|
|
|
|
process_addr(!ProfNodeMap, WhatToProfile, Scale, Units, TotalCounts, !IO) :-
|
|
globals.io_lookup_string_option(countfile, CountFile, !IO),
|
|
io.see(CountFile, Result, !IO),
|
|
(
|
|
Result = ok,
|
|
read_what_to_profile(WhatToProfile, !IO),
|
|
read_float(Scale, !IO),
|
|
read_string(Units, !IO),
|
|
process_addr_2(0, TotalCounts, !ProfNodeMap, !IO),
|
|
io.seen(!IO)
|
|
;
|
|
Result = error(Error),
|
|
io.error_message(Error, ErrorMsg),
|
|
io.write_string("\nWarning: error opening `", !IO),
|
|
io.write_string(CountFile, !IO),
|
|
io.write_string("': ", !IO),
|
|
io.write_string(ErrorMsg, !IO),
|
|
io.write_string("\n", !IO),
|
|
io.write_string("The generated profile will only include ", !IO),
|
|
io.write_string("call counts.\n\n", !IO),
|
|
TotalCounts = 0,
|
|
% We can use any arbitrary values for WhatToProfile and Scale;
|
|
% the values specified here won't be used,
|
|
% since all the times will be zero.
|
|
WhatToProfile = user_plus_system_time,
|
|
Scale = 1.0,
|
|
Units = ""
|
|
).
|
|
|
|
:- pred process_addr_2(int::in, int::out,
|
|
prof_node_map::in, prof_node_map::out, io::di, io::uo) is det.
|
|
|
|
process_addr_2(!TotalCounts, !ProfNodeMap, !IO) :-
|
|
maybe_read_label_addr(MaybeLabelAddr, !IO),
|
|
(
|
|
MaybeLabelAddr = yes(LabelAddr),
|
|
read_int(Count, !IO),
|
|
|
|
% Add to initial counts if we have a ProfNode structure
|
|
% for the address otherwise ignore it.
|
|
( map.search(!.ProfNodeMap, LabelAddr, ProfNode0) ->
|
|
prof_node_get_initial_counts(ProfNode0, InitCount0),
|
|
InitCount = InitCount0 + Count,
|
|
prof_node_set_initial_counts(InitCount, ProfNode0, ProfNode),
|
|
map.set(LabelAddr, ProfNode, !ProfNodeMap),
|
|
!:TotalCounts = !.TotalCounts + Count
|
|
;
|
|
io.format("\nWarning address %d not found! " ++
|
|
"Ignoring address and continuing computation.\n",
|
|
[i(LabelAddr)], !IO)
|
|
),
|
|
process_addr_2(!TotalCounts, !ProfNodeMap, !IO)
|
|
;
|
|
MaybeLabelAddr = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% process_addr_pair(!ProfNodeMap, !AddrDecl, DynamicCallGraph, !IO):
|
|
%
|
|
% Reads in the Prof.CallPair file and stores the data in the relevant
|
|
% lists of the prof_node structure. Also calculates the number of
|
|
% times a predicate is called.
|
|
%
|
|
:- pred process_addr_pair(prof_node_map::in, prof_node_map::out,
|
|
addrdecl::in, addrdecl::out, digraph(string)::out, io::di, io::uo)
|
|
is det.
|
|
|
|
process_addr_pair(!ProfNodeMap, !AddrDecl, DynamicCallGraph, !IO) :-
|
|
globals.io_lookup_bool_option(dynamic_cg, Dynamic, !IO),
|
|
globals.io_lookup_string_option(pairfile, PairFile, !IO),
|
|
io.see(PairFile, Result, !IO),
|
|
(
|
|
Result = ok,
|
|
process_addr_pair_2(Dynamic, digraph.init, DynamicCallGraph,
|
|
!ProfNodeMap, !AddrDecl, !IO),
|
|
io.seen(!IO)
|
|
;
|
|
Result = error(Error),
|
|
ErrorStr = "error opening pair file `" ++ PairFile ++
|
|
"': " ++ io.error_message(Error) ++ "\n",
|
|
error(ErrorStr)
|
|
).
|
|
|
|
:- pred process_addr_pair_2(bool::in,
|
|
digraph(string)::in, digraph(string)::out,
|
|
prof_node_map::in, prof_node_map::out,
|
|
addrdecl::in, addrdecl::out, io::di, io::uo) is det.
|
|
|
|
process_addr_pair_2(Dynamic, !DynamicCallGraph, !ProfNodeMap, !AddrDecl,
|
|
!IO) :-
|
|
maybe_read_label_addr(MaybeLabelAddr, !IO),
|
|
(
|
|
MaybeLabelAddr = yes(CallerAddr),
|
|
read_label_addr(CalleeAddr, !IO),
|
|
read_int(Count, !IO),
|
|
|
|
% Get child and parent information.
|
|
lookup_addr(CallerAddr, CallerProfNode0, !AddrDecl, !ProfNodeMap),
|
|
lookup_addr(CalleeAddr, CalleeProfNode0, !AddrDecl, !ProfNodeMap),
|
|
prof_node_get_pred_name(CallerProfNode0, CallerName),
|
|
prof_node_get_pred_name(CalleeProfNode0, CalleeName),
|
|
|
|
% Insert child information.
|
|
prof_node_concat_to_child(CalleeName, Count, CallerProfNode0,
|
|
CallerProfNode),
|
|
map.set(CallerAddr, CallerProfNode, !ProfNodeMap),
|
|
|
|
% Update the total calls field if not self recursive.
|
|
( CalleeAddr \= CallerAddr ->
|
|
prof_node_get_total_calls(CalleeProfNode0, TotalCalls0),
|
|
TotalCalls = TotalCalls0 + Count,
|
|
prof_node_set_total_calls(TotalCalls, CalleeProfNode0,
|
|
CalleeProfNode1),
|
|
prof_node_concat_to_parent(CallerName, Count,
|
|
CalleeProfNode1, CalleeProfNode)
|
|
;
|
|
prof_node_set_self_calls(Count, CalleeProfNode0, CalleeProfNode)
|
|
),
|
|
|
|
% Insert parent information.
|
|
map.set(CalleeAddr, CalleeProfNode, !ProfNodeMap),
|
|
|
|
% Add edge to call graph if generating dynamic call graph.
|
|
(
|
|
Dynamic = yes,
|
|
digraph.add_vertex(CallerName, CallerKey, !DynamicCallGraph),
|
|
digraph.add_vertex(CalleeName, CalleeKey, !DynamicCallGraph),
|
|
digraph.add_edge(CallerKey, CalleeKey, !DynamicCallGraph)
|
|
;
|
|
Dynamic = no
|
|
),
|
|
process_addr_pair_2(Dynamic, !DynamicCallGraph, !ProfNodeMap,
|
|
!AddrDecl, !IO)
|
|
;
|
|
MaybeLabelAddr = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% process_library_callgraph(LibraryATSort, LibPredMap, !IO):
|
|
%
|
|
% XXX
|
|
%
|
|
:- pred process_library_callgraph(list(string)::out, map(string, unit)::out,
|
|
io::di, io::uo) is det.
|
|
|
|
process_library_callgraph(LibraryATSort, LibPredMap, !IO) :-
|
|
globals.io_lookup_string_option(libraryfile, LibFile, !IO),
|
|
map.init(LibPredMap0),
|
|
io.see(LibFile, Result, !IO),
|
|
(
|
|
Result = ok,
|
|
process_library_callgraph_2([], LibraryATSort, LibPredMap0,
|
|
LibPredMap, !IO),
|
|
io.seen(!IO)
|
|
;
|
|
Result = error(Error),
|
|
io.error_message(Error, ErrorMsg),
|
|
io.stderr_stream(StdErr, !IO),
|
|
io.write_strings(StdErr, ["mprof: error opening pair file `",
|
|
LibFile, "': ", ErrorMsg, "\n"], !IO),
|
|
LibraryATSort = [],
|
|
LibPredMap = LibPredMap0
|
|
).
|
|
|
|
:- pred process_library_callgraph_2(list(string)::in, list(string)::out,
|
|
map(string, unit)::in, map(string, unit)::out, io::di, io::uo) is det.
|
|
|
|
process_library_callgraph_2(!LibATSort, !LibPredMap, !IO) :-
|
|
maybe_read_label_name(MaybeLabelName, !IO),
|
|
(
|
|
MaybeLabelName = yes(LabelName),
|
|
map.det_insert(LabelName, unit, !LibPredMap),
|
|
list.cons(LabelName, !LibATSort),
|
|
process_library_callgraph_2(!LibATSort, !LibPredMap, !IO)
|
|
;
|
|
MaybeLabelName = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Attempt to lookup the addr in the prof_node_map, if it does not exist
|
|
% then record the name as unknown__<address> in the relevant data
|
|
% structures.
|
|
%
|
|
:- pred lookup_addr(int::in, prof_node::out, addrdecl::in, addrdecl::out,
|
|
prof_node_map::in, prof_node_map::out) is det.
|
|
|
|
lookup_addr(Addr, ProfNode, !AddrDeclMap, !ProfNodeMap) :-
|
|
( map.search(!.ProfNodeMap, Addr, ProfNode0) ->
|
|
ProfNode = ProfNode0
|
|
;
|
|
Str = string.format("unknown__%d", [i(Addr)]),
|
|
ProfNode = prof_node_init(Str),
|
|
map.det_insert(Addr, ProfNode, !ProfNodeMap),
|
|
map.det_insert(Str, Addr, !AddrDeclMap)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module process_file.
|
|
%-----------------------------------------------------------------------------%
|