[PATCH] fix BSD-style old format gmon.out reading

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] fix BSD-style old format gmon.out reading

Brian Dessent

The codepath in gprof for reading the old BSD style gmon.out file format
seems to have bitrotted, specifically the histogram data handling.  This
codepath does not go through hist.c:read_histogram_header() or
hist.c:hist_read_rec() but instead happens all in
gmon_io.c:gmon_out_read().  At issue are two global variables
num_histograms and hist_scale which don't get set.  This causes the
later logic to think that there is no histogram data even though it has
been successfully read.  The attached patch fixes the issue.

This came up because a Cygwin user reported that gprof didn't function
at all for them.  Debugging revealed bugs in both the Cygwin side as
well as the gprof side.  Ideally it might be nice to update Cygwin to
write the more modern GNU format gmon.out format, but since the
profiling code there is lifted from the BSDs it currently writes the old
format.

Brian
2008-08-04  Brian Dessent  <[hidden email]>

        * gmon_io.c (gmon_out_read): When reading old format gmon.out,
        set num_histograms and hist_scale.

Index: gmon_io.c
===================================================================
RCS file: /cvs/src/src/gprof/gmon_io.c,v
retrieving revision 1.24
diff -u -p -r1.24 gmon_io.c
--- gmon_io.c 6 Jul 2007 10:40:34 -0000 1.24
+++ gmon_io.c 5 Aug 2008 04:48:00 -0000
@@ -493,10 +493,13 @@ gmon_out_read (const char *filename)
 
       if (!histograms)
  {
+  num_histograms = 1;
   histograms = xmalloc (sizeof (struct histogram));
   histograms->lowpc = tmp.low_pc;
   histograms->highpc = tmp.high_pc;
   histograms->num_bins = hist_num_bins;
+  hist_scale = (double)((tmp.high_pc - tmp.low_pc) / sizeof (UNIT))
+    / hist_num_bins;
   histograms->sample = xmalloc (hist_num_bins * sizeof (int));
   memset (histograms->sample, 0,
   hist_num_bins * sizeof (int));
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] fix BSD-style old format gmon.out reading

Alan Modra
On Mon, Aug 04, 2008 at 10:00:25PM -0700, Brian Dessent wrote:
> * gmon_io.c (gmon_out_read): When reading old format gmon.out,
> set num_histograms and hist_scale.

OK.

--
Alan Modra
Australia Development Lab, IBM