[m-rev.] for review: mslice/mdice output format improvement

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Nov 24 15:36:22 AEDT 2006


After this diff, the default output format of mslice looks like this extract:

pred lr1.add_starting_nt_look_pairs/9-0 
                                    CALL         lr1.m:401            14,592,242
pred lr1.add_starting_nt_look_pairs/9-0 
                                    EXIT         lr1.m:401            14,592,242
pred lr1.add_starting_nt_look_pairs/9-0 
                                    <c2;?;>      lr1.m:406            14,592,242
pred set_tree234.fold/4-0           <s1;>        set_tree234.m:1889   14,311,079
pred lr1.move_over_symbol/4-0       CALL         lr1.m:484            14,089,152

which in my opinion is an improvement over output in which all lines are
longer than 80 columns. The old format is still available through command
line options.

Zoltan.

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
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.499
diff -u -b -r1.499 user_guide.texi
--- doc/user_guide.texi	24 Nov 2006 03:48:15 -0000	1.499
+++ doc/user_guide.texi	24 Nov 2006 03:51:42 -0000
@@ -4963,7 +4963,7 @@
 
 The mslice tool is invoked using a command of the form:
 @example
-mslice [-s sortspec] [-l N] [-m module] file
+mslice [-s sortspec] [-l N] [-m module] [-n N] [-p N] [-f N] file
 @end example
 @sp 1
 where @samp{file} is a trace count file,
@@ -4987,11 +4987,25 @@
 If the counts for two or more events are the same,
 then those events will be sorted by number of runs in descending order.
 @sp 1
+The default is to sort descending on the Count column.
+ at sp 1
 The @samp{-l} or @samp{--limit} option limits the output to @samp{N} lines.
 @sp 1
 The @samp{-m} or @samp{--module} option limits the output
 to events only from the given module.
 @sp 1
+The @samp{-n} or @samp{--max-name-column} option's argument
+gives the maximum width of the column containing predicate names.
+If the argument is zero, there is no maximum width.
+ at sp 1
+The @samp{-p} or @samp{--max-path-column} option's argument
+gives the maximum width of the column containing ports and goal paths.
+If the argument is zero, there is no maximum width.
+ at sp 1
+The @samp{-f} or @samp{--max-file-column} option's argument
+gives the maximum width of the column containing file names and line numbers.
+If the argument is zero, there is no maximum width.
+ at sp 1
 
 @node Dicing
 @subsection Dicing
@@ -5056,7 +5070,7 @@
 The @samp{mdice} tool is invoked with a command of the form:
 @sp 1
 @example
-mdice [-s sortspec] [-l N] [-m module] passfile failfile
+mdice [-s sortspec] [-l N] [-m module] [-n N] [-p N] [-f N] passfile failfile
 @end example
 @samp{passfile} is a trace count file,
 generated either directly by a passing program run
@@ -5086,12 +5100,25 @@
 and if any two suspicions are the same,
 then by number of executions in the failing run(s), also in descending order.
 @sp 1
+The default is to sort descending on the Suspicion column.
+ at sp 1
 The option @samp{-l} or @samp{--limit}
 can be used to limit the number of lines displayed.
 @sp 1
 The @samp{-m} or @samp{--module} option
 limits the output to the given module and any submodules.
-
+ at sp 1
+The @samp{-n} or @samp{--max-name-column} option's argument
+gives the maximum width of the column containing predicate names.
+If the argument is zero, there is no maximum width.
+ at sp 1
+The @samp{-p} or @samp{--max-path-column} option's argument
+gives the maximum width of the column containing ports and goal paths.
+If the argument is zero, there is no maximum width.
+ at sp 1
+The @samp{-f} or @samp{--max-file-column} option's argument
+gives the maximum width of the column containing file names and line numbers.
+If the argument is zero, there is no maximum width.
 @sp 1
 
 @node Coverage testing
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
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/fixed
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/log4m
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/mopenssl
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/net
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/string.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.251
diff -u -b -r1.251 string.m
--- library/string.m	23 Oct 2006 00:33:01 -0000	1.251
+++ library/string.m	24 Nov 2006 03:55:19 -0000
@@ -23,9 +23,11 @@
 :- module string.
 :- interface.
 
+:- import_module assoc_list.
 :- import_module char.
 :- import_module deconstruct.
 :- import_module list.
+:- import_module maybe.
 :- import_module ops.
 
 %-----------------------------------------------------------------------------%
@@ -721,6 +723,12 @@
     %
 :- func string.format_table(list(justified_column), string) = string.
 
+    % format_table_max(Columns, Separator) does the same job as format_table,
+    % but allows the caller to associate an maximum width with each column.
+    %
+:- func string.format_table_max(assoc_list(justified_column, maybe(int)),
+    string) = string.
+
 :- type justified_column
     --->    left(list(string))
     ;       right(list(string)).
@@ -753,6 +761,7 @@
 :- import_module int.
 :- import_module integer.
 :- import_module maybe.
+:- import_module pair.
 :- import_module require.
 :- import_module std_util.
 :- import_module type_desc.
@@ -1480,8 +1489,7 @@
 %-----------------------------------------------------------------------------%
 
     % NOTE: string.hash is also defined as MR_hash_string in 
-    %       runtime/mercury_string.h.  The two definitions must be kept
-    %       identical.
+    % runtime/mercury_string.h. The two definitions must be kept identical.
     %
 string.hash(String, HashVal) :-
     string.length(String, Length),
@@ -4583,6 +4591,10 @@
 
 string.format_table(Columns, Separator) = Table :-
     MaxWidths = list.map(find_max_length, Columns),
+    % Maybe the code below should be replaced by the code of format_table_max,
+    % with all maybe widths set to "no". They do the same job; the code of
+    % format_table_max just does it more directly, without the excessive use
+    % of higher order calls.
     PaddedColumns = list.map_corresponding(pad_column, MaxWidths, Columns),
     (
         PaddedColumns = [PaddedHead | PaddedTail],
@@ -4594,16 +4606,132 @@
     ),
     Table = string.join_list("\n", Rows).
 
+string.format_table_max(ColumnsLimits, Separator) = Table :-
+    MaxWidthsSenses = list.map(find_max_length_with_limit, ColumnsLimits),
+    Columns = list.map(project_column_strings, ColumnsLimits),
+    SepLen = string.length(Separator),
+    generate_rows(MaxWidthsSenses, Separator, SepLen, Columns, [], RevRows),
+    list.reverse(RevRows, Rows),
+    Table = string.join_list("\n", Rows).
+
+:- func project_column_strings(pair(justified_column, maybe(int)))
+    = list(string).
+
+project_column_strings(left(Strings) - _) = Strings.
+project_column_strings(right(Strings) - _) = Strings.
+
+:- pred generate_rows(assoc_list(justify_sense, int)::in, string::in, int::in,
+    list(list(string))::in, list(string)::in, list(string)::out) is det.
+
+generate_rows(MaxWidthsSenses, Separator, SepLen, Columns0, !RevRows) :-
+    ( all_empty(Columns0) ->
+        true
+    ;
+        get_next_line(Columns0, Line, Columns),
+        pad_row(MaxWidthsSenses, Line, Separator, SepLen, 0, Row),
+        !:RevRows = [Row | !.RevRows],
+        generate_rows(MaxWidthsSenses, Separator, SepLen, Columns, !RevRows)
+    ).
+
+:- pred all_empty(list(list(string))::in) is semidet.
+
+all_empty([]).
+all_empty([List | Lists]) :-
+    List = [],
+    all_empty(Lists).
+
+:- pred get_next_line(list(list(string))::in,
+    list(string)::out, list(list(string))::out) is det.
+
+get_next_line([], [], []).
+get_next_line([Column | Columns], [ColumnTop | ColumnTops],
+        [ColumnRest | ColumnRests]) :-
+    (
+        Column = [],
+        error("list length mismatch in get_next_line")
+    ;
+        Column = [ColumnTop | ColumnRest]
+    ),
+    get_next_line(Columns, ColumnTops, ColumnRests).
+
+:- pred pad_row(assoc_list(justify_sense, int)::in, list(string)::in,
+    string::in, int::in, int::in, string::out) is det.
+
+pad_row([], [], _, _, _, "").
+pad_row([Justify - MaxWidth | JustifyWidths], [ColumnString0 | ColumnStrings0],
+        Separator, SepLen, CurColumn, Line) :-
+    NextColumn = CurColumn + MaxWidth + SepLen,
+    pad_row(JustifyWidths, ColumnStrings0, Separator, SepLen, NextColumn,
+        LineRest),
+    ( string.length(ColumnString0) =< MaxWidth ->
+        (
+            Justify = just_left,
+            ColumnString = string.pad_right(ColumnString0, ' ', MaxWidth)
+        ;
+            Justify = just_right,
+            ColumnString = string.pad_left(ColumnString0, ' ', MaxWidth)
+        ),
+        (
+            JustifyWidths = [],
+            Line = ColumnString
+        ;
+            JustifyWidths = [_ | _],
+            Line = ColumnString ++ Separator ++ LineRest
+        )
+    ;
+        (
+            JustifyWidths = [],
+            Line = ColumnString0
+        ;
+            JustifyWidths = [_ | _],
+            Line = ColumnString0 ++ Separator ++ "\n" ++
+                string.duplicate_char(' ', NextColumn) ++ LineRest
+        )
+    ).
+pad_row([], [_ | _], _, _, _, _) :-
+    error("list length mismatch in pad_row").
+pad_row([_ | _], [], _, _, _, _) :-
+    error("list length mismatch in pad_row").
+
 :- func join_rev_columns(string, string, string) = string.
 
 join_rev_columns(Separator, Col1, Col2) = Col2 ++ Separator ++ Col1.
 
 :- func find_max_length(justified_column) = int.
 
-find_max_length(left(Strings)) = MaxLength :-
-    list.foldl2(max_str_length, Strings, 0, MaxLength, "", _).
-find_max_length(right(Strings)) = MaxLength :-
-    list.foldl2(max_str_length, Strings, 0, MaxLength, "", _).
+find_max_length(JustColumn) = MaxLength :-
+    ( JustColumn = left(Strings)
+    ; JustColumn = right(Strings)
+    ),
+    list.foldl(max_str_length, Strings, 0, MaxLength).
+
+:- type justify_sense
+    --->    just_left
+    ;       just_right.
+
+:- func find_max_length_with_limit(pair(justified_column, maybe(int)))
+    = pair(justify_sense, int).
+
+find_max_length_with_limit(JustColumn - MaybeLimit) = Sense - MaxLength :-
+    (
+        JustColumn = left(Strings),
+        Sense = just_left
+    ;
+        JustColumn = right(Strings),
+        Sense = just_right
+    ),
+    list.foldl(max_str_length, Strings, 0, MaxLength0),
+    (
+        MaybeLimit = yes(Limit),
+        ( MaxLength0 > Limit ->
+            MaxLength = Limit
+        ;
+            MaxLength = MaxLength0
+        )
+    ;
+        MaybeLimit = no,
+        MaxLength = MaxLength0
+    ).
 
 :- func pad_column(int, justified_column) = list(string).
 
@@ -4618,17 +4746,14 @@
 
 lpad(Chr, N, Str) = string.pad_left(Str, Chr, N).
 
-:- pred max_str_length(string::in, int::in, int::out, string::in, string::out)
-    is det.
+:- pred max_str_length(string::in, int::in, int::out) is det.
 
-max_str_length(Str, PrevMaxLen, MaxLen, PrevMaxStr, MaxStr) :-
+max_str_length(Str, PrevMaxLen, MaxLen) :-
     Length = string.length(Str),
     ( Length > PrevMaxLen ->
-        MaxLen = Length,
-        MaxStr = Str
+        MaxLen = Length
     ;
-        MaxLen = PrevMaxLen,
-        MaxStr = PrevMaxStr
+        MaxLen = PrevMaxLen
     ).
 
 %-----------------------------------------------------------------------------%
cvs diff: Diffing mdbcomp
Index: mdbcomp/slice_and_dice.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/mdbcomp/slice_and_dice.m,v
retrieving revision 1.10
diff -u -b -r1.10 slice_and_dice.m
--- mdbcomp/slice_and_dice.m	2 Oct 2006 05:21:38 -0000	1.10
+++ mdbcomp/slice_and_dice.m	23 Nov 2006 16:41:07 -0000
@@ -56,14 +56,20 @@
     %
 :- pred read_slice(string::in, maybe_error(slice)::out, io::di, io::uo) is det.
 
-    % read_slice_to_string(File, SortStr, N, Module, SliceStr, Problem, !IO):
+    % read_slice_to_string(File, SortStr, MaxRows, MaybeMaxPredColumns,
+    %   MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns,
+    %   Module, SliceStr, Problem, !IO):
     %
     % Read the slice from File, and convert it to a string suitable for
     % displaying on the screen, sorting it first using SortStr. SortStr
     % can be any combination of the letters "cCtT" and indicates how the slice
     % is to be sorted. See the documentation for the `mslice' tool in the
-    % user guide for an explanation of the sort string. Take only the top N
-    % lines of the sorted list.
+    % user guide for an explanation of the sort string. Take only the top
+    % MaxRows lines of the sorted list. If MaybeMaxPredColumns is yes,
+    % allow only the number of columns it specifies for predicate names.
+    % If MaybeMaxPathColumns is yes, allow only the number of columns it
+    % specifies for ports and paths. If MaybeMaxFileColumns is yes, allow
+    % only the number of columns it specifies for file names and line numbers.
     %
     % If Module is not the empty string then only labels from the named module
     % will be included in the dice string, otherwise all modules will be
@@ -74,6 +80,7 @@
     % will be the empty string, otherwise Problem will be the empty string.
     %
 :- pred read_slice_to_string(string::in, string::in, int::in,
+    maybe(int)::in, maybe(int)::in, maybe(int)::in,
     string::in, string::out, string::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
@@ -120,8 +127,9 @@
 :- pred read_dice(string::in, string::in, maybe_error(dice)::out,
     io::di, io::uo) is det.
 
-    % read_dice_to_string(PassFile, FailFile, SortStr, N, Module, DiceStr,
-    %   Problem, !IO):
+    % read_dice_to_string(PassFile, FailFile, SortStr, MaxRow,
+    %   MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns,
+    %   Module, DiceStr, Problem, !IO):
     %
     % Read the slice from PassFile, interpreting it as (a union of) passing
     % slices; read the slices from FailFile, interpreting it as (a union of)
@@ -131,8 +139,12 @@
     % sorting it first using SortStr. SortStr can be any combination of the
     % letters "sSpPfPdD" and indicates how the dice is to be sorted.
     % See the documentation for the `dice' command in the user guide
-    % for an explanation of the sort string. Take only the top N lines
-    % of the sorted list.
+    % for an explanation of the sort string. Take only the top
+    % MaxRows lines of the sorted list. If MaybeMaxPredColumns is yes,
+    % allow only the number of columns it specifies for predicate names.
+    % If MaybeMaxPathColumns is yes, allow only the number of columns it
+    % specifies for ports and paths. If MaybeMaxFileColumns is yes, allow
+    % only the number of columns it specifies for file names and line numbers.
     %
     % If Module is not the empty string then only labels from the named module
     % will be included in the dice string, otherwise all modules will be
@@ -143,6 +155,7 @@
     % will be the empty string, otherwise Problem will be the empty string.
     %
 :- pred read_dice_to_string(string::in, string::in, string::in, int::in,
+    maybe(int)::in, maybe(int)::in, maybe(int)::in,
     string::in, string::out, string::out, io::di, io::uo) is det.
 
     % suspicion_ratio(PassCount, FailCount) = Suspicion.
@@ -378,11 +391,9 @@
 % A mechanism for sorting and formatting slices. The structure is similar
 % to the mechanism for sorting and formatting dices below.
 
-:- pragma foreign_export("C",
-    read_slice_to_string(in, in, in, in, out, out, di, uo),
-    "MR_MDB_read_slice_to_string").
-
-read_slice_to_string(File, SortStr0, N, Module, SliceStr, Problem, !IO) :-
+read_slice_to_string(File, SortStr0, MaxRows,
+        MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns,
+        Module, SliceStr, Problem, !IO) :-
     ( slice_sort_string_is_valid(SortStr0) ->
         read_slice(File, ReadSliceResult, !IO),
         (
@@ -405,13 +416,14 @@
             ),
             list.sort(slice_label_count_compare(SortStr), FilteredLabelCounts,
                 SortedLabelCounts),
-            ( list.take(N, SortedLabelCounts, Taken) ->
+            ( list.take(MaxRows, SortedLabelCounts, Taken) ->
                 TopNLabelCounts = Taken
             ;
                 TopNLabelCounts = SortedLabelCounts
             ),
             Problem = "",
-            SliceStr = format_slice_label_counts(TopNLabelCounts, TotalTests)
+            SliceStr = format_slice_label_counts(TopNLabelCounts, TotalTests,
+                MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns)
         ;
             ReadSliceResult = error(Problem),
             SliceStr = ""
@@ -523,22 +535,36 @@
 
     % Produce a formatted table from a list of slice_label_counts.
     %
-:- func format_slice_label_counts(list(slice_label_count), int) = string.
+:- func format_slice_label_counts(list(slice_label_count), int,
+    maybe(int), maybe(int), maybe(int)) = string.
 
-format_slice_label_counts(LabelCounts, TotalTests) = Str :-
+format_slice_label_counts(LabelCounts, TotalTests,
+        MaybeMaxPredColumns, MaybePathColumns, MaybeMaxFileColumns) = Str :-
     list.map5(deconstruct_slice_label_count, LabelCounts, ProcLabels,
         PathPorts, FormattedContexts, Counts, Tests),
     FormattedProcLabels = list.map(format_proc_label, ProcLabels),
     FormattedPathPorts = list.map(format_path_port, PathPorts),
     CountStrs = list.map(string.int_to_string_thousands, Counts),
+    AlwaysColumns = [
+        left( ["Procedure"       | FormattedProcLabels]) - MaybeMaxPredColumns,
+        left( ["Path/Port"       | FormattedPathPorts]) - MaybePathColumns,
+        left( ["File:Line"       | FormattedContexts]) - MaybeMaxFileColumns,
+        right(["Count"           | CountStrs]) - no],
+    filter(unify(1), Tests, _OneTests, OtherTests),
+    (
+        % All events were executed in one test. Don't include the redundant
+        % column containing "(1)" at the end of each line.
+        %
+        OtherTests = [],
+        Columns = AlwaysColumns
+    ;
+        OtherTests = [_ | _],
     TestsStrs = list.map(bracket_int, Tests),
     TotalTestsStr = "(" ++ int_to_string_thousands(TotalTests) ++ ")",
-    Str = string.format_table([
-        left( ["Procedure"       | FormattedProcLabels]),
-        left( ["Path/Port"       | FormattedPathPorts]),
-        left( ["File:Line"       | FormattedContexts]),
-        right(["Count"           | CountStrs]),
-        right([TotalTestsStr     | TestsStrs])], " ") ++ "\n".
+        Columns = AlwaysColumns ++ 
+            [right([TotalTestsStr     | TestsStrs]) - no]
+    ),
+    Str = string.format_table_max(Columns, " ") ++ "\n".
 
 :- pred deconstruct_slice_label_count(slice_label_count::in, proc_label::out,
     path_port::out, string::out, int::out, int::out) is det.
@@ -561,11 +587,20 @@
 % to the mechanism for sorting and formatting slices above.
 
 :- pragma foreign_export("C",
-    read_dice_to_string(in, in, in, in, in, out, out, di, uo),
+    read_dice_to_string_no_limit(in, in, in, in, in, out, out, di, uo),
     "MR_MDB_read_dice_to_string").
 
-read_dice_to_string(PassFile, FailFile, SortStr, N, Module, DiceStr, Problem,
-        !IO) :-
+:- pred read_dice_to_string_no_limit(string::in, string::in, string::in,
+    int::in, string::in, string::out, string::out, io::di, io::uo) is det.
+
+read_dice_to_string_no_limit(PassFile, FailFile, SortStr, MaxRow,
+        Module, DiceStr, Problem, !IO) :-
+    read_dice_to_string(PassFile, FailFile, SortStr, MaxRow, no, no, no,
+        Module, DiceStr, Problem, !IO).
+
+read_dice_to_string(PassFile, FailFile, SortStr, MaxRow,
+        MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns,
+        Module, DiceStr, Problem, !IO) :-
     ( dice_sort_string_is_valid(SortStr) ->
         read_dice(PassFile, FailFile, ReadDiceResult, !IO),
         (
@@ -580,14 +615,15 @@
             ),
             list.sort(dice_label_count_compare(SortStr), FilteredLabelCounts,
                 SortedLabelCounts),
-            ( list.take(N, SortedLabelCounts, Taken) ->
+            ( list.take(MaxRow, SortedLabelCounts, Taken) ->
                 TopNLabelCounts = Taken
             ;
                 TopNLabelCounts = SortedLabelCounts
             ),
             Problem = "",
             DiceStr = format_dice_label_counts(TopNLabelCounts,
-                TotalPassTests, TotalFailTests)
+                TotalPassTests, TotalFailTests,
+                MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns)
         ;
             ReadDiceResult = error(Problem),
             DiceStr = ""
@@ -715,9 +751,11 @@
 
     % Produce a formatted table from a list of dice_label_counts.
     %
-:- func format_dice_label_counts(list(dice_label_count), int, int) = string.
+:- func format_dice_label_counts(list(dice_label_count), int, int,
+    maybe(int), maybe(int), maybe(int)) = string.
 
-format_dice_label_counts(LabelCounts, TotalPassTests, _TotalFailTests) = Str :-
+format_dice_label_counts(LabelCounts, TotalPassTests, _TotalFailTests,
+        MaybeMaxPredColumns, MaybeMaxPathColumns, MaybeMaxFileColumns) = Str :-
     list.map7(deconstruct_dice_label_count, LabelCounts, ProcLabels,
         PathPorts, FormattedContexts, PassCounts, PassTests, FailCounts,
         _FailTests),
@@ -730,14 +768,15 @@
         PassCounts, FailCounts),
     FormattedSuspicionIndices = list.map(format_float(2), SuspicionIndices),
     TotalPassTestsStr = "(" ++ int_to_string_thousands(TotalPassTests) ++ ")",
-    Str = string.format_table([
-        left( ["Procedure"       | FormattedProcLabels]),
-        left( ["Path/Port"       | FormattedPathPorts]),
-        left( ["File:Line"       | FormattedContexts]),
-        right(["Pass"            | PassCountStrs]),
-        right([TotalPassTestsStr | PassTestsStrs]),
-        right(["Fail"            | FailCountStrs]),
-        right(["Suspicion"       | FormattedSuspicionIndices])], " ") ++ "\n".
+    Columns = [
+        left( ["Procedure"       | FormattedProcLabels]) - MaybeMaxPredColumns,
+        left( ["Path/Port"       | FormattedPathPorts]) - MaybeMaxPathColumns,
+        left( ["File:Line"       | FormattedContexts]) - MaybeMaxFileColumns,
+        right(["Pass"            | PassCountStrs]) - no,
+        right([TotalPassTestsStr | PassTestsStrs]) - no,
+        right(["Fail"            | FailCountStrs]) - no,
+        right(["Suspicion"       | FormattedSuspicionIndices]) - no],
+    Str = string.format_table_max(Columns, " ") ++ "\n".
 
 :- pred deconstruct_dice_label_count(dice_label_count::in, proc_label::out,
     path_port::out, string::out, int::out, int::out, int::out, int::out)
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
Index: slice/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/slice/Mmakefile,v
retrieving revision 1.9
diff -u -b -r1.9 Mmakefile
--- slice/Mmakefile	27 Oct 2006 07:48:34 -0000	1.9
+++ slice/Mmakefile	23 Nov 2006 12:45:39 -0000
@@ -113,7 +113,8 @@
 
 #-----------------------------------------------------------------------------#
 
-tags:	$(MTAGS) $(mslice.ms) $(mdice.ms) $(mtc_union.ms) $(LIBRARY_DIR)/*.m
+tags:	$(MTAGS) $(mslice.ms) $(mdice.ms) $(mtc_union.ms) $(mcov.ms) \
+		$(mtc_diff.ms) $(LIBRARY_DIR)/*.m
 	$(MTAGS) $(mslice.ms) $(mdice.ms) $(mtc_union.ms) $(mcov.ms) \
 	$(mtc_diff.ms) $($(LIBRARY_DIR)/*.m
 
Index: slice/mdice.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/slice/mdice.m,v
retrieving revision 1.3
diff -u -b -r1.3 mdice.m
--- slice/mdice.m	22 Sep 2006 03:50:48 -0000	1.3
+++ slice/mdice.m	23 Nov 2006 17:05:38 -0000
@@ -29,7 +29,9 @@
 :- import_module mdbcomp.slice_and_dice.
 
 :- import_module getopt.
+:- import_module maybe.
 :- import_module list.
+:- import_module string.
 
 %-----------------------------------------------------------------------------%
 
@@ -48,9 +50,28 @@
         ;
             Args = [PassFileName, FailFileName],
             lookup_string_option(OptionTable, sort, SortStr),
-            lookup_int_option(OptionTable, limit, Limit),
             lookup_string_option(OptionTable, modulename, Module),
-            read_dice_to_string(PassFileName, FailFileName, SortStr, Limit,
+            lookup_int_option(OptionTable, max_row, MaxRow),
+            lookup_int_option(OptionTable, max_pred_column, MaxPredColumn),
+            lookup_int_option(OptionTable, max_path_column, MaxPathColumn),
+            lookup_int_option(OptionTable, max_file_column, MaxFileColumn),
+            ( MaxPredColumn = 0 ->
+                MaybeMaxPredColumn = no
+            ;
+                MaybeMaxPredColumn = yes(MaxPredColumn)
+            ),
+            ( MaxPathColumn = 0 ->
+                MaybeMaxPathColumn = no
+            ;
+                MaybeMaxPathColumn = yes(MaxPathColumn)
+            ),
+            ( MaxFileColumn = 0 ->
+                MaybeMaxFileColumn = no
+            ;
+                MaybeMaxFileColumn = yes(MaxFileColumn)
+            ),
+            read_dice_to_string(PassFileName, FailFileName, SortStr, MaxRow,
+                MaybeMaxPredColumn, MaybeMaxPathColumn, MaybeMaxFileColumn,
                 Module, DiceStr, Problem, !IO),
             ( Problem = "" ->
                 io.write_string(DiceStr, !IO)
@@ -72,14 +93,19 @@
 :- pred usage(io::di, io::uo) is det.
 
 usage(!IO) :-
-    io.write_strings(["Usage: mdice [-s sortspec] [-l N] [-m module] ",
-        "passfile failfile\n"], !IO).
+    io.write_string(
+        "Usage: mdice [-s sortspec] [-m module] [-l N] [-n N] [-p N] [-f N] "
+        ++ "passfile failfile\n",
+        !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- type option
     --->    sort
-    ;       limit
+    ;       max_row
+    ;       max_pred_column
+    ;       max_path_column
+    ;       max_file_column
     ;       modulename.
 
 :- type option_table == option_table(option).
@@ -88,16 +114,25 @@
 :- pred long_option(string::in, option::out) is semidet.
 :- pred option_default(option::out, option_data::out) is multi.
 
-option_default(sort,        string("")).
-option_default(limit,       int(100)).
+option_default(sort,            string("S")).
+option_default(max_row,         int(100)).
+option_default(max_pred_column, int(35)).
+option_default(max_path_column, int(12)).
+option_default(max_file_column, int(20)).
 option_default(modulename,  string("")).
 
 short_option('s',           sort).
-short_option('l',           limit).
+short_option('l',               max_row).
+short_option('n',               max_pred_column).
+short_option('p',               max_path_column).
+short_option('f',               max_file_column).
 short_option('m',           modulename).
 
 long_option("sort",         sort).
-long_option("limit",        limit).
+long_option("limit",            max_row).
+long_option("max-name-column",  max_pred_column).
+long_option("max-path-column",  max_path_column).
+long_option("max-file-column",  max_file_column).
 long_option("module",       modulename).
 
 %-----------------------------------------------------------------------------%
Index: slice/mslice.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/slice/mslice.m,v
retrieving revision 1.3
diff -u -b -r1.3 mslice.m
--- slice/mslice.m	22 Sep 2006 03:50:48 -0000	1.3
+++ slice/mslice.m	23 Nov 2006 17:06:06 -0000
@@ -28,6 +28,8 @@
 
 :- import_module getopt.
 :- import_module list.
+:- import_module maybe.
+:- import_module string.
 
 main(!IO) :-
     io.command_line_arguments(Args0, !IO),
@@ -41,10 +43,29 @@
         ;
             Args = [FileName],
             lookup_string_option(OptionTable, sort, SortStr),
-            lookup_int_option(OptionTable, limit, Limit),
+            lookup_int_option(OptionTable, max_row, MaxRow),
+            lookup_int_option(OptionTable, max_pred_column, MaxPredColumn),
+            lookup_int_option(OptionTable, max_path_column, MaxPathColumn),
+            lookup_int_option(OptionTable, max_file_column, MaxFileColumn),
             lookup_string_option(OptionTable, modulename, Module),
-            read_slice_to_string(FileName, SortStr, Limit, Module, SliceStr,
-                Problem, !IO),
+            ( MaxPredColumn = 0 ->
+                MaybeMaxPredColumn = no
+            ;
+                MaybeMaxPredColumn = yes(MaxPredColumn)
+            ),
+            ( MaxPathColumn = 0 ->
+                MaybeMaxPathColumn = no
+            ;
+                MaybeMaxPathColumn = yes(MaxPathColumn)
+            ),
+            ( MaxFileColumn = 0 ->
+                MaybeMaxFileColumn = no
+            ;
+                MaybeMaxFileColumn = yes(MaxFileColumn)
+            ),
+            read_slice_to_string(FileName, SortStr, MaxRow,
+                MaybeMaxPredColumn, MaybeMaxPathColumn, MaybeMaxFileColumn,
+                Module, SliceStr, Problem, !IO),
             ( Problem = "" ->
                 io.write_string(SliceStr, !IO)
             ;
@@ -66,13 +87,18 @@
 
 usage(!IO) :-
     io.write_string(
-        "Usage: mslice [-s sortspec] [-l N] [-m module] filename\n", !IO).
+        "Usage: mslice [-s sortspec] [-m module] [-l N] [-n N] [-p N] [-f N] "
+        ++ "filename\n",
+        !IO).
 
 %-----------------------------------------------------------------------------%
 
 :- type option
     --->    sort
-    ;       limit
+    ;       max_row
+    ;       max_pred_column
+    ;       max_path_column
+    ;       max_file_column
     ;       modulename.
 
 :- type option_table == option_table(option).
@@ -81,16 +107,25 @@
 :- pred long_option(string::in, option::out) is semidet.
 :- pred option_default(option::out, option_data::out) is multi.
 
-option_default(sort,        string("")).
-option_default(limit,       int(100)).
+option_default(sort,            string("C")).
+option_default(max_row,         int(100)).
+option_default(max_pred_column, int(35)).
+option_default(max_path_column, int(12)).
+option_default(max_file_column, int(20)).
 option_default(modulename,  string("")).
 
 short_option('s',           sort).
-short_option('l',           limit).
+short_option('l',               max_row).
+short_option('n',               max_pred_column).
+short_option('p',               max_path_column).
+short_option('f',               max_file_column).
 short_option('m',           modulename).
 
 long_option("sort",         sort).
-long_option("limit",        limit).
+long_option("limit",            max_row).
+long_option("max-name-column",  max_pred_column).
+long_option("max-path-column",  max_path_column).
+long_option("max-file-column",  max_file_column).
 long_option("module",       modulename).
 
 %-----------------------------------------------------------------------------%
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