diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:44:09 +0000 |
commit | 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b (patch) | |
tree | acd4001a266a8713495af7f1b2102b61e67113b0 /mdk-stage1/dietlibc/profiling | |
parent | 71b111ec6c4671667a19c6fbe0023d33422535d7 (diff) | |
download | drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.gz drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.bz2 drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.tar.xz drakx-backup-do-not-use-4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b.zip |
Import dietlibc 0.22 + other fixes for AMD64
Diffstat (limited to 'mdk-stage1/dietlibc/profiling')
-rw-r--r-- | mdk-stage1/dietlibc/profiling/PORTING | 25 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/profiling/README | 37 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/profiling/__mcount.c | 24 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/profiling/monitor.c | 93 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/profiling/profil.c | 75 |
5 files changed, 254 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/profiling/PORTING b/mdk-stage1/dietlibc/profiling/PORTING new file mode 100644 index 000000000..c3fc5eba7 --- /dev/null +++ b/mdk-stage1/dietlibc/profiling/PORTING @@ -0,0 +1,25 @@ + Porting to other platforms + + ... is easy. Just create an mcount.S in the $ARCH + directory (eg. dietlibc/i386) which includes a + function (called "mcount") that: + + 1.) saves ALL registers that are freely usable + and which might be used by __mcount(). + 2.) loads the instruction pointer (PC) from the + function that called mcount, and the function + which called the function, that called mcount + into the first two argument registers (or push + them on the stack - depending on the processor- + architecture). + 3.) call __mcount. + 4.) restore the registers saved in 1) + + Then You need a macro called PC in <asm/sigcontext.h> + which extracts the (instruction pointer / program + counter) from a sigcontext structure (eg. on i386 this + would be ctx.eip). + + $ARCH/start.S must also be modified to call monitor + with the offset of .text and _etext as parameters. + diff --git a/mdk-stage1/dietlibc/profiling/README b/mdk-stage1/dietlibc/profiling/README new file mode 100644 index 000000000..0a0293073 --- /dev/null +++ b/mdk-stage1/dietlibc/profiling/README @@ -0,0 +1,37 @@ + + Notes on profiling support for dietlibc + + 1.) A big problem when doing profiling on statically linked + programs, is that the internal profiling functions (mcount + and friends) will be included in the call graph although + they would not if the program would have been dynamically + linked. This is because every symbol between .text and + _etext is included in the call-graph. If a program is + dynamically linked, then mcount and friends are not between + .text and _etext, so they are not included. A workaround + for this, would be to put mcount, __mcount, monitor and + profiler into another section (eg. ".profile"), but this + creates some strange problems, I'm currently not aware of. + If you want to debug this: Putting a function into a specific + section works like this (with gcc): + + void foo (int bar) __attribute__ ((section(".foobar"))) + + 2.) _start may randomly be found in the callgraph. I don't + know why. May be a bug in gprof. + + 3.) The profiling is a complete rewrite, though I looked at + the glibc Version for inspiration. Please note that this + version might not be as portable as the glibc version but + its much smaller (although this is not a really important + argument, as profiled binaries seldom get shipped) and + hopefully easier to understand. + + 4.) all objects that should be profiled mustn't be compiled + with -fomit-frame-pointer (as with glibc). Add + -fno-fomit-frame-pointer to $CFLAGS if you're encountering + weird problems. + + 5.) There is currently no basic-block statistic support. + +Please send comments and bug reports to: tom@rhadamanthys.org diff --git a/mdk-stage1/dietlibc/profiling/__mcount.c b/mdk-stage1/dietlibc/profiling/__mcount.c new file mode 100644 index 000000000..b1955f370 --- /dev/null +++ b/mdk-stage1/dietlibc/profiling/__mcount.c @@ -0,0 +1,24 @@ +#include <unistd.h> +#include <sys/gmon.h> + +extern struct monparam mparam; + +void __mcount (unsigned long, unsigned long) PROF_SECTION; + +void +__mcount (unsigned long frompc, unsigned long selfpc) +{ + struct rawarc *arc = mparam.arcs, thisarc; + unsigned long num; + /* If arc already exists, increment count */ + for (num = 0; num < mparam.arcnum; num++) + if (arc[num].raw_frompc == frompc && arc[num].raw_selfpc == selfpc) { + arc[num].raw_count++; + return; + } + if (selfpc < mparam.lowpc || selfpc > mparam.highpc) return; + thisarc.raw_frompc = frompc; + thisarc.raw_selfpc = selfpc; + thisarc.raw_count = 1; + arc[mparam.arcnum++] = thisarc; +} diff --git a/mdk-stage1/dietlibc/profiling/monitor.c b/mdk-stage1/dietlibc/profiling/monitor.c new file mode 100644 index 000000000..cc06e3465 --- /dev/null +++ b/mdk-stage1/dietlibc/profiling/monitor.c @@ -0,0 +1,93 @@ +/************************************************************** + Copyright (C) 2001, 2002 Thomas M. Ogrisegg + + This is free software. You can redistribute and modify + it under the terms of the GNU General Public License. + + This file is part of the profiling support for dietlibc + + monitor(3) interface + + *************************************************************/ +#include <sys/uio.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdlib.h> +#include <sys/gmon.h> + +typedef unsigned short u_short; + +struct monparam mparam; + +void monitor (unsigned long, unsigned long) PROF_SECTION; +void _stop_monitor (void) PROF_SECTION; + +/* + monitor is called by _start, to start profiling + lowpc -> lowest valid program counter (normally .text) + highpc -> highest valid program counter (normally _etext) +*/ +void +monitor (unsigned long lowpc, unsigned long highpc) +{ + mparam.highpc = highpc; + mparam.lowpc = lowpc; + mparam.kcountsize = (mparam.textsize = highpc-lowpc) << 1; + mparam.kcount = (u_short *) malloc (mparam.kcountsize); + mparam.arcs = (struct rawarc *) malloc (MAXARCS*sizeof (struct rawarc)); + if (!mparam.kcount || !mparam.arcs) + exit (42); + mparam.arcnum = 0; + /* start profiling */ + profil (mparam.kcount, highpc-lowpc, lowpc, 10000); +} + +/* + write_gmon - write all data collected by the helper routines + to gmon.out +*/ +static void +write_gmon (void) +{ + struct gmon_hdr ghdr = { "gmon", 1, "" }; + int fd = open ("gmon.out", O_CREAT | O_RDWR | O_TRUNC, 0666); + + if (fd < 0) return; + write (fd, &ghdr, sizeof (ghdr)); + if (mparam.kcountsize) + { + char tag = GMON_TAG_TIME_HIST; + struct gmon_hist_hdr ghdr = { + mparam.lowpc, mparam.highpc, + (mparam.kcountsize >> 1), 100, "seconds", 's' + }; + struct iovec iov[3] = { + { &tag, sizeof (tag) }, + { &ghdr, sizeof (ghdr) }, + { mparam.kcount, mparam.kcountsize >> 1 << 1 } + }; + writev (fd, iov, 3); + } + if (mparam.arcnum) + { + char tag = GMON_TAG_CG_ARC; + struct iovec iov[mparam.arcnum*2]; + unsigned long l; + for (l=0;l<mparam.arcnum;l++) { + iov[l*2].iov_base = &tag; + iov[l*2].iov_len = sizeof (tag); + iov[l*2+1].iov_base = &mparam.arcs[l]; + iov[l*2+1].iov_len = sizeof (mparam.arcs[l]); + } + writev (fd, iov, mparam.arcnum*2); + } + close (fd); +} + +/* called by _start before exit */ +void +_stop_monitor (void) +{ + profil (NULL, 0, 0, 0); + write_gmon (); +} diff --git a/mdk-stage1/dietlibc/profiling/profil.c b/mdk-stage1/dietlibc/profiling/profil.c new file mode 100644 index 000000000..fa9a0ef2b --- /dev/null +++ b/mdk-stage1/dietlibc/profiling/profil.c @@ -0,0 +1,75 @@ +/****************************************************** + Copyright (C) 2001, 2002 Thomas M. Ogrisegg + + This is free software. You can redistribute and modify + it under the terms of the GNU General Public License. + + This file is part of the profiling support for dietlibc + + profil (3) generic implementation + + *************************************************************/ + +#include <asm/sigcontext.h> +#include <sys/types.h> +#include <sys/time.h> +#include <unistd.h> +#include <signal.h> + +#define SHORT_SIZE sizeof (short) +#define MAX_SHORT 65536 + +#ifdef DEBUG +# include <stdio.h> +# define debug printf +#else +# define debug +#endif + +#ifndef u_short +# define u_short unsigned short +#endif + +#ifndef u_int +# define u_int unsigned int +#endif + +static unsigned short *buffer = NULL; +static size_t maxhits = 0; +static unsigned long low_pc = 0; +static unsigned long pscale = 0; + +/* profiler - helper function for profil(3) */ +static void +profiler (int signal, struct sigcontext ctx) +{ + size_t s = PC(ctx)-low_pc; + (void)signal; + if ((PC(ctx)) < low_pc) return; + s >>= 1; + if (s < maxhits) + ++buffer[s]; +} + +/* profil(3) - start or stop the profiling timer */ +int +profil (u_short *buf, size_t bufsiz, size_t offset, u_int scale) +{ + struct itimerval itv = { { 0, 1 }, { 0, 1 } }; + struct sigaction sa; + if (!buf) { + sigaction (SIGPROF, NULL, NULL); + setitimer (ITIMER_PROF, NULL, NULL); + return (0); + } + sa.sa_handler = (sighandler_t)&profiler; + sa.sa_flags = SA_RESTART; + sigfillset (&sa.sa_mask); + sigaction (SIGPROF, &sa, NULL); + pscale = scale; + buffer = buf; + low_pc = offset; + maxhits = bufsiz/SHORT_SIZE; + + return (setitimer (ITIMER_PROF, &itv, &itv)); +} |