about summary refs log tree commit diff
path: root/gmon
diff options
context:
space:
mode:
Diffstat (limited to 'gmon')
-rw-r--r--gmon/gmon.c33
-rw-r--r--gmon/sys/gmon.h4
-rw-r--r--gmon/sys/gmon_out.h3
3 files changed, 33 insertions, 7 deletions
diff --git a/gmon/gmon.c b/gmon/gmon.c
index 72b36f99c3..300ca30a09 100644
--- a/gmon/gmon.c
+++ b/gmon/gmon.c
@@ -126,13 +126,12 @@ __monstartup (lowpc, highpc)
     p->tolimit = MAXARCS;
   p->tossize = p->tolimit * sizeof(struct tostruct);
 
-  cp = malloc (p->kcountsize + p->fromssize + p->tossize);
+  cp = calloc (p->kcountsize + p->fromssize + p->tossize, 1);
   if (! cp)
     {
       ERR(_("monstartup: out of memory\n"));
       return;
     }
-  memset (cp, '\0', p->kcountsize + p->fromssize + p->tossize);
   p->tos = (struct tostruct *)cp;
   cp += p->tossize;
   p->kcount = (u_short *)cp;
@@ -296,13 +295,12 @@ write_bb_counts (fd)
 }
 
 
-void
-_mcleanup ()
+static void
+write_gmon (void)
 {
     struct gmon_hdr ghdr __attribute__ ((aligned (__alignof__ (int))));
     int fd;
 
-    __moncontrol (0);
     fd = __open ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY, 0666);
     if (fd < 0)
       {
@@ -328,8 +326,29 @@ _mcleanup ()
     /* write basic-block execution counts: */
     write_bb_counts (fd);
 
+    __close (fd);
+}
+
+
+void
+__write_profiling (void)
+{
+  int save = _gmonparam.state;
+  _gmonparam.state = GMON_PROF_OFF;
+  if (save == GMON_PROF_ON)
+    write_gmon ();
+  _gmonparam.state = save;
+}
+weak_alias (__write_profiling, write_profiling)
+
+
+void
+_mcleanup (void)
+{
+    __moncontrol (0);
+
+    write_gmon ();
+
     /* free the memory. */
     free (_gmonparam.tos);
-
-    __close (fd);
 }
diff --git a/gmon/sys/gmon.h b/gmon/sys/gmon.h
index 8368ca1ce3..930729e7fc 100644
--- a/gmon/sys/gmon.h
+++ b/gmon/sys/gmon.h
@@ -175,6 +175,10 @@ extern void monstartup __P ((u_long __lowpc, u_long __highpc));
 /* Clean up profiling and write out gmon.out.  */
 extern void _mcleanup __P ((void));
 
+/* Write current profiling data to file.  */
+extern void __write_profiling __P ((void));
+extern void write_profiling __P ((void));
+
 __END_DECLS
 
 #endif /* sys/gmon.h */
diff --git a/gmon/sys/gmon_out.h b/gmon/sys/gmon_out.h
index c84f945ce8..83dd1ec83e 100644
--- a/gmon/sys/gmon_out.h
+++ b/gmon/sys/gmon_out.h
@@ -33,6 +33,9 @@
 #define	GMON_MAGIC	"gmon"	/* magic cookie */
 #define GMON_VERSION	1	/* version number */
 
+/* For profiling shared object we need a new format.  */
+#define GMON_SHOBJ_VERSION	0x1ffff
+
 __BEGIN_DECLS
 
 /*