[m-rev.] For review: clean up mdprof_dump command line parsing.
Paul Bone
pbone at csse.unimelb.edu.au
Fri Feb 8 22:44:44 AEDT 2008
For review by anyone.
Estimated hours taken: 2
Branch: main
Improved mdprof_dump's command line parsing. It's now easier to predict
mdprof_dump's behaviour. Major changes include The "-D restrict" option is
now "--restrict", and is no-longer affected by other -D options. Silently
ignored -D options have now been documented as unimplemented.
deep_profiler/dump.m:
New types and predicates have been introduced to support a more
strictly-checked set of options. Including the dump_options type to
represent options given to deep_dump/4 and deep_initial_dump/4.
deep_dump/4, deep_initial_dump/4 and should_dump/2 have been modified to
use the dump_options type.
deep_profiler/startup.m:
Conform to changes in dump.m, read_and_startup now takes a deep_options
type rather than a list of strings as before. A new version of
read_and_startup has been created that doesn't take any deep_options and
assumes the defaults.
deep_profiler/mdprof_cgi.m:
Conform to changes in startup.m, now makes use of deep.m.
deep_profiler/mdprof_dump.m:
Modified command line options, -D is only used to specify which arrays
to dump and --restrict has been added which is no-longer affected by -D
options. Corrected usage message and conform to changes in dump.m.
deep_profiler/mdprof_feedback.m:
Conform to changes in startup.m, now makes use of deep.m.
deep_profiler/mdprof_test.m:
Conform to changes in startup.m, now makes use of deep.m.
Index: deep_profiler/dump.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/dump.m,v
retrieving revision 1.12
diff -u -u -r1.12 dump.m
--- deep_profiler/dump.m 23 Nov 2007 07:35:51 -0000 1.12
+++ deep_profiler/dump.m 8 Feb 2008 11:55:19 -0000
@@ -21,21 +21,106 @@
:- import_module io.
:- import_module list.
+:- import_module set.
%-----------------------------------------------------------------------------%
+ % This type represtents the set of options that the dump_initial_deep
+ % and dump_deep predicates below take.
+ %
+:- type dump_options
+ ---> dump_options(
+ do_restricted :: show_restricted_dump,
+ do_arrays :: set(dumpable_array),
+ do_stats :: show_stats,
+ do_dump_cliques :: dump_cliques,
+ do_dump_rev_links :: dump_rev_links,
+ do_dump_prop_measurements :: dump_prop_measurements
+ ).
+
+
+ % show_restricted_dump
+ %
+ % This type is used to describe if a restricted set of "css" and "ps"
+ % structures should be shown, (those for code that was executed), or if all
+ % "css" and "ps" structures should be shown.
+ %
+:- type show_restricted_dump
+ ---> show_restricted_dump
+ ; show_complete_dump.
+
+
+ % dumpable_array represents the availble arrays that may be selected
+ % for dumping.
+ %
+:- type dumpable_array
+ ---> csd
+ ; css
+ ; pd
+ ; ps.
+
+
+ % show_stats describes whether to show some statistics and the root node
+ % in the dump.
+ %
+:- type show_stats
+ ---> show_stats
+ ; dont_show_stats.
+
+
+ % Types to specifiy if cliques, rev (proc static to caller) links and
+ % propogated measurements should be dumpped by dump_deep/3.
+ %
+:- type dump_cliques
+ ---> dump_cliques
+ ; dont_dump_cliques.
+
+:- type dump_rev_links
+ ---> dump_rev_links
+ ; dont_dump_rev_links.
+
+:- type dump_prop_measurements
+ ---> dump_prop_measurements
+ ; dont_dump_prop_measurements.
+
+
+%-----------------------------------------------------------------------------%
+
+ % default_dump_options will retreive the default set of dump options.
+ %
+:- func default_dump_options = dump_options is det.
+
+
+ % dump_array_options will take a list of strings for the accumulating
+ % dump options and produce a set if possible.
+ %
+ % A deterministic version is avalible that will throw an exception if
+ % a string cannot be converted to a option.
+ %
+:- pred dump_array_options(list(string)::in, set(dumpable_array)::out)
+ is semidet.
+:- pred dump_array_options_det(list(string)::in, set(dumpable_array)::out)
+ is det.
+
+
+ % dump_array_options_to_dump_options takes a list of strings of the
+ % accumulating array dump options and create a dump_options structure
+ % based on the default plus these spacific array options.
+ %
+:- pred dump_array_options_to_dump_options(list(string)::in,
+ dump_options::out) is det.
+
+
% dump_initial_deep(InitialDeep, DumpOptions, !IO):
%
- % Dump selected parts of InitialDeep to standard output. The array of call
- % site dynamics, proc dynamics, call site statics and proc statics is
- % dumped if DumpOptions contains "csd", "pd", "css" or "ps" respectively.
- % If it contains "restrict", then the only the elements of the static
- % arrays that will be dumped are the ones that are referred to from the
- % dynamic arrays. The statistics and the root node are dumped if
+ % Dump selected parts of InitialDeep to standard output. The array of
+ % call site dynamics, proc dynamics, call site statics and proc statics
+ % is dumped if DumpOptions contains "csd", "pd", "css" or "ps"
+ % respectively. The statistics and the root node are dumped if
% DumpOptions contains "stats".
%
-:- pred dump_initial_deep(initial_deep::in, list(string)::in, io::di, io::uo)
- is det.
+:- pred dump_initial_deep(initial_deep::in, dump_options::in, io::di,
+ io::uo) is det.
% dump_deep(Deep, DumpOptions, !IO):
%
@@ -44,7 +129,7 @@
% contain reverse links are dumped if DumpOptions contains "rev".
% The propagated costs are dumped if DumpOptions contains "prop".
%
-:- pred dump_deep(deep::in, list(string)::in, io::di, io::uo) is det.
+:- pred dump_deep(deep::in, dump_options::in, io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -64,42 +149,141 @@
:- import_module maybe.
:- import_module pair.
:- import_module require.
-:- import_module set.
:- import_module string.
:- import_module svset.
%----------------------------------------------------------------------------%
+default_dump_options = DumpOptions :-
+ some [!ArraySet]
+ (
+ !:ArraySet = set.init,
+ svset.insert(csd, !ArraySet),
+ svset.insert(css, !ArraySet),
+ svset.insert(pd, !ArraySet),
+ svset.insert(ps, !ArraySet),
+ DumpOptions = dump_options(show_complete_dump, !.ArraySet,
+ show_stats, dump_cliques, dump_rev_links,
+ dump_prop_measurements)
+ ).
+
+
+dump_array_options_det(Strings, DumpArrayOptions) :-
+ (
+ dump_array_options_special(Strings, DumpArrayOptionsSpecial)
+ ->
+ DumpArrayOptions = DumpArrayOptionsSpecial
+ ;
+ string_list_to_sym_set(dump_array_option_det, Strings,
+ DumpArrayOptions)
+ ).
+
+dump_array_options(Strings, DumpArrayOptions) :-
+ (
+ dump_array_options_special(Strings, DumpArrayOptionsSpecial)
+ ->
+ DumpArrayOptions = DumpArrayOptionsSpecial
+ ;
+ string_list_to_sym_set(dump_array_option, Strings,
+ DumpArrayOptions)
+ ).
+
+
+ % Handle special cases in the list of array options.
+ %
+:- pred dump_array_options_special(list(string)::in, set(dumpable_array)::out)
+ is semidet.
+
+dump_array_options_special([], all_array_options).
+dump_array_options_special(["all"], all_array_options).
+
+
+dump_array_options_to_dump_options(Strings, DumpOptions) :-
+ dump_array_options_det(Strings, DumpArrayOptions),
+ DumpOptions = default_dump_options ^ do_arrays := DumpArrayOptions.
+
+
+
+:- pred string_list_to_sym_set(pred(string, X), list(string), set(X)).
+:- mode string_list_to_sym_set(pred(in, out) is det, in, out) is det.
+:- mode string_list_to_sym_set(pred(in, out) is semidet, in, out) is semidet.
+
+string_list_to_sym_set(StrToSym, List0, Set) :-
+ map(StrToSym, List0, List),
+ list_to_set(List, Set).
+
+
+:- pred dump_array_option_det(string::in, dumpable_array::out) is det.
+
+dump_array_option_det(String, Array) :-
+ ( dump_array_option(String, ArrayP) ->
+ Array = ArrayP
+ ;
+ error("Invalid array name in dump options: " ++ String)
+ ).
+
+
+:- pred dump_array_option(string::in, dumpable_array::out) is semidet.
+
+dump_array_option("csd", csd).
+dump_array_option("css", css).
+dump_array_option("pd", pd).
+dump_array_option("ps", ps).
+
+
+:- func all_array_options = set(dumpable_array).
+
+all_array_options = Set :-
+ some [!Set] (
+ !:Set = set.init,
+ svset.insert(csd, !Set),
+ svset.insert(css, !Set),
+ svset.insert(pd, !Set),
+ svset.insert(ps, !Set),
+ Set = !.Set
+ ).
+
+
+%----------------------------------------------------------------------------%
+%
+% Dump initial deep profiling structure.
+%
+
dump_initial_deep(InitialDeep, DumpOptions, !IO) :-
InitialDeep = initial_deep(Stats, InitRoot, CSDs, PDs, CSSs, PSs),
- ( should_dump(DumpOptions, "restrict") ->
+ Restrict = DumpOptions ^ do_restricted,
+ (
+ Restrict = show_restricted_dump,
get_static_ptrs_from_dynamic_procs(PDs, PSs, UsedPSs, UsedCSSs),
Restriction = these(UsedPSs, UsedCSSs)
;
+ Restrict = show_complete_dump,
Restriction = none
),
- ( should_dump(DumpOptions, "stat") ->
+ ShowStats = DumpOptions ^ do_stats,
+ (
+ ShowStats = show_stats,
dump_init_profile_stats(Stats, !IO),
dump_init_root(InitRoot, !IO)
;
- true
+ ShowStats = dont_show_stats
),
- ( should_dump(DumpOptions, "csd") ->
+ ( should_dump(DumpOptions, csd) ->
dump_init_call_site_dynamics(CSDs, !IO)
;
true
),
- ( should_dump(DumpOptions, "pd") ->
+ ( should_dump(DumpOptions, pd) ->
dump_init_proc_dynamics(PDs, PSs, !IO)
;
true
),
- ( should_dump(DumpOptions, "css") ->
+ ( should_dump(DumpOptions, css) ->
dump_init_call_site_statics(Restriction, CSSs, !IO)
;
true
),
- ( should_dump(DumpOptions, "ps") ->
+ ( should_dump(DumpOptions, ps) ->
dump_init_proc_statics(Restriction, PSs, !IO)
;
true
@@ -462,22 +646,29 @@
%----------------------------------------------------------------------------%
dump_deep(Deep, DumpOptions, !IO) :-
- ( should_dump(DumpOptions, "clique") ->
+ DumpCliques = DumpOptions ^ do_dump_cliques,
+ DumpRevLinks = DumpOptions ^ do_dump_rev_links,
+ DumpPropMeasurements = DumpOptions ^ do_dump_prop_measurements,
+ (
+ DumpCliques = dump_cliques,
dump_deep_cliques(Deep, !IO)
;
- true
+ DumpCliques = dont_dump_cliques
),
- ( should_dump(DumpOptions, "rev") ->
+ (
+ DumpRevLinks = dump_rev_links,
dump_deep_rev_links(Deep, !IO)
;
- true
+ DumpRevLinks = dont_dump_rev_links
),
- ( should_dump(DumpOptions, "prop") ->
+ (
+ DumpPropMeasurements = dump_prop_measurements,
dump_deep_prop_measurements(Deep, !IO)
;
- true
+ DumpPropMeasurements = dont_dump_prop_measurements
).
+
%----------------------------------------------------------------------------%
:- pred dump_deep_cliques(deep::in, io::di, io::uo) is det.
@@ -749,13 +940,11 @@
%----------------------------------------------------------------------------%
-:- pred should_dump(list(string)::in, string::in) is semidet.
+:- pred should_dump(dump_options::in, dumpable_array::in) is semidet.
should_dump(DumpOptions, What) :-
- ( list.member(What, DumpOptions)
- ; list.member("all", DumpOptions)
- ; DumpOptions = []
- ).
+ Arrays = DumpOptions ^ do_arrays,
+ set.member(What, Arrays).
%----------------------------------------------------------------------------%
:- end_module dump.
Index: deep_profiler/mdprof_cgi.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/mdprof_cgi.m,v
retrieving revision 1.20
diff -u -u -r1.20 mdprof_cgi.m
--- deep_profiler/mdprof_cgi.m 23 Nov 2007 07:35:52 -0000 1.20
+++ deep_profiler/mdprof_cgi.m 8 Feb 2008 11:55:19 -0000
@@ -336,7 +336,7 @@
MaybeStartupStream = no
),
read_and_startup(Machine, ScriptName, [FileName], Canonical,
- MaybeStartupStream, [], [], Res, !IO),
+ MaybeStartupStream, [], Res, !IO),
(
Res = ok(Deep),
Pref = solidify_preference(Deep, PrefInd),
@@ -493,7 +493,7 @@
( Cmd0 = deep_cmd_restart ->
read_and_startup(Deep0 ^ server_name_port, Deep0 ^ script_name,
- [Deep0 ^ data_file_name], Canonical, MaybeStartupStream, [], [],
+ [Deep0 ^ data_file_name], Canonical, MaybeStartupStream, [],
MaybeDeep, !IO),
(
MaybeDeep = ok(Deep),
Index: deep_profiler/mdprof_dump.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/mdprof_dump.m,v
retrieving revision 1.7
diff -u -u -r1.7 mdprof_dump.m
--- deep_profiler/mdprof_dump.m 8 Nov 2006 05:24:37 -0000 1.7
+++ deep_profiler/mdprof_dump.m 8 Feb 2008 11:55:19 -0000
@@ -58,12 +58,21 @@
;
NeedsHelp = no,
(
- Args = [],
- FileName = "Deep.data",
- main_2(Options, FileName, !IO)
- ;
- Args = [FileName],
- main_2(Options, FileName, !IO)
+ (
+ Args = [],
+ FileName = "Deep.data"
+ ;
+ Args = [FileName]
+ ),
+ % Process options, check that they make sense.
+ make_dump_options(Options, MaybeDumpOptions),
+ (
+ MaybeDumpOptions = yes(DumpOptions),
+ main_2(DumpOptions, FileName, !IO)
+ ;
+ MaybeDumpOptions = no,
+ usage(ProgName, !IO)
+ )
;
Args = [_, _ | _],
usage(ProgName, !IO)
@@ -76,10 +85,9 @@
io.set_exit_status(1, !IO)
).
-:- pred main_2(option_table(option)::in, string::in, io::di, io::uo) is det.
+:- pred main_2(dump_options::in, string::in, io::di, io::uo) is det.
-main_2(Options, FileName, !IO) :-
- getopt.lookup_accumulating_option(Options, dump_options, DumpOptions),
+main_2(DumpOptions, FileName, !IO) :-
read_call_graph(FileName, MaybeInitialDeep, !IO),
(
MaybeInitialDeep = ok(InitialDeep),
@@ -94,9 +102,36 @@
% Option processing
%
+
+ % Process options and the list of arrays to be dumped.
+ %
+:- pred make_dump_options(option_table(option)::in, maybe(dump_options)::out)
+ is det.
+
+make_dump_options(Options, MaybeDumpOptions) :-
+ getopt.lookup_accumulating_option(Options, dump_options, ArrayOptionStrs),
+ getopt.lookup_bool_option(Options, option_restrict, RestrictBool),
+ (
+ RestrictBool = yes,
+ Restrict = show_restricted_dump
+ ;
+ RestrictBool = no,
+ Restrict = show_complete_dump
+ ),
+ DumpOptions0 = default_dump_options ^ do_restricted := Restrict,
+ (
+ dump_array_options(ArrayOptionStrs, ArrayOptions)
+ ->
+ MaybeDumpOptions = yes(DumpOptions0 ^ do_arrays := ArrayOptions)
+ ;
+ MaybeDumpOptions = no
+ ).
+
+
:- type option
---> help
- ; dump_options.
+ ; dump_options
+ ; option_restrict.
:- type option_table == (option_table(option)).
@@ -104,16 +139,19 @@
short_option('h', help).
short_option('D', dump_options).
+short_option('r', option_restrict).
:- pred long_option(string::in, option::out) is semidet.
long_option("help", help).
long_option("dump-options", dump_options).
+long_option("restrict", option_restrict).
:- pred defaults(option::out, option_data::out) is multi.
defaults(help, bool(no)).
defaults(dump_options, accumulating([])).
+defaults(option_restrict, bool(no)).
%----------------------------------------------------------------------------%
@@ -131,6 +169,12 @@
"Options:\n" ++
"\t-h, --help\n" ++
"\t\tDisplay this message.\n" ++
+ "\t-r, --restrict\n" ++
+ "\t\tDo not dump proc and call-site statics that are\n" ++
+ "\t\tnot referenced from the proc dynamics\n" ++
+ "\t-D all\n" ++
+ "\t\tAll of the following four options are implied,\n" ++
+ "\t\t(the default if no -D options are given)\n" ++
"\t-D csd\n" ++
"\t\tDump call-site dynamics.\n" ++
"\t-D pd\n" ++
@@ -139,9 +183,7 @@
"\t\tDump call-site statics.\n" ++
"\t-D ps\n" ++
"\t\tDump proc statics.\n" ++
- "\t-D restrict\n" ++
- "\t\tDo not dump proc and call-site statics that are\n" ++
- "\t\tnot referenced from the proc dynamics\n" ++
+ "\nThese options arn't avalible in this version:\n" ++
"\t-D clique\n" ++
"\t\tDump information about cliques.\n" ++
"\t-D rev\n" ++
@@ -149,6 +191,7 @@
"\t-D prop\n" ++
"\t\tDump propagated measurement information.\n".
+
%----------------------------------------------------------------------------%
:- end_module mdprof_dump.
%----------------------------------------------------------------------------%
Index: deep_profiler/mdprof_feedback.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/mdprof_feedback.m,v
retrieving revision 1.3
diff -u -u -r1.3 mdprof_feedback.m
--- deep_profiler/mdprof_feedback.m 2 Apr 2007 02:42:33 -0000 1.3
+++ deep_profiler/mdprof_feedback.m 8 Feb 2008 11:55:19 -0000
@@ -31,6 +31,7 @@
:- implementation.
:- import_module conf.
+:- import_module dump.
:- import_module measurements.
:- import_module profile.
:- import_module startup.
@@ -71,6 +72,8 @@
lookup_accumulating_option(Options, dump_stages,
DumpStages),
lookup_accumulating_option(Options, dump_options,
+ DumpArrayOptionStrs),
+ dump_array_options_to_dump_options(DumpArrayOptionStrs,
DumpOptions),
read_deep_file(Input, Verbose, DumpStages, DumpOptions,
MaybeProfile, !IO),
@@ -141,7 +144,7 @@
% Read a deep profiling data file.
%
:- pred read_deep_file(string::in, bool::in,
- list(string)::in, list(string)::in,
+ list(string)::in, dump_options::in,
maybe_error(deep)::out, io::di, io::uo) is det.
read_deep_file(Input, Verbose, DumpStages, DumpOptions, MaybeProfile, !IO) :-
Index: deep_profiler/mdprof_test.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/mdprof_test.m,v
retrieving revision 1.15
diff -u -u -r1.15 mdprof_test.m
--- deep_profiler/mdprof_test.m 2 Apr 2007 02:42:33 -0000 1.15
+++ deep_profiler/mdprof_test.m 8 Feb 2008 11:55:19 -0000
@@ -27,6 +27,7 @@
:- implementation.
:- import_module conf.
+:- import_module dump.
:- import_module interface.
:- import_module profile.
:- import_module query.
@@ -102,7 +103,8 @@
lookup_bool_option(Options, canonical_clique, Canonical),
lookup_bool_option(Options, verbose, Verbose),
lookup_accumulating_option(Options, dump, DumpStages),
- lookup_accumulating_option(Options, dump_options, DumpOptions),
+ lookup_accumulating_option(Options, dump_options, DumpArrayOptionsStr),
+ dump_array_options_to_dump_options(DumpArrayOptionsStr, DumpOptions),
server_name_port(Machine, !IO),
script_name(ScriptName, !IO),
(
@@ -168,7 +170,7 @@
Machine = "dummy_server", % For verification this doesn't matter.
script_name(ScriptName, !IO),
read_and_startup(Machine, ScriptName, [FileName], Canonical, no,
- [], [], Res, !IO),
+ [], default_dump_options, Res, !IO),
(
Res = ok(_Deep)
;
Index: deep_profiler/startup.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/startup.m,v
retrieving revision 1.17
diff -u -u -r1.17 startup.m
--- deep_profiler/startup.m 23 Nov 2007 07:35:52 -0000 1.17
+++ deep_profiler/startup.m 8 Feb 2008 11:55:19 -0000
@@ -19,6 +19,7 @@
:- module startup.
:- interface.
+:- import_module dump.
:- import_module profile.
:- import_module bool.
@@ -28,8 +29,12 @@
%-----------------------------------------------------------------------------%
-:- pred read_and_startup(string::in, string::in, list(string)::in,
- bool::in, maybe(io.output_stream)::in, list(string)::in, list(string)::in,
+:- pred read_and_startup(string::in, string::in, list(string)::in, bool::in,
+ maybe(io.output_stream)::in, list(string)::in, maybe_error(deep)::out,
+ io::di, io::uo) is det.
+
+:- pred read_and_startup(string::in, string::in, list(string)::in, bool::in,
+ maybe(io.output_stream)::in, list(string)::in, dump_options::in,
maybe_error(deep)::out, io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
@@ -40,7 +45,6 @@
:- import_module array_util.
:- import_module callgraph.
:- import_module canonical.
-:- import_module dump.
:- import_module measurements.
:- import_module profile.
:- import_module read_profile.
@@ -56,6 +60,11 @@
%-----------------------------------------------------------------------------%
read_and_startup(Machine, ScriptName, DataFileNames, Canonical,
+ MaybeOutputStream, DumpStages, Res, !IO) :-
+ read_and_startup(Machine, ScriptName, DataFileNames, Canonical,
+ MaybeOutputStream, DumpStages, default_dump_options, Res, !IO).
+
+read_and_startup(Machine, ScriptName, DataFileNames, Canonical,
MaybeOutputStream, DumpStages, DumpOptions, Res, !IO) :-
(
DataFileNames = [],
@@ -85,8 +94,9 @@
error("mdprof_server: merging of data files is not yet implemented")
).
+
:- pred startup(string::in, string::in, string::in, bool::in,
- maybe(io.output_stream)::in, list(string)::in, list(string)::in,
+ maybe(io.output_stream)::in, list(string)::in, dump_options::in,
initial_deep::in, deep::out, io::di, io::uo) is det.
startup(Machine, ScriptName, DataFileName, Canonical, MaybeOutputStream,
@@ -94,7 +104,7 @@
InitDeep0 = initial_deep(InitStats, Root,
CallSiteDynamics0, ProcDynamics, CallSiteStatics0, ProcStatics0),
maybe_dump(DataFileName, DumpStages, 0,
- dump_initial_deep(InitDeep0, DumpOptions), !IO),
+ dump_initial_deep(InitDeep0, default_dump_options), !IO),
maybe_report_msg(MaybeOutputStream,
"% Mapping static call sites to containing procedures...\n", !IO),
--------------------------------------------------------------------------
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