diff --git a/README.Erlang b/README.Erlang index 27dd1540d..0998a83e0 100644 --- a/README.Erlang +++ b/README.Erlang @@ -191,9 +191,7 @@ A. The following language features are not supported and will not be: The following standard library modules are completely unimplemented: - benchmarking bit_buffer - dir thread thread.semaphore time diff --git a/library/benchmarking.m b/library/benchmarking.m index e67fc04f2..c813a245e 100644 --- a/library/benchmarking.m +++ b/library/benchmarking.m @@ -27,6 +27,9 @@ % some memory and time usage statistics about the time period since % 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. % `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(); "). +:- pragma foreign_proc("Erlang", + report_stats, + [may_call_mercury, terminates], +" + 'ML_report_stats'() +"). + %-----------------------------------------------------------------------------% :- 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). @@ -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 ** away, we assign the benchmark output to a volatile global variable. @@ -899,6 +930,13 @@ repeat(N) :- ML_benchmarking_dummy_word = X; "). +:- pragma foreign_proc("Erlang", + do_nothing(_X::in), + [will_not_call_mercury, thread_safe], +" + void +"). + %-----------------------------------------------------------------------------% % Impure integer references.