[m-rev.] for post-commit review: allow reporting of statistics for C#
Julien Fischer
jfischer at opturion.com
Tue Mar 23 14:32:13 AEDT 2021
Allow reporting of statistics for C#
library/benchmarking.m:
Generalise the C# implementations of report_stats so that they
can write a specified text output stream, not just standard error.
library/io.m:
Implement report_{standard,full_memory}_stats_2 for C#.
Delete some XXX predicates.
Julien.
diff --git a/library/benchmarking.m b/library/benchmarking.m
index 846f4df..a7a76f8 100644
--- a/library/benchmarking.m
+++ b/library/benchmarking.m
@@ -183,7 +183,7 @@
report_stats,
[may_call_mercury, terminates],
"
- MR_report_standard_stats();
+ ML_report_standard_stats(io.mercury_stderr);
").
:- pragma foreign_proc("Java",
@@ -206,7 +206,7 @@
report_full_memory_stats,
[will_not_call_mercury],
"
- MR_report_full_memory_stats();
+ ML_report_full_memory_stats(io.mercury_stderr);
").
:- pragma foreign_proc("Java",
@@ -258,8 +258,8 @@ private static long real_time_at_start
= real_time_at_last_stat = System.DateTime.Now.Ticks;
private static long real_time_at_last_stat;
-private static void
-MR_report_standard_stats()
+public static void
+ML_report_standard_stats(io.MR_MercuryFileStruct stream)
{
double user_time_at_prev_stat = user_time_at_last_stat;
user_time_at_last_stat = System.Diagnostics.Process.GetCurrentProcess()
@@ -268,30 +268,37 @@ MR_report_standard_stats()
long real_time_at_prev_stat = real_time_at_last_stat;
real_time_at_last_stat = System.DateTime.Now.Ticks;
- System.Console.WriteLine(System.String.Format(
- ""[User time: +{0:F2}s, {1:F2}s Real time: +{2:F2}s, {3:F2}s]"",
- (user_time_at_last_stat - user_time_at_prev_stat),
- (user_time_at_last_stat - user_time_at_start),
- ((real_time_at_last_stat - real_time_at_prev_stat)
- / (double) System.TimeSpan.TicksPerSecond),
- ((real_time_at_last_stat - real_time_at_start)
- / (double) System.TimeSpan.TicksPerSecond)
- ));
-
- // XXX At this point there should be a whole bunch of memory usage
- // statistics.
+ try {
+ io.mercury_print_string(stream, System.String.Format(
+ ""[User time: +{0:F2}s, {1:F2}s Real time: +{2:F2}s, {3:F2}s]\\n"",
+ (user_time_at_last_stat - user_time_at_prev_stat),
+ (user_time_at_last_stat - user_time_at_start),
+ ((real_time_at_last_stat - real_time_at_prev_stat)
+ / (double) System.TimeSpan.TicksPerSecond),
+ ((real_time_at_last_stat - real_time_at_start)
+ / (double) System.TimeSpan.TicksPerSecond)
+ ));
+ // XXX At this point there should be a whole bunch of memory usage
+ // statistics.
+ } catch (System.SystemException e) {
+ // XXX how should we handle I/O errors when printing statistics?
+ }
}
-private static void
-MR_report_full_memory_stats()
+public static void
+ML_report_full_memory_stats(io.MR_MercuryFileStruct stream)
{
// XXX The support for this predicate is even worse. Since we don't have
// access to memory usage statistics, all you get here is an apology.
// But at least it doesn't just crash with an error.
- System.Console.Error.WriteLine(
- ""Sorry, report_full_memory_stats is not yet "" +
- ""implemented for the C# back-end."");
+ try {
+ io.mercury_print_string(stream,
+ ""Sorry, report_full_memory_stats is not yet "" +
+ ""implemented for the C# back-end.\\n"");
+ } catch (System.SystemException e) {
+ // XXX how should we handle I/O errors when printing statistics?
+ }
}
").
diff --git a/library/io.m b/library/io.m
index 8f9bf5d..697bbe4 100644
--- a/library/io.m
+++ b/library/io.m
@@ -1884,8 +1884,6 @@
% Requires the runtime to have been compiled with the macro
% MR_TABLE_STATISTICS defined.
%
- % XXX For now, these predicates work only with the C backend.
- %
:- pred report_stats(io.text_output_stream::in, string::in,
io::di, io::uo) is det.
:- pred report_stats(string::in, io::di, io::uo) is det.
@@ -1893,8 +1891,6 @@
% Write standard memory/time usage statistics to the specified stream,
% or (if none) to stderr.
%
- % XXX For now, these predicates work only with the C backend.
- %
:- pred report_standard_stats(io.text_output_stream::in,
io::di, io::uo) is det.
:- pred report_standard_stats(io::di, io::uo) is det.
@@ -1902,8 +1898,6 @@
% `report_full_memory_stats/3' reports a full memory profile
% to the specified output stream, or (if none) to stderr.
%
- % XXX For now, these predicates work only with the C backend.
- %
:- pred report_full_memory_stats(io.text_output_stream::in,
io::di, io::uo) is det.
:- pred report_full_memory_stats(io::di, io::uo) is det.
@@ -12132,6 +12126,13 @@ report_standard_stats(!IO) :-
MR_report_standard_stats(MR_file(*Stream));
").
+:- pragma foreign_proc("C#",
+ report_standard_stats_2(Stream::in, _IO0::di, _IO::uo),
+ [promise_pure, will_not_call_mercury],
+"
+ benchmarking.ML_report_standard_stats(Stream);
+").
+
:- pragma foreign_proc("Java",
report_standard_stats_2(Stream::in, _IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury],
@@ -12140,9 +12141,6 @@ report_standard_stats(!IO) :-
(jmercury.io.MR_TextOutputFile) Stream);
").
-report_standard_stats_2(_Stream, !IO) :-
- private_builtin.sorry("report_standard_stats").
-
%---------------------%
report_full_memory_stats(output_stream(Stream), !IO) :-
@@ -12162,6 +12160,13 @@ report_full_memory_stats(!IO) :-
MR_report_full_memory_stats(MR_file(*Stream));
").
+:- pragma foreign_proc("C#",
+ report_full_memory_stats_2(Stream::in, _IO0::di, _IO::uo),
+ [promise_pure, will_not_call_mercury],
+"
+ benchmarking.ML_report_full_memory_stats(Stream);
+").
+
:- pragma foreign_proc("Java",
report_full_memory_stats_2(Stream::in, _IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury],
@@ -12170,9 +12175,6 @@ report_full_memory_stats(!IO) :-
(jmercury.io.MR_TextOutputFile) Stream);
").
-report_full_memory_stats_2(_Stream, !IO) :-
- private_builtin.sorry("report_full_memory_stats").
-
%---------------------%
report_tabling_statistics(output_stream(Stream), !IO) :-
More information about the reviews
mailing list