[m-rev.] diff: mdprof_feedback improvements.

Paul Bone pbone at csse.unimelb.edu.au
Thu May 13 12:26:53 AEST 2010


mdprof_feedback improvements.

Add an option to mdprof_feedback to print the feedback report without modifying
it.  This option also avoids reading and parsing a Deep.data file, this makes
it quick and convenient if you just wish to view the feedback report.

deep_profiler/mdprof_feedback.m:
    As above,

    These changes make it necessary for the feedback_info structure to store
    the program's name that the feedback is generated for.  mdprof_feedback now
    also checks that the program names in the feedback file, and deep profiling
    data match.

mdbcomp/feedback.m:
    Store the name of the program in the feedback_info structure and provide
    methods to query this.

    read_or_create now takes a new parameter, the name of the program that
    we're creating a feedback file for.  Or if a feedback file already exists,
    the name that is checked against the one in the existing feedback file.

    init_feedback_file now takes a new parameter, the name of the program that
    this feedback_info structure is for.

    These changes haven't changed the format of the feedback file, it always
    contained the program's name.  Therefore the feedback file version number
    has not been incremented.

compiler/globals.m:
    The feedback field in the compiler's globals structure now has the type
    maybe(feedback).  If feedback data couldn't be, or wasn't read then empty
    feedback data is no longer used.

compiler/handle_options.m:
    Conform to changes in mdbcomp/feedback.m and compiler/globals.m.

compiler/implicit_parallelism.m:
    Conform to changes in compiler/globals.m

Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.94
diff -u -p -b -r1.94 globals.m
--- compiler/globals.m	11 Feb 2010 04:36:09 -0000	1.94
+++ compiler/globals.m	1 May 2010 05:38:35 -0000
@@ -188,7 +188,8 @@
     tags_method::in, termination_norm::in, termination_norm::in,
     trace_level::in, trace_suppress_items::in,
     may_be_thread_safe::in, c_compiler_type::in, reuse_strategy::in,
-    maybe(il_version_number)::in, feedback_info::in, globals::out) is det.
+    maybe(il_version_number)::in, maybe(feedback_info)::in, globals::out) 
+    is det.
 
 :- pred get_options(globals::in, option_table::out) is det.
 :- pred get_target(globals::in, compilation_target::out) is det.
@@ -205,7 +206,7 @@
 :- pred get_reuse_strategy(globals::in, reuse_strategy::out) is det.
 :- pred get_maybe_il_version_number(globals::in, maybe(il_version_number)::out)
     is det.
-:- pred get_feedback_info(globals::in, feedback_info::out) is det.
+:- pred get_maybe_feedback_info(globals::in, maybe(feedback_info)::out) is det.
 
 :- pred set_option(option::in, option_data::in, globals::in, globals::out)
     is det.
@@ -214,8 +215,8 @@
 :- pred set_tags_method(tags_method::in, globals::in, globals::out) is det.
 :- pred set_trace_level(trace_level::in, globals::in, globals::out) is det.
 :- pred set_trace_level_none(globals::in, globals::out) is det.
-:- pred set_feedback_info(feedback_info::in, globals::in, globals::out) 
-    is det.
+:- pred set_maybe_feedback_info(maybe(feedback_info)::in, 
+    globals::in, globals::out) is det.
 
 :- pred lookup_option(globals::in, option::in, option_data::out) is det.
 
@@ -481,17 +482,17 @@ gc_is_conservative(gc_automatic) = no.
                 g_c_compiler_type           :: c_compiler_type,
                 g_reuse_strategy            :: reuse_strategy,
                 g_maybe_il_version_number   :: maybe(il_version_number),
-                g_feedback                  :: feedback_info
+                g_maybe_feedback            :: maybe(feedback_info)
             ).
 
 globals_init(Options, Target, GC_Method, TagsMethod,
         TerminationNorm, Termination2Norm, TraceLevel, TraceSuppress,
         MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
-        Feedback, Globals) :-
+        MaybeFeedback, Globals) :-
     Globals = globals(Options, Target, GC_Method, TagsMethod,
         TerminationNorm, Termination2Norm, TraceLevel, TraceSuppress,
         MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
-        Feedback).
+        MaybeFeedback).
 
 get_options(Globals, Globals ^ g_options).
 get_target(Globals, Globals ^ g_target).
@@ -505,7 +506,7 @@ get_maybe_thread_safe(Globals, Globals ^
 get_c_compiler_type(Globals, Globals ^ g_c_compiler_type).
 get_reuse_strategy(Globals, Globals ^ g_reuse_strategy).
 get_maybe_il_version_number(Globals, Globals ^ g_maybe_il_version_number).
-get_feedback_info(Globals, Globals ^ g_feedback).
+get_maybe_feedback_info(Globals, Globals ^ g_maybe_feedback).
 
 get_backend_foreign_languages(Globals, ForeignLangs) :-
     lookup_accumulating_option(Globals, backend_foreign_languages, LangStrs),
@@ -536,8 +537,8 @@ set_trace_level(TraceLevel, !Globals) :-
 set_trace_level_none(!Globals) :-
     !Globals ^ g_trace_level := trace_level_none.
 
-set_feedback_info(Feedback, !Globals) :-
-    !Globals ^ g_feedback := Feedback.
+set_maybe_feedback_info(MaybeFeedback, !Globals) :-
+    !Globals ^ g_maybe_feedback := MaybeFeedback.
 
 lookup_option(Globals, Option, OptionData) :-
     get_options(Globals, OptionTable),
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.347
diff -u -p -b -r1.347 handle_options.m
--- compiler/handle_options.m	11 Feb 2010 04:36:09 -0000	1.347
+++ compiler/handle_options.m	1 May 2010 05:33:53 -0000
@@ -215,13 +215,13 @@ convert_option_table_result_to_globals(o
     check_option_values(OptionTable0, OptionTable, Target, GC_Method,
         TagsMethod, TermNorm, Term2Norm, TraceLevel, TraceSuppress,
         MaybeThreadSafe, C_CompilerType, ReuseStrategy, MaybeILVersion,
-        FeedbackInfo, [], CheckErrors, !IO),
+        MaybeFeedbackInfo, [], CheckErrors, !IO),
     (
         CheckErrors = [],
         convert_options_to_globals(OptionTable, Target, GC_Method,
             TagsMethod, TermNorm, Term2Norm, TraceLevel,
             TraceSuppress, MaybeThreadSafe, C_CompilerType, ReuseStrategy,
-            MaybeILVersion, FeedbackInfo, [], Errors, Globals, !IO)
+            MaybeILVersion, MaybeFeedbackInfo, [], Errors, Globals, !IO)
     ;
         CheckErrors = [_ | _],
         Errors = CheckErrors,
@@ -233,12 +233,12 @@ convert_option_table_result_to_globals(o
     termination_norm::out, termination_norm::out, trace_level::out,
     trace_suppress_items::out, may_be_thread_safe::out,
     c_compiler_type::out, reuse_strategy::out, maybe(il_version_number)::out,
-    feedback_info::out, list(string)::in, list(string)::out,
+    maybe(feedback_info)::out, list(string)::in, list(string)::out,
     io::di, io::uo) is det.
 
 check_option_values(!OptionTable, Target, GC_Method, TagsMethod,
         TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
-        C_CompilerType, ReuseStrategy, MaybeILVersion, FeedbackInfo,
+        C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
         !Errors, !IO) :-
     map.lookup(!.OptionTable, target, Target0),
     (
@@ -446,16 +446,17 @@ check_option_values(!OptionTable, Target
     ->
         read_feedback_file(FeedbackFile, FeedbackReadResult, !IO),
         (
-            FeedbackReadResult = ok(FeedbackInfo)
+            FeedbackReadResult = ok(FeedbackInfo),
+            MaybeFeedbackInfo = yes(FeedbackInfo)
         ;
             FeedbackReadResult = error(Error),
             read_error_message_string(FeedbackFile, Error, ErrorMessage),
             add_error(ErrorMessage, !Errors),
-            FeedbackInfo = init_feedback_info
+            MaybeFeedbackInfo = no
         )
     ;
         % No feedback info.
-        FeedbackInfo = init_feedback_info
+        MaybeFeedbackInfo = no
     ). 
         
 :- pred add_error(string::in, list(string)::in, list(string)::out) is det.
@@ -471,16 +472,16 @@ add_error(Error, Errors0, Errors) :-
     compilation_target::in, gc_method::in, tags_method::in,
     termination_norm::in, termination_norm::in, trace_level::in,
     trace_suppress_items::in, may_be_thread_safe::in, c_compiler_type::in,
-    reuse_strategy::in, maybe(il_version_number)::in, feedback_info::in,
+    reuse_strategy::in, maybe(il_version_number)::in, maybe(feedback_info)::in,
     list(string)::in, list(string)::out, globals::out, io::di, io::uo) is det.
 
 convert_options_to_globals(OptionTable0, Target, GC_Method, TagsMethod0,
         TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
-        C_CompilerType, ReuseStrategy, MaybeILVersion, FeedbackInfo,
+        C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
         !Errors, !:Globals, !IO) :-
     globals_init(OptionTable0, Target, GC_Method, TagsMethod0,
         TermNorm, Term2Norm, TraceLevel, TraceSuppress, MaybeThreadSafe,
-        C_CompilerType, ReuseStrategy, MaybeILVersion, FeedbackInfo,
+        C_CompilerType, ReuseStrategy, MaybeILVersion, MaybeFeedbackInfo,
         !:Globals),
 
     globals.lookup_string_option(!.Globals, event_set_file_name,
Index: compiler/implicit_parallelism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/implicit_parallelism.m,v
retrieving revision 1.16
diff -u -p -b -r1.16 implicit_parallelism.m
--- compiler/implicit_parallelism.m	30 Apr 2010 13:09:53 -0000	1.16
+++ compiler/implicit_parallelism.m	1 May 2010 05:43:52 -0000
@@ -100,9 +100,10 @@ apply_implicit_parallelism_transformatio
 
 apply_new_implicit_parallelism_transformation(ModuleInfo0, MaybeModuleInfo) :-
     module_info_get_globals(ModuleInfo0, Globals0),
-    globals.get_feedback_info(Globals0, FeedbackInfo),
+    globals.get_maybe_feedback_info(Globals0, MaybeFeedbackInfo),
     module_info_get_name(ModuleInfo0, ModuleName),
     (
+        yes(FeedbackInfo) = MaybeFeedbackInfo,
         get_implicit_parallelism_feedback(ModuleName, FeedbackInfo,
             ParallelismInfo)
     ->
@@ -647,8 +648,8 @@ construct_call_site_kind("callback",    
 
 apply_old_implicit_parallelism_transformation(ModuleInfo0, MaybeModuleInfo) :-
     module_info_get_globals(ModuleInfo0, Globals),
-    globals.get_feedback_info(Globals, FeedbackInfo),
     (
+        globals.get_maybe_feedback_info(Globals, yes(FeedbackInfo)),
         FeedbackData = feedback_data_calls_above_threshold_sorted(_, _, _),
         get_feedback_data(FeedbackInfo, FeedbackData)
     ->
Index: deep_profiler/mdprof_feedback.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/mdprof_feedback.m,v
retrieving revision 1.21
diff -u -p -b -r1.21 mdprof_feedback.m
--- deep_profiler/mdprof_feedback.m	30 Apr 2010 13:09:54 -0000	1.21
+++ deep_profiler/mdprof_feedback.m	13 May 2010 02:13:41 -0000
@@ -80,6 +80,22 @@ main(!IO) :-
         ->
             write_help_message(ProgName, !IO)
         ;
+            Args = [OutputFileName]
+        ->
+            feedback.read_feedback_file(OutputFileName, FeedbackReadResult,
+                !IO),
+            (
+                FeedbackReadResult = ok(Feedback),
+                ProfileProgName = get_feedback_program_name(Feedback),
+                print_feedback_report(ProfileProgName, Feedback, !IO)
+            ;
+                FeedbackReadResult = error(FeedbackReadError),
+                feedback.read_error_message_string(OutputFileName,
+                    FeedbackReadError, Message),
+                io.write_string(Stderr, Message, !IO),
+                io.set_exit_status(1, !IO)
+            )
+        ;
             Args = [InputFileName, OutputFileName],
             check_options(Options, RequestedFeedbackInfo),
             check_verbosity_option(Options, VerbosityLevel)
@@ -87,13 +103,13 @@ main(!IO) :-
             read_deep_file(InputFileName, DebugReadProfile, MaybeDeep, !IO),
             (
                 MaybeDeep = ok(Deep),
-                feedback.read_or_create(OutputFileName, FeedbackReadResult,
-                    !IO),
+                ProfileProgName = Deep ^ profile_stats ^ program_name, 
+                feedback.read_or_create(OutputFileName, ProfileProgName,
+                    FeedbackReadResult, !IO),
                 (
                     FeedbackReadResult = ok(Feedback0),
                     process_deep_to_feedback(RequestedFeedbackInfo,
                         Deep, Messages, Feedback0, Feedback),
-                    ProfileProgName = Deep ^ profile_stats ^ program_name,
                     (
                         Report = yes,
                         print_feedback_report(ProfileProgName, Feedback, !IO)
@@ -185,6 +201,15 @@ create_feedback_report(feedback_data_can
 
 help_message =
 "Usage: %s [<options>] <input> <output>
+       %s <output>
+       %s --help
+       %s --version
+
+    The first form of this command generates feedback information from
+    profiling data.  The second form prints a report of the feedback data and
+    does not modify it.  The third and forth forms print this help message and
+    version information respectively.
+
     <input> must name a deep profiling data file.
     <output> is the name of the file to be generated by this program.
 
Index: mdbcomp/feedback.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/feedback.m,v
retrieving revision 1.9
diff -u -p -b -r1.9 feedback.m
--- mdbcomp/feedback.m	30 Apr 2010 13:09:54 -0000	1.9
+++ mdbcomp/feedback.m	13 May 2010 02:15:20 -0000
@@ -311,6 +311,10 @@
 :- pred get_all_feedback_data(feedback_info::in, list(feedback_data)::out)
     is det.
 
+    % Get the name of the program that generated this feedback information.
+    %
+:- func get_feedback_program_name(feedback_info) = string.
+
 %-----------------------------------------------------------------------------%
 
     % read_feedback_file(Path, FeedbackInfo, !IO)
@@ -329,13 +333,16 @@
     --->    open_error(io.error)
     ;       read_error(io.error)
     ;       parse_error(
-                message     :: string,
-                line_no     :: int
+                fre_pe_message          :: string,
+                fre_pe_line_no          :: int
             )
     ;       unexpected_eof
     ;       incorrect_version
     ;       incorrect_first_line
-    ;       incorrect_program_name.
+    ;       incorrect_program_name(
+                fre_ipn_expected        :: string,
+                fre_ipn_got             :: string
+            ).
 
 %-----------------------------------------------------------------------------%
 
@@ -348,19 +355,25 @@
 
 %-----------------------------------------------------------------------------%
 
+    % read_or_create(Path, ProgramName, Result, !IO).
+    %
     % Try to read in a feedback file, if the file doesn't exist create a new
     % empty feedback state in memory.
     %
-:- pred read_or_create(string::in, feedback_read_result(feedback_info)::out,
-    io::di, io::uo) is det.
+    % ProgramName is the name of the program that generated this feedback file.
+    % It is used to set this information for new feedback files or to verify
+    % that the name in an existing file matches what was expected.
+    %
+:- pred read_or_create(string::in, string::in,
+    feedback_read_result(feedback_info)::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 
-    % init_feedback_info = FeedbackInfo
+    % init_feedback_info(ProgramName) = FeedbackInfo
     %
     % Create a new empty feedback info structure.
     %
-:- func init_feedback_info = feedback_info.
+:- func init_feedback_info(string) = feedback_info.
 
 %-----------------------------------------------------------------------------%
 
@@ -394,6 +407,7 @@
 
 :- type feedback_info
     --->    feedback_info(
+                fi_program_name                 :: string,
                 fi_map                          :: map(feedback_type, 
                                                     feedback_data)
                     % The actual feedback data as read from the feedback file.
@@ -427,6 +441,8 @@ get_feedback_data(Info, Data) :-
 get_all_feedback_data(Info, AllData) :-
     map.values(Info ^ fi_map, AllData).
 
+get_feedback_program_name(Info) = Info ^ fi_program_name.
+
 %-----------------------------------------------------------------------------%
 
 put_feedback_data(Data, !Info) :-
@@ -476,7 +492,7 @@ read_feedback_file(Path, ReadResultFeedb
                 read_check_line(feedback_version, incorrect_version, Stream),
                 !Result, !IO),
             maybe_read(
-                read_no_check_line(Stream),
+                read_program_name(Stream),
                 !Result, !IO),
             maybe_read(read_data(Stream), !Result, !IO),
             ReadResultFeedbackInfo = !.Result
@@ -550,17 +566,33 @@ read_no_check_line(Stream, _, Result, !I
         Result = error(read_error(Error))
     ).
 
+:- pred read_program_name(io.input_stream::in, unit::in,
+    feedback_read_result(string)::out, io::di, io::uo) is det.
+
+read_program_name(Stream, _, Result, !IO) :-
+    io.read_line_as_string(Stream, IOResultLine, !IO),
+    (
+        IOResultLine = ok(String),
+        Result = ok(String)
+    ;
+        IOResultLine = eof,
+        Result = error(unexpected_eof)
+    ;
+        IOResultLine = error(Error),
+        Result = error(read_error(Error))
+    ).
+
     % Read the feedback data from the file.
     %
-:- pred read_data(io.input_stream::in, unit::in,
+:- pred read_data(io.input_stream::in, string::in,
     feedback_read_result(feedback_info)::out, io::di, io::uo) is det.
 
-read_data(Stream, _, Result, !IO) :-
+read_data(Stream, ProgramName, Result, !IO) :-
     io.read(Stream, ReadResultDataAssocList, !IO),
     (
         ReadResultDataAssocList = ok(DataList),
         list.foldl(det_insert_feedback_data, DataList, map.init, Map),
-        Result = ok(feedback_info(Map))
+        Result = ok(feedback_info(ProgramName, Map))
     ;
         ReadResultDataAssocList = eof,
         Result = error(unexpected_eof)
@@ -578,26 +610,32 @@ det_insert_feedback_data(Data, !Map) :-
 
 %-----------------------------------------------------------------------------%
 
-read_or_create(Path, ReadResultFeedback, !IO) :-
+read_or_create(Path, ExpectedProgName, ReadResultFeedback, !IO) :-
     read_feedback_file(Path, ReadResultFeedback1, !IO),
     (
-        ReadResultFeedback1 = ok(_),
+        ReadResultFeedback1 = ok(Feedback),
+        GotProgName = get_feedback_program_name(Feedback),
+        ( ExpectedProgName = GotProgName ->
         ReadResultFeedback = ReadResultFeedback1
     ;
+            ReadResultFeedback = error(
+                incorrect_program_name(ExpectedProgName, GotProgName))
+        )
+    ;
         ReadResultFeedback1 = error(Error),
         (
             % XXX: Assume that an open error is probably caused by the file not
             % existing, (but we can't be sure because io.error is a string
             % internally, and error messages may change and are not portable).
             Error = open_error(_),
-            ReadResultFeedback = ok(init_feedback_info)
+            ReadResultFeedback = ok(init_feedback_info(ExpectedProgName))
         ;
             ( Error = read_error(_)
             ; Error = parse_error(_, _)
             ; Error = unexpected_eof
             ; Error = incorrect_version
             ; Error = incorrect_first_line
-            ; Error = incorrect_program_name
+            ; Error = incorrect_program_name(_, _)
             ),
             ReadResultFeedback = ReadResultFeedback1
         )
@@ -624,9 +662,10 @@ read_error_message_string(File, Error, M
         Error = incorrect_first_line,
         MessagePart = "Incorrect file format"
     ;
-        Error = incorrect_program_name,
+        Error = incorrect_program_name(Expected, Got),
         MessagePart =
-            "Program name didn't match, is this the right feedback file?"
+            "Program name didn't match, is this the right feedback file?\n"
+            ++ format("Expected: %s Got: %s", [s(Expected), s(Got)])
     ),
     string.format("%s: %s\n", [s(File), s(MessagePart)], Message).
 
@@ -641,7 +680,7 @@ display_read_error(File, Error, !IO) :-
 
 %-----------------------------------------------------------------------------%
 
-init_feedback_info = feedback_info(map.init).
+init_feedback_info(ProgramName) = feedback_info(ProgramName, map.init).
 
 %-----------------------------------------------------------------------------%
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20100513/d5bd08ed/attachment.sig>


More information about the reviews mailing list