[m-rev.] for review: dumping trace counts
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon Sep 25 13:25:27 AEST 2006
For review by anyone.
Question for reviewers: should the dump_trace_counts_to predicate be moved
to a library module to make it available to other programs, and if so, which
one and with what name?
BTW, this is the situation that mtc_diff was created for: the diff the
trace counts of two stages, to get a performance profile of the code
executed in between.
Zoltan.
compiler/mercury_compile.m:
Add a mechanism for dumping out trace counts at selected stages.
cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.404
diff -u -r1.404 mercury_compile.m
--- compiler/mercury_compile.m 20 Sep 2006 09:42:06 -0000 1.404
+++ compiler/mercury_compile.m 20 Sep 2006 09:44:32 -0000
@@ -4597,9 +4597,12 @@
dump_info::in, dump_info::out, io::di, io::uo) is det.
maybe_dump_hlds(HLDS, StageNum, StageName, !DumpInfo, !IO) :-
- globals.io_lookup_accumulating_option(dump_hlds, DumpStages, !IO),
+ globals.io_lookup_bool_option(verbose, Verbose, !IO),
+ globals.io_lookup_accumulating_option(dump_hlds, DumpHLDSStages, !IO),
+ globals.io_lookup_accumulating_option(dump_trace_counts, DumpTraceStages,
+ !IO),
StageNumStr = stage_num_str(StageNum),
- ( should_dump_stage(StageNum, StageNumStr, StageName, DumpStages) ->
+ ( should_dump_stage(StageNum, StageNumStr, StageName, DumpHLDSStages) ->
module_info_get_name(HLDS, ModuleName),
module_name_to_file_name(ModuleName, ".hlds_dump", yes, BaseFileName,
!IO),
@@ -4615,7 +4618,6 @@
"to the stage in " ++ PrevDumpFileName ++ ".\n", !IO),
io.close_output(FileStream, !IO)
;
- globals.io_lookup_bool_option(verbose, Verbose, !IO),
maybe_write_string(Verbose, "\n", !IO),
Msg = "can't open file `" ++ DumpFileName ++ "' for output.",
report_error(Msg, !IO)
@@ -4625,10 +4627,71 @@
CurDumpFileName = DumpFileName
),
!:DumpInfo = prev_dumped_hlds(CurDumpFileName, HLDS)
+ ; should_dump_stage(StageNum, StageNumStr, StageName, DumpTraceStages) ->
+ module_info_get_name(HLDS, ModuleName),
+ module_name_to_file_name(ModuleName, ".trace_counts", yes,
+ BaseFileName, !IO),
+ DumpFileName = BaseFileName ++ "." ++ StageNumStr ++ "-" ++ StageName,
+ dump_trace_counts_to(DumpFileName, Result, !IO),
+ ( Result = 0 ->
+ maybe_write_string(Verbose, "% Dumped trace counts to `", !IO),
+ maybe_write_string(Verbose, DumpFileName, !IO),
+ maybe_write_string(Verbose, "'\n", !IO),
+ maybe_flush_output(Verbose, !IO)
+ ; Result = 1 ->
+ io.write_string("% Couldn't dump trace counts to `", !IO),
+ io.write_string(DumpFileName, !IO),
+ io.write_string("': no compiled with debugging\n", !IO),
+ io.flush_output(!IO)
+ ; Result = 2 ->
+ io.write_string("% Couldn't dump trace counts to `", !IO),
+ io.write_string(DumpFileName, !IO),
+ io.write_string("': trace counting not turned on\n", !IO),
+ io.flush_output(!IO)
+ ; Result = 3 ->
+ io.write_string("% Couldn't dump trace counts to `", !IO),
+ io.write_string(DumpFileName, !IO),
+ io.write_string("': couldn't open file\n", !IO),
+ io.flush_output(!IO)
+ ;
+ io.write_string("% Couldn't dump trace counts to `", !IO),
+ io.write_string(DumpFileName, !IO),
+ io.write_string("'\n", !IO),
+ io.flush_output(!IO)
+ )
;
true
).
+:- pred dump_trace_counts_to(string::in, int::out, io::di, io::uo) is det.
+
+:- pragma foreign_proc("C",
+ dump_trace_counts_to(FileName::in, Result::out, _IO0::di, _IO::uo),
+ [will_not_call_mercury, promise_pure],
+"
+#ifdef MR_EXEC_TRACE
+ FILE *fp;
+
+ if (MR_trace_count_enabled && MR_trace_func_enabled) {
+ fp = fopen(FileName, ""w"");
+ if (fp != NULL) {
+ MR_trace_write_label_exec_counts(fp, MR_FALSE);
+ Result = 0;
+ (void) fclose(fp);
+ } else {
+ Result = 3;
+ }
+ } else {
+ Result = 2;
+ }
+#else
+ Result = 1;
+#endif
+").
+
+% Default definition for non-C backends.
+dump_trace_counts_to(_, 1, !IO).
+
:- func stage_num_str(int) = string.
stage_num_str(StageNum) = StageNumStr :-
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.528
diff -u -r1.528 options.m
--- compiler/options.m 18 Sep 2006 03:16:28 -0000 1.528
+++ compiler/options.m 18 Sep 2006 03:18:51 -0000
@@ -205,6 +205,7 @@
; auto_comments
; frameopt_comments
; show_dependency_graph
+ ; dump_trace_counts
; dump_hlds
; dump_hlds_pred_id
; dump_hlds_alias
@@ -961,6 +962,7 @@
auto_comments - bool(no),
frameopt_comments - bool(no),
show_dependency_graph - bool(no),
+ dump_trace_counts - accumulating([]),
dump_hlds - accumulating([]),
dump_hlds_pred_id - int(-1),
dump_hlds_alias - string(""),
@@ -1685,6 +1687,7 @@
long_option("auto-comments", auto_comments).
long_option("frameopt-comments", frameopt_comments).
long_option("show-dependency-graph", show_dependency_graph).
+long_option("dump-trace-counts", dump_trace_counts).
long_option("dump-hlds", dump_hlds).
long_option("hlds-dump", dump_hlds).
long_option("dump-hlds-pred-id", dump_hlds_pred_id).
@@ -3158,6 +3161,13 @@
"\tuse the `--no-llds-optimize' option.)",
"--show-dependency-graph",
"\tWrite out the dependency graph to `<module>.dependency_graph'.",
+% This option is for developers only.
+% "--dump-trace-counts <stage number or name>",
+% "\tIf the compiler was compiled with debugging enabled and is being",
+% "\trun with trace counting enabled, write out the trace counts file",
+% "\tafter the specified stage to `<module>.trace_counts.<num>-<name>'.",
+% "\tStage numbers range from 1-599.",
+% "\tMultiple dump options accumulate.",
"-d <n>, --dump-hlds <stage number or name>",
"\tDump the HLDS (high level intermediate representation) after",
"\tthe specified stage to `<module>.hlds_dump.<num>-<name>'.",
@@ -3166,7 +3176,7 @@
"--dump-hlds-pred-id <n>",
"\tDump the HLDS only of the predicate/function with the given",
"\tpred id.",
-% This option is for developers only
+% This option is for developers only.
% "-D, --dump-hlds-alias <dump-alias>",
% "\tWith `--dump-hlds', include extra detail in the dump.",
% "\tEach dump alias is shorthand for a set of option letters.",
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list