mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-09 10:52:24 +00:00
Implement `report_stats' and do_nothing for Erlang backend.
Estimated hours taken: 0.5 Branches: main library/benchmarking.m: Implement `report_stats' and do_nothing for Erlang backend. Add a comment that the benchmark_* procedures have a side effect on `report_stats' in Erlang (fixing this raises its own issues). README.Erlang: Remove `benchmarking' and `dir' from the completely unimplemented library modules list.
This commit is contained in:
@@ -191,9 +191,7 @@ A. The following language features are not supported and will not be:
|
|||||||
|
|
||||||
The following standard library modules are completely unimplemented:
|
The following standard library modules are completely unimplemented:
|
||||||
|
|
||||||
benchmarking
|
|
||||||
bit_buffer
|
bit_buffer
|
||||||
dir
|
|
||||||
thread
|
thread
|
||||||
thread.semaphore
|
thread.semaphore
|
||||||
time
|
time
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
% some memory and time usage statistics about the time period since
|
% some memory and time usage statistics about the time period since
|
||||||
% the last call to report_stats to stderr.
|
% the last call to report_stats to stderr.
|
||||||
%
|
%
|
||||||
|
% Note: in Erlang, the benchmark_* procedures will change the apparent time
|
||||||
|
% of the last call to report_stats.
|
||||||
|
%
|
||||||
:- impure pred report_stats is det.
|
:- impure pred report_stats is det.
|
||||||
|
|
||||||
% `report_full_memory_stats' is a non-logical procedure intended for use
|
% `report_full_memory_stats' is a non-logical procedure intended for use
|
||||||
@@ -170,6 +173,13 @@ extern void ML_report_full_memory_stats(void);
|
|||||||
ML_report_full_memory_stats();
|
ML_report_full_memory_stats();
|
||||||
").
|
").
|
||||||
|
|
||||||
|
:- pragma foreign_proc("Erlang",
|
||||||
|
report_stats,
|
||||||
|
[may_call_mercury, terminates],
|
||||||
|
"
|
||||||
|
'ML_report_stats'()
|
||||||
|
").
|
||||||
|
|
||||||
%-----------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
|
|
||||||
:- pragma foreign_code("C", "
|
:- pragma foreign_code("C", "
|
||||||
@@ -712,6 +722,20 @@ ML_report_full_memory_stats() {
|
|||||||
}
|
}
|
||||||
").
|
").
|
||||||
|
|
||||||
|
:- pragma foreign_code("Erlang",
|
||||||
|
"
|
||||||
|
'ML_report_stats'() ->
|
||||||
|
{Time, TimeSinceLastCall} = statistics(runtime),
|
||||||
|
TimeSecs = Time / 1000.0,
|
||||||
|
TimeSinceLastCallSecs = TimeSinceLastCall / 1000.0,
|
||||||
|
|
||||||
|
{value, {total, Bytes}} = lists:keysearch(total, 1, erlang:memory()),
|
||||||
|
KBytes = Bytes / 1024.0,
|
||||||
|
|
||||||
|
io:format(""[Time: ~.3fs, +~.3fs, Total used: ~.3fk]~n"",
|
||||||
|
[TimeSecs, TimeSinceLastCallSecs, KBytes]).
|
||||||
|
").
|
||||||
|
|
||||||
%-----------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
|
|
||||||
:- pragma promise_pure(benchmark_det/5).
|
:- pragma promise_pure(benchmark_det/5).
|
||||||
@@ -852,6 +876,13 @@ repeat(N) :-
|
|||||||
}
|
}
|
||||||
").
|
").
|
||||||
|
|
||||||
|
:- pragma foreign_proc("Erlang",
|
||||||
|
get_user_cpu_milliseconds(Time::out),
|
||||||
|
[will_not_call_mercury],
|
||||||
|
"
|
||||||
|
{Time, _TimeSinceLastCall} = statistics(runtime)
|
||||||
|
").
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** To prevent the C compiler from optimizing the benchmark code
|
** To prevent the C compiler from optimizing the benchmark code
|
||||||
** away, we assign the benchmark output to a volatile global variable.
|
** away, we assign the benchmark output to a volatile global variable.
|
||||||
@@ -899,6 +930,13 @@ repeat(N) :-
|
|||||||
ML_benchmarking_dummy_word = X;
|
ML_benchmarking_dummy_word = X;
|
||||||
").
|
").
|
||||||
|
|
||||||
|
:- pragma foreign_proc("Erlang",
|
||||||
|
do_nothing(_X::in),
|
||||||
|
[will_not_call_mercury, thread_safe],
|
||||||
|
"
|
||||||
|
void
|
||||||
|
").
|
||||||
|
|
||||||
%-----------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
|
|
||||||
% Impure integer references.
|
% Impure integer references.
|
||||||
|
|||||||
Reference in New Issue
Block a user