[m-rev.] for review: add --show-make-times option

Peter Wang novalazy at gmail.com
Mon Jul 28 17:58:13 AEST 2008


Branches: main

Add a `mmc --make --show-make-times' option which reports how long each
module target took to build, e.g.

Making Mercury/analysiss/hlds.make_hlds.make_hlds_error.analysis
Making Mercury/analysiss/hlds.make_hlds.make_hlds_error.analysis took 20.09s

compiler/options.m:
	Add the new option.

compiler/make.util.m:
	Export MR_get_real_milliseconds() for use by Mercury code.

compiler/make.module_target.m:
	Write a message if `--show-make-times' is enabled and a target took
	some time to execute.

doc/user_guide.texi:
	Document the new option.

diff --git a/compiler/make.module_target.m b/compiler/make.module_target.m
index 38b2cd4..c1c4270 100644
--- a/compiler/make.module_target.m
+++ b/compiler/make.module_target.m
@@ -81,6 +81,7 @@
 :- import_module transform_hlds.mmc_analysis.
 
 :- import_module dir.
+:- import_module float.
 :- import_module svmap.
 
 %-----------------------------------------------------------------------------%
@@ -376,13 +377,32 @@ build_target(CompilationTask, TargetFile, Imports, TouchedTargetFiles,
                 MaybeArgFileName = no
             )
         ),
+
+    get_real_milliseconds(Time0, !IO),
     build_with_check_for_interrupt(
         build_with_module_options_and_output_redirect(ModuleName,
             ExtraOptions ++ TaskOptions,
             build_target_2(ModuleName, Task, MaybeArgFileName, Imports)),
         Cleanup, Succeeded, !Info, !IO),
     record_made_target_2(Succeeded, TargetFile, TouchedTargetFiles,
-        TouchedFiles, !Info, !IO).
+        TouchedFiles, !Info, !IO),
+    get_real_milliseconds(Time, !IO),
+
+    globals.io_lookup_bool_option(show_make_times, ShowMakeTimes, !IO),
+    (
+        ShowMakeTimes = yes,
+        DiffSecs = float(Time - Time0) / 1000.0,
+        % Avoid cluttering the screen with short running times.
+        ( DiffSecs >= 0.4 ->
+            io.write_string("Making ", !IO),
+            make_write_target_file(TargetFile, !IO),
+            io.format(" took %.2fs\n", [f(DiffSecs)], !IO)
+        ;
+            true
+        )
+    ;
+        ShowMakeTimes = no
+    ).
 
 :- pred build_target_2(module_name::in, compilation_task_type::in,
     maybe(file_name)::in, module_imports::in, list(string)::in,
diff --git a/compiler/make.util.m b/compiler/make.util.m
index 3f2c576..25e0426 100644
--- a/compiler/make.util.m
+++ b/compiler/make.util.m
@@ -297,6 +297,13 @@
 
 %-----------------------------------------------------------------------------%
 %
+% Timing
+%
+
+:- pred get_real_milliseconds(int::out, io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%
 % Hash functions
 %
 
@@ -1584,6 +1591,19 @@ make_write_module_or_linked_target(ModuleName - FileType, !IO) :-
 
 %-----------------------------------------------------------------------------%
 %
+% Timing
+%
+
+:- pragma foreign_proc("C",
+    get_real_milliseconds(Time::out, IO0::di, IO::uo),
+    [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],
+"
+    Time = MR_get_real_milliseconds();
+    IO = IO0;
+").
+
+%-----------------------------------------------------------------------------%
+%
 % Hash functions
 %
 
diff --git a/compiler/options.m b/compiler/options.m
index 27f9ef6..6598461 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -860,6 +860,7 @@
     ;       intermod_directories
     ;       use_search_directories_for_intermod
     ;       libgrade_install_check
+    ;       show_make_times
 
     % Miscellaneous Options
     ;       filenames_from_stdin
@@ -1678,7 +1679,8 @@ option_defaults_2(build_system_option, [
     search_directories                  -   accumulating(["."]),
     intermod_directories                -   accumulating([]),
     use_search_directories_for_intermod -   bool(yes),
-    libgrade_install_check              -   bool(yes)
+    libgrade_install_check              -   bool(yes),
+    show_make_times                     -   bool(no)
 ]).
 option_defaults_2(miscellaneous_option, [
     % Miscellaneous Options
@@ -2534,7 +2536,7 @@ long_option("intermod-directory",   intermod_directories).
 long_option("use-search-directories-for-intermod",
                     use_search_directories_for_intermod).
 long_option("libgrade-install-check", libgrade_install_check).
-        
+long_option("show-make-times",      show_make_times).
 
 % misc options
 long_option("typecheck-ambiguity-warn-limit",
@@ -5176,7 +5178,9 @@ options_help_build_system -->
         "--no-libgrade-install-check",
         "\tDo not check that libraries have been installed before",
         "\tattempting to use them.  (This option is only meaningful with",
-        "\t`mmc --make'.)"
+        "\t`mmc --make'.)",
+        "--show-make-times",
+        "\tReport running times for commands executed by `mmc --make'."
     ]).
 
 :- pred options_help_misc(io::di, io::uo) is det.
diff --git a/doc/user_guide.texi b/doc/user_guide.texi
index d6f876f..51ada54 100644
--- a/doc/user_guide.texi
+++ b/doc/user_guide.texi
@@ -8896,6 +8896,11 @@ current directory.
 @samp{--use-grade-subdirs} does not work with Mmake (it does
 work with @samp{mmc --make}).
 
+ at sp 1
+ at item --show-make-times
+ at findex --show-make-times
+Report running times for commands executed by @samp{mmc --make}.
+
 @end table
 
 @node Miscellaneous options


--------------------------------------------------------------------------
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