[m-rev.] for review: programatically turn profiling on and off

Peter Ross pro at missioncriticalit.com
Tue Sep 26 05:05:03 AEST 2006


Hi,

Provided no-one sees problems with this change.  The next plan is
to add a library module which allows one to turn profiling on and
off as impure predicates.

This change is used here at MC to ignore the start up of our latest
server which is very slow and allocates lots of memory and hence
drowns out the rest of the profile unless you run the program for
a very long time.

===================================================================


Estimated hours taken: 1
Branches: main

Add the ability to turn profiling off and on programatically.
This allows one to ignore parts of a running program in the
profile.

runtime/mercury_heap_profile.c:
runtime/mercury_heap_profile.h:
	Add the ability to turn off and on heap profiling.
	
runtime/mercury_prof.c:
runtime/mercury_prof.h:
	Add the ability to stop recording the call graph.
	Check if time profiling is on or off before turning
	it on or off as it seems to be problematic to turn
	on already turned on profiling.

Index: runtime/mercury_heap_profile.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap_profile.c,v
retrieving revision 1.5
diff -U5 -r1.5 mercury_heap_profile.c
--- runtime/mercury_heap_profile.c	18 Feb 2002 07:01:16 -0000	1.5
+++ runtime/mercury_heap_profile.c	25 Sep 2006 18:54:45 -0000
@@ -28,10 +28,13 @@
 /* all fields of these variables are initialized to 0 */
 MR_memprof_counter	MR_memprof_overall;
 MR_memprof_table	MR_memprof_procs;
 MR_memprof_table	MR_memprof_types;
 
+/* private global variables */
+static int		profile_heap = MR_TRUE;
+
 /*
 ** Initialize a heap profiling counter.
 */
 static void
 MR_init_counter(MR_memprof_counter *counter)
@@ -123,14 +126,29 @@
 */
 void
 MR_record_allocation(int size, MR_Code *proc_addr,
 	const char *proc_name, const char *type)
 {
+	if (!profile_heap) {
+		return;
+	}
+
 	/*
 	** Increment the overall totals,
 	** record the allocation in the per-procedure table, and
 	** record the allocation in the per-type table.
 	*/
 	MR_increment_counter(&MR_memprof_overall, size);
 	MR_increment_table_entry(&MR_memprof_procs, proc_name, proc_addr, size);
 	MR_increment_table_entry(&MR_memprof_types, type, NULL, size);
+}
+
+void
+MR_prof_turn_on_heap_profiling(void)
+{
+        profile_heap = MR_TRUE;
+}
+
+void MR_prof_turn_off_heap_profiling(void)
+{
+        profile_heap = MR_FALSE;
 }
Index: runtime/mercury_heap_profile.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap_profile.h,v
retrieving revision 1.4
diff -U5 -r1.4 mercury_heap_profile.h
--- runtime/mercury_heap_profile.h	27 Dec 2001 07:25:23 -0000	1.4
+++ runtime/mercury_heap_profile.h	25 Sep 2006 18:54:45 -0000
@@ -106,8 +106,16 @@
 */
 extern void MR_prof_output_mem_tables(void);
 
 /*---------------------------------------------------------------------------*/
 
+/*
+** At runtime turn heap profiling on or off.
+*/
+extern void MR_prof_turn_on_heap_profiling(void);
+extern void MR_prof_turn_off_heap_profiling(void);
+
+/*---------------------------------------------------------------------------*/
+
 #endif /* MERCURY_HEAP_PROFILE_H */
 
 /*---------------------------------------------------------------------------*/
Index: runtime/mercury_prof.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.c,v
retrieving revision 1.22
diff -U5 -r1.22 mercury_prof.c
--- runtime/mercury_prof.c	18 Feb 2002 07:01:19 -0000	1.22
+++ runtime/mercury_prof.c	25 Sep 2006 18:54:45 -0000
@@ -85,15 +85,17 @@
 */
 
 static volatile	int		in_profiling_code = MR_FALSE;
 
 #ifdef MR_MPROF_PROFILE_CALLS
+  static int             profile_calls = MR_TRUE;
   static FILE 		*MR_prof_decl_fptr = NULL;
   static prof_call_node	*addr_pair_table[CALL_TABLE_SIZE] = {NULL};
 #endif
 
 #ifdef MR_MPROF_PROFILE_TIME
+  static int		profile_time = MR_FALSE;
   static prof_time_node	*addr_table[TIME_TABLE_SIZE] = {NULL};
 #endif
 
 /*
 ** Local function declarations
@@ -135,10 +137,14 @@
 MR_prof_call_profile(MR_Code *Callee, MR_Code *Caller)
 {
 	prof_call_node	*node, **node_addr, *new_node;
 	int		 hash_value;
 
+        if (!profile_calls) {
+                return;
+        }
+
 	in_profiling_code = MR_TRUE;
 
 	hash_value = hash_addr_pair(Callee, Caller);
 
 	node_addr = &addr_pair_table[hash_value];
@@ -461,22 +467,41 @@
 		MR_checked_fclose(MR_prof_decl_fptr, "Prof.Decl");
 	}
 #endif
 }
 
+#ifdef MR_MPROF_PROFILE_CALLS
+void
+MR_prof_turn_on_call_profiling(void)
+{
+        profile_calls = MR_TRUE;
+}
+
+void MR_prof_turn_off_call_profiling(void)
+{
+        profile_calls = MR_FALSE;
+}
+#endif
+
 #ifdef MR_MPROF_PROFILE_TIME
 
 void
 MR_prof_turn_on_time_profiling(void)
 {
-	MR_turn_on_time_profiling(prof_handle_tick);
+	if (!profile_time) {
+		MR_turn_on_time_profiling(prof_handle_tick);
+		profile_time = MR_TRUE;
+	}
 }
 
 void
 MR_prof_turn_off_time_profiling(void)
 {
-	MR_turn_off_time_profiling();
+	if (profile_time) {
+		MR_turn_off_time_profiling();
+		profile_time = MR_FALSE;
+	}
 }
 
 #endif
 
 /* ======================================================================== */
Index: runtime/mercury_prof.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.h,v
retrieving revision 1.16
diff -U5 -r1.16 mercury_prof.h
--- runtime/mercury_prof.h	20 Jun 2005 02:16:44 -0000	1.16
+++ runtime/mercury_prof.h	25 Sep 2006 18:54:45 -0000
@@ -94,10 +94,15 @@
 
 extern	void	MR_prof_init(void);
 extern	void	MR_prof_finish(void);
 extern	void	MR_close_prof_decl_file(void);
 
+#ifdef MR_MPROF_PROFILE_CALLS
+  extern void 	MR_prof_turn_on_call_profiling(void);
+  extern void	MR_prof_turn_off_call_profiling(void);
+#endif
+
 #ifdef MR_MPROF_PROFILE_TIME
   extern void 	MR_prof_turn_on_time_profiling(void);
   extern void	MR_prof_turn_off_time_profiling(void);
 #endif
 

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