[m-rev.] diff: add library routines for controlling profiling
Peter Ross
pro at missioncriticalit.com
Wed Sep 27 16:19:41 AEST 2006
Hi,
===================================================================
Estimated hours taken: 1
Branches: main
library/benchmarking.m:
Programmatically turn profiling on and off.
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.70
diff -U5 -r1.70 benchmarking.m
--- library/benchmarking.m 7 Aug 2006 06:21:30 -0000 1.70
+++ library/benchmarking.m 27 Sep 2006 06:17:01 -0000
@@ -18,10 +18,11 @@
:- module benchmarking.
:- interface.
:- import_module int.
+:- import_module io.
% `report_stats' is a non-logical procedure intended for use in profiling
% the performance of a program. It has the side-effect of reporting
% some memory and time usage statistics about the time period since
% the last call to report_stats to stderr.
@@ -68,10 +69,51 @@
is cc_multi.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
+ %
+ % Turn off or on the collection of all profiling statistics.
+ %
+:- pred turn_off_profiling(io::di, io::uo) is det.
+:- pred turn_on_profiling(io::di, io::uo) is det.
+
+:- impure pred turn_off_profiling is det.
+:- impure pred turn_on_profiling is det.
+
+ %
+ % Turn off or on the collection of call graph profiling statistics.
+ %
+:- pred turn_off_call_profiling(io::di, io::uo) is det.
+:- pred turn_on_call_profiling(io::di, io::uo) is det.
+
+:- impure pred turn_off_call_profiling is det.
+:- impure pred turn_on_call_profiling is det.
+
+ %
+ % Turn off or on the collection of time spent in each procedure
+ % profiling statistics.
+ %
+:- pred turn_off_time_profiling(io::di, io::uo) is det.
+:- pred turn_on_time_profiling(io::di, io::uo) is det.
+
+:- impure pred turn_off_time_profiling is det.
+:- impure pred turn_on_time_profiling is det.
+
+ %
+ % Turn off or on the collection of memory allocated in each procedure
+ % profiling statistics.
+ %
+:- pred turn_off_heap_profiling(io::di, io::uo) is det.
+:- pred turn_on_heap_profiling(io::di, io::uo) is det.
+
+:- impure pred turn_off_heap_profiling is det.
+:- impure pred turn_on_heap_profiling is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
:- implementation.
%-----------------------------------------------------------------------------%
:- pragma foreign_decl("C", "
@@ -910,9 +952,107 @@
:- pragma foreign_proc("Java",
update_ref(Ref::in, X::in),
[will_not_call_mercury],
"
Ref.value = X;
+").
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+turn_off_profiling(!IO) :-
+ promise_pure ( impure turn_off_profiling ).
+
+turn_on_profiling(!IO) :-
+ promise_pure ( impure turn_on_profiling ).
+
+turn_off_profiling :-
+ impure turn_off_call_profiling,
+ impure turn_off_time_profiling,
+ impure turn_off_heap_profiling.
+
+turn_on_profiling :-
+ impure turn_on_call_profiling,
+ impure turn_on_time_profiling,
+ impure turn_on_heap_profiling.
+
+%-----------------------------------------------------------------------------%
+
+turn_off_call_profiling(!IO) :-
+ promise_pure ( impure turn_off_call_profiling ).
+
+turn_on_call_profiling(!IO) :-
+ promise_pure ( impure turn_on_call_profiling ).
+
+turn_off_time_profiling(!IO) :-
+ promise_pure ( impure turn_off_time_profiling ).
+
+turn_on_time_profiling(!IO) :-
+ promise_pure ( impure turn_on_time_profiling ).
+
+turn_off_heap_profiling(!IO) :-
+ promise_pure ( impure turn_off_heap_profiling ).
+
+turn_on_heap_profiling(!IO) :-
+ promise_pure ( impure turn_on_heap_profiling ).
+
+%-----------------------------------------------------------------------------%
+
+:- pragma foreign_decl(c, local, "
+#include ""mercury_prof.h""
+#include ""mercury_heap_profile.h""
+").
+
+:- pragma foreign_proc(c, turn_off_call_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_CALLS
+ MR_prof_turn_off_call_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_on_call_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_CALLS
+ MR_prof_turn_on_call_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_off_time_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_TIME
+ MR_prof_turn_off_time_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_on_time_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_TIME
+ MR_prof_turn_on_time_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_off_time_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_TIME
+ MR_prof_turn_off_time_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_on_time_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+#ifdef MR_MPROF_PROFILE_TIME
+ MR_prof_turn_on_time_profiling();
+#endif
+").
+
+:- pragma foreign_proc(c, turn_off_heap_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+ MR_prof_turn_off_heap_profiling();
+").
+
+:- pragma foreign_proc(c, turn_on_heap_profiling,
+ [will_not_call_mercury, thread_safe, tabled_for_io], "
+ MR_prof_turn_on_heap_profiling();
").
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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