aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/gmon.h
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>1995-12-29 15:30:05 +0000
committerBruce Evans <bde@FreeBSD.org>1995-12-29 15:30:05 +0000
commit912e60377833803e8c89e2cbfd4c8eb8a6d90280 (patch)
tree9ce1e55534d3d930aead3ff55aeb7fcedbc086a4 /sys/sys/gmon.h
parent703a371f1a0ab9292eab79ecfde2f156af78c652 (diff)
downloadsrc-912e60377833803e8c89e2cbfd4c8eb8a6d90280.tar.gz
src-912e60377833803e8c89e2cbfd4c8eb8a6d90280.zip
Implemented non-statistical kernel profiling. This is based on
looking at a high resolution clock for each of the following events: function call, function return, interrupt entry, interrupt exit, and interesting branches. The differences between the times of these events are added at appropriate places in a ordinary histogram (as if very fast statistical profiling sampled the pc at those places) so that ordinary gprof can be used to analyze the times. gmon.h: Histogram counters need to be 4 bytes for microsecond resolutions. They will need to be larger for the 586 clock. The comments were vax-centric and wrong even on vaxes. Does anyone disagree? gprof4.c: The standard gprof should support counters of all integral sizes and the size of the counter should be in the gmon header. This hack will do until then. (Use gprof4 -u to examine the results of non-statistical profiling.) config/*: Non-statistical profiling is configured with `config -pp'. `config -p' still gives ordinary profiling. kgmon/*: Non-statistical profiling is enabled with `kgmon -B'. `kgmon -b' still enables ordinary profiling (and distables non-statistical profiling) if non-statistical profiling is configured.
Notes
Notes: svn path=/head/; revision=13107
Diffstat (limited to 'sys/sys/gmon.h')
-rw-r--r--sys/sys/gmon.h64
1 files changed, 56 insertions, 8 deletions
diff --git a/sys/sys/gmon.h b/sys/sys/gmon.h
index 9b3882de918a..619e94c45acb 100644
--- a/sys/sys/gmon.h
+++ b/sys/sys/gmon.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)gmon.h 8.2 (Berkeley) 1/4/94
- * $Id: gmon.h,v 1.6 1995/05/30 08:14:22 rgrimes Exp $
+ * $Id: gmon.h,v 1.7 1995/08/29 03:09:14 bde Exp $
*/
#ifndef _SYS_GMON_H_
@@ -49,18 +49,33 @@ struct gmonhdr {
int version; /* version number */
int profrate; /* profiling clock rate */
int spare[3]; /* reserved */
+ /* XXX should record counter size and density */
};
#define GMONVERSION 0x00051879
/*
- * histogram counters are unsigned shorts (according to the kernel).
+ * Type of histogram counters used in the kernel.
*/
+#ifdef GPROF4
+#define HISTCOUNTER unsigned
+#else
#define HISTCOUNTER unsigned short
+#endif
/*
- * fraction of text space to allocate for histogram counters here, 1/2
+ * Fraction of text space to allocate for histogram counters.
+ * We allocate counters at the same or higher density as function
+ * addresses, so that each counter belongs to a unique function.
+ * A lower density of counters would give less resolution but a
+ * higher density would be wasted.
+ *
+ * Assume that function addresses are at least 4-byte-aligned.
+ * It would be better to get the linker to align functions more
+ * strictly so that we could use smaller tables.
*/
-#define HISTFRACTION 2
+#define FUNCTION_ALIGNMENT 4
+#define HISTFRACTION (FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER) == 0 \
+ ? 1 : FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER))
/*
* Fraction of text space to allocate for from hash buckets.
@@ -90,7 +105,23 @@ struct gmonhdr {
* profiling data structures without (in practice) sacrificing
* any granularity.
*/
-#define HASHFRACTION 2
+/*
+ * XXX I think the above analysis completely misses the point. I think
+ * the point is that addresses in different functions must hash to
+ * different values. Since the hash is essentially division by
+ * sizeof(unsigned short), the correct formula is:
+ *
+ * HASHFRACTION = MIN_FUNCTION_ALIGNMENT / sizeof(unsigned short)
+ *
+ * Note that he unsigned short here has nothing to do with the one for
+ * HISTFRACTION.
+ *
+ * Hash collisions from a two call sequence don't matter. They get
+ * handled like collisions for calls to different addresses from the
+ * same address through a function pointer.
+ */
+#define HASHFRACTION (FUNCTION_ALIGNMENT / sizeof(unsigned short) == 0 \
+ ? 1 : FUNCTION_ALIGNMENT / sizeof(unsigned short))
/*
* percent of text space to allocate for tostructs with a minimum.
@@ -132,17 +163,33 @@ struct rawarc {
*/
struct gmonparam {
int state;
- u_short *kcount;
+ HISTCOUNTER *kcount;
u_long kcountsize;
u_short *froms;
u_long fromssize;
struct tostruct *tos;
u_long tossize;
long tolimit;
- u_long lowpc;
- u_long highpc;
+ fptrint_t lowpc;
+ fptrint_t highpc;
u_long textsize;
u_long hashfraction;
+ u_long profrate;
+ HISTCOUNTER *cputime_count;
+ u_int cputime_overhead;
+ u_int cputime_overhead_frac;
+ u_int cputime_overhead_resid;
+ u_int cputime_overhead_sub;
+ HISTCOUNTER *mcount_count;
+ u_int mcount_overhead;
+ u_int mcount_overhead_frac;
+ u_int mcount_overhead_resid;
+ u_int mcount_overhead_sub;
+ HISTCOUNTER *mexitcount_count;
+ u_int mexitcount_overhead;
+ u_int mexitcount_overhead_frac;
+ u_int mexitcount_overhead_resid;
+ u_int mexitcount_overhead_sub;
};
extern struct gmonparam _gmonparam;
@@ -153,6 +200,7 @@ extern struct gmonparam _gmonparam;
#define GMON_PROF_BUSY 1
#define GMON_PROF_ERROR 2
#define GMON_PROF_OFF 3
+#define GMON_PROF_HIRES 4
/*
* Sysctl definitions for extracting profiling information from the kernel.