[m-dev.] for review: bootstrap hlc.gc.memprof grade

Peter Ross peter.ross at miscrit.be
Thu Aug 10 19:50:46 AEST 2000


On Thu, Aug 10, 2000 at 06:23:07AM +1000, Fergus Henderson wrote:
> On 09-Aug-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > On Tue, Aug 08, 2000 at 06:14:57PM +1000, Fergus Henderson wrote:
> > > On 02-Aug-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > > > runtime/mercury_prof.c:
> > > > runtime/mercury_prof.h:
> > > >     Make decl_fptr an extern global pointer so that mercury_wrapper.c
> > > >     can call fclose on it.
> > > > 
> > > > runtime/mercury_wrapper.c:
> > > >     Call fclose on decl_fptr.
> > > 
> > > Why do you need to call fclose(decl_ptr) from mercury_wrapper.c?
> > > There's already code to fclose(decl_ptr) in the MR_prof_finish()
> > > function in runtime/mercury_prof.c.  Isn't that the right place
> > > to do the close?
> > > 
> > If you examine the file under WinNT before the file has been closed, bad
> > things happen!  So I changed to code so that fclose happened as soon as
> > possible, unlike MR_prof_finish() which is called at the end of
> > execution.
> 
> Hmm, I think this change may cause more problems than it solves.
> In particular:
> 	- you didn't check the return value from fclose();
> 	  probably you should be calling checked_fclose() rather than fclose().
> 	- you've added a call to MR_fclose(),
> 	  but you didn't remove the old call to MR_fclose(),
> 	  so the file will get closed twice.  This will lead to
> 	  undefined behaviour...
> 	- if do_init_modules() is called multiple times, then
> 	  the file will get closed multiple times, again leading
> 	  to undefined behaviour.
> 
> You need to fix those problems.
> 
> There's also another minor issue: unlike the code in mercury_prof.c,
> you didn't check to see whether decl_fptr is null.  That may be OK I
> guess, but it might be safer to check it.
> 
> I think it would be better to abstract things a little, and do
> the work from some function in mercury_prof.c which gets called
> by mercury_wrapper.c, rather than doing it directly from mercury_wrapper.c.

Hi,


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


Estimated hours taken: 0.5

Refactor the code which closes the `Prof.Decl' file.

mercury_prof.h:
runtime/mercury_prof.c:
    Add a new function MR_close_prof_decl_file which closes the
    `Prof.Decl' file.
    No longer close `Prof.Decl' from MR_prof_finish.
    
mercury_wrapper.c:
    Call MR_close_prof_decl_file() from do_init_modules().


Index: mercury_prof.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.c,v
retrieving revision 1.11
diff -u -r1.11 mercury_prof.c
--- mercury_prof.c	2000/08/09 15:29:05	1.11
+++ mercury_prof.c	2000/08/10 09:46:11
@@ -101,7 +101,7 @@
 
 
 #ifdef PROFILE_CALLS
-  FILE 			*MR_prof_decl_fptr = NULL;
+  static FILE 		*MR_prof_decl_fptr = NULL;
   static prof_call_node	*addr_pair_table[CALL_TABLE_SIZE] = {NULL};
 #endif
 
@@ -613,20 +613,26 @@
 	if (done) return;
 	done = TRUE;
 
+#ifdef PROFILE_CALLS
+	prof_output_addr_pair_table();
+#endif
+
 #ifdef PROFILE_TIME
 	MR_prof_turn_off_time_profiling();
 	prof_output_addr_table();
 #endif
 
+#ifdef PROFILE_MEMORY
+	prof_output_mem_tables();
+#endif
+}
+
+void MR_close_prof_decl_file(void)
+{
 #ifdef PROFILE_CALLS
 	if (MR_prof_decl_fptr) {
 		checked_fclose(MR_prof_decl_fptr, "Prof.Decl");
 	}
-	prof_output_addr_pair_table();
-#endif
-
-#ifdef PROFILE_MEMORY
-	prof_output_mem_tables();
 #endif
 }
 
Index: mercury_prof.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_prof.h
--- mercury_prof.h	2000/08/09 15:29:06	1.8
+++ mercury_prof.h	2000/08/10 09:46:11
@@ -25,13 +25,6 @@
 extern MR_Code *	volatile	MR_prof_current_proc;
 
 /*
-** A pointer to the "Prof.Decl" file.
-*/
-#ifdef PROFILE_CALLS
-  extern FILE	*MR_prof_decl_fptr;
-#endif
-
-/*
 ** The following two macros are used to ensure that the profiler can
 ** use `prof_current_proc' to determine what procedure is currently
 ** being executed when a profiling interrupt occurs.
@@ -74,8 +67,9 @@
 /*
 ** The following functions are used by mercury_wrapper.c to
 ** initiate profiling, at the start of the the program,
-** and to finish up profiling (writing the profiling data to files)
-** at the end of the program.
+** to finish up profiling (writing the profiling data to files)
+** at the end of the program, and to close the `Prof.Decl' file at end of
+** module initialization.
 ** Note that prof_init() calls atexit(prof_finish), so that it can handle
 ** the case where the program exits by calling exit() rather than just
 ** returning, so it is actually not necessary to call prof_finish()
@@ -84,6 +78,7 @@
 
 extern	void	MR_prof_init(void);
 extern	void	MR_prof_finish(void);
+extern	void	MR_close_prof_decl_file(void);
 
 #ifdef PROFILE_TIME
   extern void 	MR_prof_turn_on_time_profiling(void);
Index: mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.66
diff -u -r1.66 mercury_wrapper.c
--- mercury_wrapper.c	2000/08/09 15:29:06	1.66
+++ mercury_wrapper.c	2000/08/10 09:46:20
@@ -421,12 +421,9 @@
 
 	if (! done) {
 		(*address_of_init_modules)();
+		MR_close_prof_decl_file();
 		done = TRUE;
 	}
-
-#ifdef PROFILE_CALLS
-	fclose(MR_prof_decl_fptr);
-#endif
 }
 
 /*

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list