Files
mercury/profiler/options.m
Fergus Henderson e6ac077bae Add support for memory profiling.
Estimated hours taken: 40 (+ unknown time by Zoltan)

Add support for memory profiling.

(A significant part of this change is actuallly Zoltan's work.  Zoltan
did the changes to the compiler and a first go at the changes to the
runtime and library.  I rewrote much of Zoltan's changes to the runtime
and library, added support for the new options/grades, added code to
interface with mprof, did the changes to the profiler, and wrote the
documentation.)

[TODO: add test cases.]

NEWS:
	Mention support for memory profiling.

runtime/mercury_heap_profile.h:
runtime/mercury_heap_profile.c:
	New files.  These contain code to record heap profiling information.

runtime/mercury_heap.h:
	Add new macros incr_hp_msg(), tag_incr_hp_msg(),
	incr_hp_atomic_msg(), and tag_incr_hp_atomic_msg().
	These are like the non-`msg' versions, except that if
	PROFILE_MEMORY is defined, they also call MR_record_allocation()
	from mercury_heap_profile.h to record heap profiling information.
	Also, fix up the indentation in lots of places.

runtime/mercury_prof.h:
runtime/mercury_prof.c:
	Added code to dump out memory profiling information to files
	`Prof.MemoryWords' and `Prof.MemoryCells' (for use by mprof).
	Change the format of the `Prof.Counts' file so that the
	first line says what it is counting, the units, and a scale
	factor.  Prof.MemoryWords and Prof.MemoryCells can thus have
	exactly the same format as Prof.Counts.
	Also cleaned up the interface to mercury_prof.c a bit, and did
	various other minor cleanups -- indentation changes, changes to
	use MR_ prefixes, additional comments, etc.

runtime/mercury_prof_mem.h:
runtime/mercury_prof_mem.c:
	Rename prof_malloc() as MR_prof_malloc().
	Rename prof_make() as MR_PROF_NEW() and add MR_PROF_NEW_ARRAY().

runtime/mercury_wrapper.h:
	Minor modifications to reflect the new interface to mercury_prof.c.

runtime/mercury_wrapper.c:
runtime/mercury_label.c:
	Rename the old `-p' (primary cache size) option as `-C'.
	Add a new `-p' option to disable profiling.

runtime/Mmakefile:
	Add mercury_heap_profile.[ch].
	Put the list of files in alphabetical order.
	Delete some obsolete stuff for supporting `.mod' files.
	Mention that libmer_dll.h and libmer_globals.h are
	produced by Makefile.DLLs.

runtime/mercury_imp.h:
	Mention that libmer_dll.h is produced by Makefile.DLLs.

runtime/mercury_dummy.c:
	Change a comment to refer to libmer_dll.h rather than
	libmer_globals.h.

compiler/llds.m:
	Add a new field to `create' and `incr_hp' instructions
	holding the name of the type, for heap profiling.

compiler/unify_gen.m:
	Initialize the new field of `create' instructions with
	the appropriate type name.

compiler/llds_out.m:
	Output incr_hp_msg() / tag_incr_hp_msg() instead of
	incr_hp() / tag_incr_hp().

compiler/*.m:
	Minor changes to most files in the compiler back-end to
	accomodate the new field in `incr_hp' and `create' instructions.

library/io.m:
	Add `io__report_full_memory_stats'.

library/benchmarking.m:
	Add `report_full_memory_stats'.  This uses the information saved
	by runtime/mercury_heap_profile.{c,h} to print out a report
	of memory usage by procedures and by types.
	Also modify `report_stats' to print out some of that information.

compiler/mercury_compile.m:
	If `--statistics' is enabled, call io__report_full_memory_stats
	at the end of main/2.  This will print out full memory statistics,
	if the compiler was compiled with memory profiling enabled.

compiler/options.m:
compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/ml.in:
scripts/mgnuc.in:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Add new option `--memory-profiling' and new grade `.memprof'.
	Add `--time-profiling' as a new synonym for `--profiling'.
	Also add `--profile-memory' for more fine-grained control:
	`--memory-profiling' implies both `--profile-memory' and
	`--profile-calls'.

scripts/mprof_merge_runs:
	Update to handle the new format of Prof.Counts and to
	also merge Prof.MemoryWords and Prof.MemoryCells.

profiler/options.m:
profiler/mercury_profile.m:
	Add new options `--profile memory-words' (`-m'),
	`--profile memory-cells' (`-M') and `--profile time' (`-t').
	Thes options make the profiler select a different count file,
	Prof.MemoryWords or Prof.MemoryCells instead of Prof.Counts.
	specific to time profiling.

profiler/read.m:
profiler/process_file.m:
profiler/prof_info.m:
profiler/generate_output.m:
	Update to handle the new format of the counts file.
	When reading the counts file, look at the first line of
	the file to determine what is being profiled.

profiler/globals.m:
	Add a new global variable `what_to_profile' that records
	what is being profiled.

profiler/output.m:
	Change the headings to reflect what is being profiled.

doc/user_guide.texi:
	Document memory profiling.
	Document new options.

doc/user_guide.texi:
compiler/options.m:
	Comment out the documentation for `.proftime'/`--profile-time',
	since doing time and call profiling seperately doesn't work,
	because the code addresses change when you recompile with a
	different grade.  Ditto for `.profmem'/`--profile-memory'.
	Also comment out the documentation for
	`.profcalls'/`--profile-calls', since it is redundant --
	`.memprof' produces the same information and more.

configure.in:
	Build a `.memprof' grade.  (Hmm, should we do this only
	if `--enable-all-grades' is specified?)
	Don't ever build a `.profcalls' grade.
1997-12-05 15:58:34 +00:00

188 lines
6.7 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1995-1997 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: options.m.
% Main author: fjh.
% This defines the stuff necessary so that getopt.m
% can parse the command-line options.
%-----------------------------------------------------------------------------%
:- module options.
:- interface.
:- import_module bool, string, io, getopt.
:- type option
% Verbosity options
---> verbose
; very_verbose
% Profiler options
; dynamic_cg
; call_graph
; profile
; profile_time
; profile_memory_words
; profile_memory_cells
; countfile
; pairfile
; declfile
; libraryfile
% Miscellaneous Options
; help.
:- type option_table == option_table(option).
:- pred short_option(character::in, option::out) is semidet.
:- pred long_option(string::in, option::out) is semidet.
:- pred option_defaults(option::out, option_data::out) is nondet.
:- pred option_default(option::out, option_data::out) is multidet.
:- pred special_handler(option::in, special_data::in,
option_table::in, maybe_option_table(option)::out) is semidet.
:- pred options_help(io__state::di, io__state::uo) is det.
% A couple of misc utilities
:- pred maybe_write_string(bool::input, string::input,
io__state::di, io__state::uo) is det.
:- pred maybe_flush_output(bool::in, io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module std_util, map.
option_defaults(Option, Default) :-
semidet_succeed,
option_default(Option, Default).
% Verbosity Options
option_default(verbose, bool(no)).
option_default(very_verbose, bool(no)).
% General profiler options
option_default(dynamic_cg, bool(no)).
option_default(call_graph, bool(no)).
option_default(profile, string_special).
option_default(profile_time, special).
option_default(profile_memory_words, special).
option_default(profile_memory_cells, special).
option_default(countfile, string("Prof.Counts")).
option_default(pairfile, string("Prof.CallPair")).
option_default(declfile, string("Prof.Decl")).
option_default(libraryfile, string("")).
% Miscellaneous Options
option_default(help, bool(no)).
% please keep this in alphabetic order
short_option('C', countfile).
short_option('c', call_graph).
short_option('d', dynamic_cg).
short_option('D', declfile).
short_option('h', help).
short_option('L', libraryfile).
short_option('m', profile_memory_words).
short_option('M', profile_memory_cells).
short_option('p', profile).
short_option('P', pairfile).
short_option('t', profile_time).
short_option('v', verbose).
short_option('V', very_verbose).
long_option("call-pair-file", pairfile).
long_option("call-graph", call_graph).
long_option("count-file", countfile).
long_option("declaration-file", declfile).
long_option("help", help).
long_option("library-callgraph", help).
long_option("profile", profile).
long_option("profile-memory-words", profile_memory_words).
long_option("profile-memory-cells", profile_memory_cells).
long_option("profile-time", profile_time).
long_option("use-dynamic", dynamic_cg).
long_option("verbose", verbose).
long_option("very-verbose", very_verbose).
special_handler(profile, string(WhatToProfile), OptionTable0, Result)
:-
( valid_profile_option(WhatToProfile, CountFile) ->
map__set(OptionTable0, countfile, string(CountFile),
OptionTable),
Result = ok(OptionTable)
;
Result = error("Invalid argument to `--profile' or `-p' option")
).
special_handler(profile_memory_words, _, OptionTable0, ok(OptionTable)) :-
map__set(OptionTable0, countfile, string("Prof.MemoryWords"),
OptionTable).
special_handler(profile_memory_cells, _, OptionTable0, ok(OptionTable)) :-
map__set(OptionTable0, countfile, string("Prof.MemoryCells"),
OptionTable).
special_handler(profile_time, _, OptionTable0, ok(OptionTable)) :-
map__set(OptionTable0, countfile, string("Prof.Counts"),
OptionTable).
:- pred valid_profile_option(string::in, string::out) is semidet.
valid_profile_option("memory-words", "Prof.MemoryWords").
valid_profile_option("memory-cells", "Prof.MemoryCells").
valid_profile_option("time", "Prof.Counts").
% :- pred special_handler(option::in, special_data::in,
% option_table::in, maybe_option_table::out) is semidet.
options_help -->
io__write_string("\t-h, --help\n"),
io__write_string("\t\tPrint this usage message.\n"),
io__write_string("\nProfiler Options:\n"),
io__write_string("\t-c, --call-graph\n"),
io__write_string("\t\tInclude the call graph profile.\n"),
io__write_string("\t-d, --use-dynamic\n"),
io__write_string("\t\tBuild the call graph dynamically.\n"),
io__write_string("\t-p, --profile {time, memory-words, memory-cells}\n"),
io__write_string("\t\tSelect what to profile: time, amount of memory allocated, or\n"),
io__write_string("\t\tnumber of memory allocations (regardless of size).\n"),
io__write_string("\t-m\n"),
io__write_string("\t\tSame as `--profile memory-words'\n"),
io__write_string("\t-M\n"),
io__write_string("\t\tSame as `--profile memory-cells'.\n"),
io__write_string("\t-t\n"),
io__write_string("\t\tSame as `--profile time'.\n"),
io__write_string("\nFilename Options:\n"),
io__write_string("\t-C <file>, --count-file <file>\n"),
io__write_string("\t\tName of the count file. Usually `Prof.Counts',\n"),
io__write_string("\t\t`Prof.MemoryWords', or `Prof.MemoryCells'.\n"),
io__write_string("\t-D <file>, --declaration-file <file>\n"),
io__write_string("\t\tName of the declaration file. Usually `Prof.Decl'.\n"),
io__write_string("\t-P <file>, --call-pair-file <file>\n"),
io__write_string("\t\tName of the call-pair file. Usually `Prof.CallPair'.\n"),
io__write_string("\t-L <file>, --library-callgraph <file>\n"),
io__write_string("\t\tName of the file which contains the call graph for\n"),
io__write_string("\t\tthe library modules.\n"),
io__write_string("\nVerbosity Options:\n"),
io__write_string("\t-v, --verbose\n"),
io__write_string("\t\tOutput progress messages at each stage.\n"),
io__write_string("\t-V, --very_verbose\n"),
io__write_string("\t\tOutput very verbose progress messages.\n").
%-----------------------------------------------------------------------------%
maybe_write_string(yes, String) --> io__write_string(String).
maybe_write_string(no, _) --> [].
maybe_flush_output(yes) --> io__flush_output.
maybe_flush_output(no) --> [].
:- end_module options.
%-----------------------------------------------------------------------------%