mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 05:44:58 +00:00
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.
236 lines
4.5 KiB
Plaintext
236 lines
4.5 KiB
Plaintext
#---------------------------------------------------------------------------#
|
|
# Copyright (C) 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.
|
|
#---------------------------------------------------------------------------#
|
|
#
|
|
# parse_grade_options.sh-subr:
|
|
# An `sh' subroutine for parsing grade-related options.
|
|
# Used by the `ml' and `mgnuc' scripts.
|
|
#
|
|
# The code here should be inserted in the case statement in a scripts
|
|
# option-parsing loop.
|
|
#
|
|
#---------------------------------------------------------------------------#
|
|
|
|
--asm-labels)
|
|
asm_labels=true ;;
|
|
--no-asm-labels)
|
|
asm_labels=false ;;
|
|
|
|
--gcc-non-local-gotos)
|
|
non_local_gotos=true ;;
|
|
--no-gcc-non-local-gotos)
|
|
non_local_gotos=false ;;
|
|
|
|
--gcc-global-registers)
|
|
global_regs=true ;;
|
|
--no-gcc-global-registers)
|
|
global_regs=false ;;
|
|
|
|
--debug)
|
|
debug=true ;;
|
|
--no-debug)
|
|
debug=false ;;
|
|
|
|
--gc)
|
|
shift
|
|
case "$1" in
|
|
accurate|conservative|none)
|
|
gc_method=$1 ;;
|
|
*)
|
|
echo "$0: invalid gc method \`$1'" 1>&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
|
|
-p|--profiling|--time-profiling)
|
|
profile_time=true
|
|
profile_calls=true
|
|
profile_memory=false
|
|
;;
|
|
--memory-profiling)
|
|
profile_time=false
|
|
profile_calls=true
|
|
profile_memory=true
|
|
;;
|
|
-p-|--no-profiling)
|
|
profile_time=false
|
|
profile_calls=false
|
|
profile_memory=false
|
|
;;
|
|
--profile-time)
|
|
profile_time=true ;;
|
|
--no-profile-time)
|
|
profile_time=false ;;
|
|
--profile-calls)
|
|
profile_calls=true ;;
|
|
--no-profile-calls)
|
|
profile_calls=false ;;
|
|
--profile-memory)
|
|
profile_memory=true ;;
|
|
--no-profile-memory)
|
|
profile_memory=false ;;
|
|
|
|
--use-trail)
|
|
use_trail=true ;;
|
|
--no-use-trail)
|
|
use_trail=false ;;
|
|
|
|
--args)
|
|
shift
|
|
case "$1" in
|
|
simple|compact)
|
|
args_method=$1;;
|
|
*)
|
|
echo "$0: invalid arg method \`$1'" 1>&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
|
|
--pic-reg)
|
|
pic_reg=true ;;
|
|
--no-pic-reg)
|
|
pic_reg=false ;;
|
|
|
|
-s|--grade)
|
|
shift
|
|
grade="$1";
|
|
|
|
# Convert a grade to a set of options.
|
|
#
|
|
# IMPORTANT: any changes to the handling of grades here
|
|
# may also require changes to
|
|
# runtime/mercury_grade.h
|
|
# compiler/handle_options.m
|
|
# scripts/ml.in
|
|
|
|
case "$grade" in
|
|
*.debug)
|
|
debug=true
|
|
grade="` expr $grade : '\(.*\).debug' `"
|
|
;;
|
|
*) debug=false
|
|
;;
|
|
esac
|
|
|
|
case "$grade" in
|
|
*.sa)
|
|
args_method=simple
|
|
grade="` expr $grade : '\(.*\).sa' `"
|
|
;;
|
|
*) args_method=compact
|
|
;;
|
|
esac
|
|
|
|
case "$grade" in
|
|
*.tr) use_trail=true
|
|
grade="` expr $grade : '\(.*\).tr' `"
|
|
;;
|
|
*) use_trail=false
|
|
;;
|
|
esac
|
|
|
|
case "$grade" in
|
|
*.memprof)
|
|
profile_time=false
|
|
profile_calls=true
|
|
profile_memory=true
|
|
grade="` expr $grade : '\(.*\).memprof' `"
|
|
;;
|
|
*.prof)
|
|
profile_time=true
|
|
profile_calls=true
|
|
profile_memory=false
|
|
grade="` expr $grade : '\(.*\).prof' `"
|
|
;;
|
|
*.proftime)
|
|
profile_time=true
|
|
profile_calls=false
|
|
profile_memory=false
|
|
grade="` expr $grade : '\(.*\).proftime' `"
|
|
;;
|
|
*.profcalls)
|
|
profile_time=false
|
|
profile_calls=true
|
|
profile_memory=false
|
|
grade="` expr $grade : '\(.*\).profcalls' `"
|
|
;;
|
|
*.profall)
|
|
profile_time=true
|
|
profile_calls=true
|
|
profile_memory=true
|
|
grade="` expr $grade : '\(.*\).profall' `"
|
|
;;
|
|
*)
|
|
profile_time=false
|
|
profile_calls=false
|
|
profile_memory=false
|
|
;;
|
|
esac
|
|
|
|
case "$grade" in
|
|
*.agc) gc_method=accurate
|
|
grade="` expr $grade : '\(.*\).agc' `"
|
|
;;
|
|
*.gc) gc_method=conservative
|
|
grade="` expr $grade : '\(.*\).gc' `"
|
|
;;
|
|
*) gc_method=none
|
|
;;
|
|
esac
|
|
|
|
case "$grade" in
|
|
asm_fast)
|
|
global_regs=true
|
|
non_local_gotos=true
|
|
asm_labels=true
|
|
;;
|
|
fast)
|
|
global_regs=true
|
|
non_local_gotos=true
|
|
asm_labels=false
|
|
;;
|
|
reg)
|
|
global_regs=true
|
|
non_local_gotos=false
|
|
asm_labels=false
|
|
;;
|
|
asm_jump)
|
|
global_regs=false
|
|
non_local_gotos=true
|
|
asm_labels=true
|
|
;;
|
|
jump)
|
|
global_regs=false
|
|
asm_labels=false
|
|
non_local_gotos=true
|
|
;;
|
|
none)
|
|
global_regs=false
|
|
asm_labels=false
|
|
non_local_gotos=false
|
|
;;
|
|
debug)
|
|
debug=true
|
|
global_regs=false
|
|
asm_labels=false
|
|
non_local_gotos=false
|
|
;;
|
|
*)
|
|
echo "$0: invalid grade \`$grade'" 1>&2;
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
-s*)
|
|
grade="` expr $1 : '-s\(.*\)' `"
|
|
# just insert it as `--grade $grade' and then reparse it
|
|
case $# in
|
|
0) set - "x --grade $grade" ;;
|
|
0) set - "x --grade $grade" "$@" ;;
|
|
esac
|
|
;;
|