Øyvind Harboe wrote: > The attached patch allow invoking profile_on() multiple times to set > up a fresh profiling range.
This looks good, but I made some changes. I thought profile_off was worth exporting if it exists, and I moved where the doc is, and tweaked it. Also please remember in future where possible to mention each file modified in the changelog entry (where reasonable as per FSF/GNU standards: <http://www.gnu.org/prep/standards/html_node/Change-Logs.html> although we aren't usually quite as pedantic as that). Thanks for contributing! Jifl Index: ChangeLog =================================================================== RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/ChangeLog,v retrieving revision 1.6.10036.4 diff -u -5 -p -r1.6.10036.4 ChangeLog --- ChangeLog 14 Sep 2006 12:21:56 -0000 1.6.10036.4 +++ ChangeLog 21 Dec 2007 16:23:17 -0000 @@ -1,5 +1,14 @@ +2007-12-14 Oyvind Harboe <[EMAIL PROTECTED]> +2007-12-21 Jonathan Larmour <[EMAIL PROTECTED]> + + * include/profile.h: Declare profile_off. + * src/profile.c: Added support for invoking profile_on() multiple + times. It now stops profiling and sets up a fresh profiling range + on every invocation using new profile_off() function. + * doc/profile.sgml: Document it. + 2005-05-13 Peter Korsgaard <[EMAIL PROTECTED]> * doc/profile.sgml: Fixed typo in HAL support section. 2005-02-18 Bart Veer <[EMAIL PROTECTED]> Index: doc/profile.sgml =================================================================== RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/doc/profile.sgml,v retrieving revision 1.2.10036.3 diff -u -5 -p -r1.2.10036.3 profile.sgml --- doc/profile.sgml 14 Sep 2006 12:21:57 -0000 1.2.10036.3 +++ doc/profile.sgml 21 Dec 2007 16:23:18 -0000 @@ -265,10 +265,23 @@ disproportionally sample code that runs clock. </para></listitem> </varlistentry> </variablelist> <para> +<function>profile_on</function> can be invoked multiple times, and +on subsequent invocations, it will delete profiling data +and allocate a fresh profiling range. + </para> + <para> +Profiling can be turned off using the function +<function>profile_off</function>: +<programlisting> +void profile_off(void); +</programlisting> +This will also reset any existing profile data. + </para> + <para> If the eCos configuration includes a TCP/IP stack and if a tftp daemon will be used to <link linkend="gprof-extract">extract</link> the data from the target then the call to <function>profile_on</function> should happen after the network is up. <filename>profile_on</filename> will attempt to start a tftp daemon thread, and this will fail if Index: include/profile.h =================================================================== RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/include/profile.h,v retrieving revision 1.2.10036.2 diff -u -5 -p -r1.2.10036.2 profile.h --- include/profile.h 14 Sep 2006 12:21:57 -0000 1.2.10036.2 +++ include/profile.h 21 Dec 2007 16:23:18 -0000 @@ -63,10 +63,13 @@ // Enable profiling __externC void profile_on(void *start_addr, void *end_addr, int bucket_size, int sample_resolution); +// Disable and reset profiling +__externC void profile_off(void); + // Callback used by timer routine __externC void __profile_hit(CYG_ADDRWORD pc); // Callgraph support __externC void __profile_mcount(CYG_ADDRWORD /* caller_pc */, CYG_ADDRWORD /* callee_pc */); Index: src/profile.c =================================================================== RCS file: /cvs/ecos/ecos/packages/services/profile/gprof/current/src/profile.c,v retrieving revision 1.4.10036.2 diff -u -5 -p -r1.4.10036.2 profile.c --- src/profile.c 14 Sep 2006 12:21:57 -0000 1.4.10036.2 +++ src/profile.c 21 Dec 2007 16:23:18 -0000 @@ -433,26 +433,65 @@ static struct tftpd_fileops profile_tftp &profile_tftp_read }; #endif // ---------------------------------------------------------------------------- +// stop profiling +void +profile_off(void) +{ + // suspend currently running profiling + profile_enabled = 0; + // Clear all pre-existing profile data + 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 // some of the code. The bucket size controls how many PC addresses // will be treated as a single hit: a smaller bucket increases precision // 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) { int bucket_size; 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. memcpy(profile_gmon_hdr.cookie, GMON_MAGIC, 4); memcpy(profile_gmon_hdr.version, &version, 4); @@ -538,10 +577,11 @@ profile_on(void *_start, void *_end, int profile_enabled = 1; #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 } // EOF profile.c -- eCosCentric Limited http://www.eCosCentric.com/ The eCos experts Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571 Registered in England and Wales: Reg No 4422071. ------["Si fractum non sit, noli id reficere"]------ Opinions==mine
