This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
gprof synth dump feature
- From: Simon Kallweit <simon dot kallweit at intefo dot ch>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Wed, 22 Jul 2009 17:01:41 +0200
- Subject: gprof synth dump feature
This little patch adds a feature to dump the profiling data directly to
the host filesystem when running on the synth target.
diff --git a/packages/services/profile/gprof/current/ChangeLog b/packages/services/profile/gprof/current/ChangeLog
index e533fac..005428e 100644
--- a/packages/services/profile/gprof/current/ChangeLog
+++ b/packages/services/profile/gprof/current/ChangeLog
@@ -1,3 +1,12 @@
+2009-07-22 Simon Kallweit <simon.kallweit@intefo.ch>
+
+ * cdl/profile_gprof.cdl:
+ * src/profile.h:
+ * src/profile.c: Implemented direct dump of profiling data to the
+ host file system when running gprof on the synth target. Introduced
+ CYGFUN_PROFILE_SYNTH_DUMP to enable the feature, and
+ profile_synth_dump() to perform the dump.
+
2007-10-14 Oyvind Harboe <oyvind.harboe@zylin.com>
* src/profile.c: do not relaunch tftpd thread upon second invocation
diff --git a/packages/services/profile/gprof/current/cdl/profile_gprof.cdl b/packages/services/profile/gprof/current/cdl/profile_gprof.cdl
index 31f5f25..7b305ea 100644
--- a/packages/services/profile/gprof/current/cdl/profile_gprof.cdl
+++ b/packages/services/profile/gprof/current/cdl/profile_gprof.cdl
@@ -8,7 +8,7 @@
## ####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
-## Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+## Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
@@ -158,6 +158,15 @@ cdl_package CYGPKG_PROFILE_GPROF {
}
}
+ cdl_option CYGFUN_PROFILE_SYNTH_DUMP {
+ display "Allow the profile data synth dump"
+ default_value 0
+ requires CYGPKG_HAL_SYNTH
+ description "
+ Allows the profile data to be dumped directly to the host
+ filesystem. This does only work when running the synth target."
+ }
+
cdl_component CYGPKG_PROFILE_GPROF_OPTIONS {
display "Profiling build options"
flavor none
diff --git a/packages/services/profile/gprof/current/include/profile.h b/packages/services/profile/gprof/current/include/profile.h
index 25462f8..c521398 100644
--- a/packages/services/profile/gprof/current/include/profile.h
+++ b/packages/services/profile/gprof/current/include/profile.h
@@ -11,7 +11,7 @@
// ####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
-// Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
@@ -66,6 +66,11 @@ __externC void profile_on(void *start_addr, void *end_addr,
// Disable and reset profiling
__externC void profile_off(void);
+#ifdef CYGFUN_PROFILE_SYNTH_DUMP
+// Dump profile data to the host filesystem
+__externC void profile_synth_dump(void);
+#endif
+
// Callback used by timer routine
__externC void __profile_hit(CYG_ADDRWORD pc);
diff --git a/packages/services/profile/gprof/current/src/profile.c b/packages/services/profile/gprof/current/src/profile.c
index 70ea198..fa1e905 100644
--- a/packages/services/profile/gprof/current/src/profile.c
+++ b/packages/services/profile/gprof/current/src/profile.c
@@ -8,7 +8,7 @@
// ####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
-// Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
@@ -64,6 +64,11 @@
# include <tftp_support.h>
#endif
+#ifdef CYGFUN_PROFILE_SYNTH_DUMP
+# include <cyg/hal/hal_io.h>
+#endif
+
+
// ----------------------------------------------------------------------------
// A gmon.out file starts with a struct gmon_hdr containing a cookie
// "gmon", a format version number, and some spare bytes. The structure
@@ -587,4 +592,45 @@ profile_on(void *_start, void *_end, int _bucket_size, int resolution)
#endif
}
+#ifdef CYGFUN_PROFILE_SYNTH_DUMP
+
+// Dump profile data to the host filesystem
+void
+profile_synth_dump(void)
+{
+ int fd;
+ int arc_index;
+
+#ifdef CYGPKG_PROFILE_CALLGRAPH
+ if (profile_arc_overflow) {
+ diag_printf("Profiling: warning, the table of callgraph arcs has overflowed\n");
+ diag_printf("This can be avoided by increasing CYGNUM_PROFILE_CALLGRAPH_ARC_PERCENTAGE\n");
+ }
+#endif
+
+ fd = cyg_hal_sys_open(
+ "gmon.out", CYG_HAL_SYS_O_WRONLY | CYG_HAL_SYS_O_CREAT,
+ CYG_HAL_SYS_S_IRWXU | CYG_HAL_SYS_S_IRWXG | CYG_HAL_SYS_S_IRWXO);
+
+ if (fd == -ENOENT) {
+ CYG_FAIL("Creating 'gmon.out' failed!");
+ return;
+ }
+
+ cyg_hal_sys_write(fd, &profile_gmon_hdr, sizeof(struct gmon_hdr));
+ cyg_hal_sys_write(fd, &profile_tags[0], 1);
+ cyg_hal_sys_write(fd, &profile_hist_hdr, sizeof(struct gmon_hist_hdr));
+ cyg_hal_sys_write(fd, profile_hist_data,
+ profile_hist_hdr.hist_size * sizeof(cyg_uint16));
+ for (arc_index = 1; arc_index < profile_arc_next; arc_index++) {
+ // gmon.out should contain a 1 byte tag followed by each arc record.
+ cyg_hal_sys_write(fd, &(profile_arc_records[arc_index].tags[3]),
+ sizeof(struct gmon_cg_arc_record) + 1);
+ }
+
+ cyg_hal_sys_close(fd);
+}
+
+#endif
+
// EOF profile.c