The attached patch allow invoking profile_on() multiple times to set
up a fresh profiling range.




-- 
Øyvind Harboe
http://www.zylin.com - eCos ARM & FPGA  developer kit
### Eclipse Workspace Patch 1.0
#P ecos
Index: services/profile/gprof/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/ChangeLog,v
retrieving revision 1.8
diff -u -r1.8 ChangeLog
--- services/profile/gprof/current/ChangeLog    7 Jun 2005 18:15:02 -0000       
1.8
+++ services/profile/gprof/current/ChangeLog    14 Dec 2007 11:38:21 -0000
@@ -1,3 +1,8 @@
+2007-12-14  Oyvind Harboe  <[EMAIL PROTECTED]>
+
+       * Added support for invoking profile_on() multiple times. It now stops
+       profiling and sets up a fresh profiling range on every invocation.
+       
 2005-05-13  Peter Korsgaard  <[EMAIL PROTECTED]>
 
        * doc/profile.sgml: Fixed typo in HAL support section.
Index: services/profile/gprof/current/doc/profile.sgml
===================================================================
RCS file: 
/cvs/ecos/ecos/packages/services/profile/gprof/current/doc/profile.sgml,v
retrieving revision 1.4
diff -u -r1.4 profile.sgml
--- services/profile/gprof/current/doc/profile.sgml     7 Jun 2005 18:15:02 
-0000       1.4
+++ services/profile/gprof/current/doc/profile.sgml     14 Dec 2007 11:38:22 
-0000
@@ -219,7 +219,9 @@
 <varname>_etext</varname> corresponding to the beginning and end of
 code, so these can be used as the addresses. It is possible to
 perform profiling on a subset of the code if that code is
-located contiguously in memory.
+located contiguously in memory. Note that profile_on() can be invoked
+multiple times, on subsequent invocations, it will delete profiling data
+and allocate a fresh profiling range.
         </para></listitem>
       </varlistentry>
       <varlistentry>
Index: services/profile/gprof/current/src/profile.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/src/profile.c,v
retrieving revision 1.5
diff -u -r1.5 profile.c
--- services/profile/gprof/current/src/profile.c        21 Mar 2005 13:56:10 
-0000      1.5
+++ services/profile/gprof/current/src/profile.c        14 Dec 2007 11:38:23 
-0000
@@ -435,6 +435,29 @@
 #endif
 
 // ----------------------------------------------------------------------------
+// stop profiling
+void 
+profile_off()
+{
+       // suspend currently running profiling
+    profile_enabled             = 0;
+    profile_reset();
+    if (profile_hist_data)
+       free(profile_hist_data);
+    profile_hist_data = NULL;
+#ifdef CYGPKG_PROFILE_CALLGRAPH
+    if (profile_arc_hashtable)
+       free(profile_arc_hashtable);
+    profile_arc_hashtable=NULL;
+    if (profile_arc_records)
+       free(profile_arc_records);
+    profile_arc_records=NULL;  
+#endif
+    
+}
+
+
+// ----------------------------------------------------------------------------
 // profile_on() has to be called by application code to start profiling.
 // Application code will determine the start and end addresses, usually
 // _stext and _etext, but it is possible to limit profiling to only
@@ -443,6 +466,12 @@
 // but requires more memory. The resolution is used to initialize the
 // profiling timer: more frequent interrupts means more accurate results
 // but increases the risk of an overflow.
+//
+// profile_on() can be invoked multiple times. If invoked a second time
+// it will stop the current profiling run and create a new profiling 
+// range.
+
+
 
 void 
 profile_on(void *_start, void *_end, int _bucket_size, int resolution)
@@ -451,6 +480,13 @@
     cyg_uint32      version     = GMON_VERSION;
     CYG_ADDRWORD    text_size   = (CYG_ADDRWORD)_end - (CYG_ADDRWORD)_start;
 
+    if (profile_enabled)
+    {
+       // invoking profile_on a second time
+       profile_off();
+    }
+    
+    
     // Initialize statics. This also ensures that they won't be
     // garbage collected by the linker so a gdb script can safely
     // reference them.
@@ -540,6 +576,7 @@
 
 #ifdef CYGPKG_PROFILE_TFTP    
     // Create a TFTP server to provide the data
+    // invoking this a second time is harmless
     (void) tftpd_start(CYGNUM_PROFILE_TFTP_PORT, &profile_tftp_fileops);
 #endif    
 }

Reply via email to