[m-rev.] for review: dumping trace counts

Zoltan Somogyi zs at csse.unimelb.edu.au
Mon Oct 2 11:40:09 AEST 2006


On 26-Sep-2006, Ian MacLarty <maclarty at csse.unimelb.edu.au> wrote:
> If we move all benchmarking preds to benchmarking then we should remove
> the io -> benchmarking dependency (?).

I have put the predicate in benchmarking.m. The updated diff follows.

Zoltan.

library/benchmarking.m:
	Add a mechanism for dumping out trace counts at selected stages.

compiler/options.m:
doc/user_guide.texi:
	Add an option, --dump-trace-counts, to dump out trace counts at
	selected stages. The selection is indicated the same way as with
	the --dump-hlds option.

compiler/handle_options.m:
	Make --dump-trace-counts, as well as --dump-hlds, imply compilation by
	phases. Without this, stage numbers referring to the code generator
	would be ineffective (since the selected stage of the HLDS would
	never exist for all procedures at once).

compiler/mercury_compile.m:
	Dump the trace counts file when the option calls for it.

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/handle_options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.273
diff -u -b -r1.273 handle_options.m
--- compiler/handle_options.m	10 Sep 2006 23:38:59 -0000	1.273
+++ compiler/handle_options.m	2 Oct 2006 01:14:32 -0000
@@ -857,10 +857,10 @@
             DebugLiveness >= 0,
             convert_dump_alias("all", AllDumpOptions)
         ->
-                % Programmers only enable --debug-liveness if they are
-                % interested in the goal annotations put on goals by
-                % the various phases of the liveness pass. The default
-                % dump options do not print these annotations.
+            % Programmers only enable --debug-liveness if they are interested
+            % in the goal annotations put on goals by the various phases
+            % of the liveness pass. The default dump options do not print
+            % these annotations.
             globals.lookup_string_option(!.Globals, dump_hlds_options,
                 DumpOptions0),
             string.append(DumpOptions0, AllDumpOptions, DumpOptions1),
@@ -1388,13 +1388,17 @@
 
         % --dump-hlds, --statistics, --parallel-liveness and
         % --parallel-code-gen require compilation by phases
-        globals.lookup_accumulating_option(!.Globals, dump_hlds, DumpStages),
+        globals.lookup_accumulating_option(!.Globals, dump_hlds,
+            DumpHLDSStages),
+        globals.lookup_accumulating_option(!.Globals, dump_trace_counts,
+            DumpTraceStages),
         globals.lookup_bool_option(!.Globals, parallel_liveness,
             ParallelLiveness),
         globals.lookup_bool_option(!.Globals, parallel_code_gen,
             ParallelCodeGen),
         (
-            ( DumpStages = [_ | _]
+            ( DumpHLDSStages = [_ | _]
+            ; DumpTraceStages = [_ | _]
             ; Statistics = yes
             ; ParallelLiveness = yes
             ; ParallelCodeGen = yes
@@ -1405,8 +1409,8 @@
             true
         ),
 
-        % If we are doing type-specialization, we may as well take
-        % advantage of the declarations supplied by the programmer.
+        % If we are doing type-specialization, we may as well take advantage
+        % of the declarations supplied by the programmer.
         option_implies(type_specialization, user_guided_type_specialization,
             bool(yes), !Globals),
 
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.405
diff -u -b -r1.405 mercury_compile.m
--- compiler/mercury_compile.m	25 Sep 2006 18:31:28 -0000	1.405
+++ compiler/mercury_compile.m	2 Oct 2006 01:09:41 -0000
@@ -4599,9 +4599,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),
@@ -4617,7 +4620,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)
@@ -4627,6 +4629,25 @@
             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,
+        write_out_trace_counts(DumpFileName, MaybeTraceCountsError, !IO),
+        (
+            MaybeTraceCountsError = no,
+            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)
+        ;
+            MaybeTraceCountsError = yes(TraceCountsError),
+            io.write_string("% ", !IO),
+            io.write_string(TraceCountsError, !IO),
+            io.nl(!IO),
+            io.flush_output(!IO)
+        )
     ;
         true
     ).
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.530
diff -u -b -r1.530 options.m
--- compiler/options.m	26 Sep 2006 03:53:14 -0000	1.530
+++ compiler/options.m	26 Sep 2006 04:21:29 -0000
@@ -213,6 +213,7 @@
     ;       auto_comments
     ;       frameopt_comments
     ;       show_dependency_graph
+    ;       dump_trace_counts
     ;       dump_hlds
     ;       dump_hlds_pred_id
     ;       dump_hlds_alias
@@ -970,6 +971,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(""),
@@ -1695,6 +1697,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).
@@ -3186,6 +3189,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>'.",
@@ -3194,7 +3204,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
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.493
diff -u -b -r1.493 user_guide.texi
--- doc/user_guide.texi	25 Sep 2006 08:00:38 -0000	1.493
+++ doc/user_guide.texi	2 Oct 2006 01:21:31 -0000
@@ -6101,6 +6101,20 @@
 @findex --show-dependency-graph
 Write out the dependency graph to @var{module}.dependency_graph.
 
+ at c @sp 1
+ at c @item -d @var{stage}
+ at c @itemx --dump-trace-counts @var{stage}
+ at c @findex --dump-trace-counts
+ at c tIf the compiler was compiled with debugging enabled
+ at c and is being run with trace counting enabled,
+ at c write out the trace counts file after the specified stage to
+ at c @file{@var{module}.trace_counts. at var{num}- at var{name}}.
+ at c Stage numbers range from 1 to 599; not all stage numbers are valid.
+ at c If a stage number is followed by a plus sign,
+ at c all stages after the given stage will be dumped as well.
+ at c The special stage name @samp{all} causes the dumping of all stages.
+ at c Multiple dump options accumulate.
+
 @sp 1
 @item -d @var{stage}
 @itemx --dump-hlds @var{stage}
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
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.72
diff -u -b -r1.72 benchmarking.m
--- library/benchmarking.m	30 Sep 2006 17:10:38 -0000	1.72
+++ library/benchmarking.m	2 Oct 2006 01:09:43 -0000
@@ -8,7 +8,7 @@
 % 
 % File: benchmarking.m.
 % Main author: zs.
-% Stability: medium to high.
+% Stability: medium.
 % 
 % This module contains predicates that deal with the CPU time requirements
 % of (various parts of) the program.
@@ -20,6 +20,7 @@
 :- interface.
 
 :- import_module io.
+:- import_module maybe.
 
     % `report_stats' is a non-logical procedure intended for use in profiling
     % the performance of a program. It has the side-effect of reporting
@@ -70,7 +71,6 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-    %
     % Turn off or on the collection of all profiling statistics.
     %
 :- pred turn_off_profiling(io::di, io::uo) is det.
@@ -79,7 +79,6 @@
 :- impure pred turn_off_profiling is det.
 :- impure pred turn_on_profiling is det.
 
-    %
     % Turn off or on the collection of call graph profiling statistics.
     %
 :- pred turn_off_call_profiling(io::di, io::uo) is det.
@@ -88,7 +87,6 @@
 :- impure pred turn_off_call_profiling is det.
 :- impure pred turn_on_call_profiling is det.
 
-    %
     % Turn off or on the collection of time spent in each procedure
     % profiling statistics.
     %
@@ -98,7 +96,6 @@
 :- impure pred turn_off_time_profiling is det.
 :- impure pred turn_on_time_profiling is det.
 
-    %
     % Turn off or on the collection of memory allocated in each procedure
     % profiling statistics.
     %
@@ -111,9 +108,24 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
+    % write_out_trace_counts(FileName, MaybeErrorMsg, !IO):
+    %
+    % Write out the trace counts accumulated so far in this program's execution
+    % to FileName. If successful, set MaybeErrorMsg to "no". If unsuccessful,
+    % e.g. because the program wasn't compiled with debugging enabled or
+    % because trace counting isn't turned on, then set MaybeErrorMsg to a "yes"
+    % wrapper around an error message.
+    %
+:- pred write_out_trace_counts(string::in, maybe(string)::out,
+    io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
 :- implementation.
 
 :- import_module int.
+:- import_module string.
 
 %-----------------------------------------------------------------------------%
 
@@ -1056,4 +1068,52 @@
 ").
 
 %-----------------------------------------------------------------------------%
+
+write_out_trace_counts(DumpFileName, MaybeErrorMsg, !IO) :-
+    dump_trace_counts_to(DumpFileName, Result, !IO),
+    ( Result = 0 ->
+        MaybeErrorMsg = no
+    ; Result = 1 ->
+        MaybeErrorMsg = yes("Couldn't dump trace counts to `" ++
+            DumpFileName ++ "': no compiled with debugging")
+    ; Result = 2 ->
+        MaybeErrorMsg = yes("Couldn't dump trace counts to `" ++
+            DumpFileName ++ "': trace counting not turned on")
+    ; Result = 3 ->
+        MaybeErrorMsg = yes("Couldn't dump trace counts to `" ++
+            DumpFileName ++ "': couldn't open file")
+    ;
+        MaybeErrorMsg = yes("Couldn't dump trace counts to `" ++
+            DumpFileName ++ "'")
+    ).
+
+:- 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_progname, 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).
+
 %-----------------------------------------------------------------------------%
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