diff options
Diffstat (limited to 'gmon')
-rw-r--r-- | gmon/Makefile | 12 | ||||
-rw-r--r-- | gmon/bb_init_func.c | 54 | ||||
-rw-r--r-- | gmon/gmon.c | 14 | ||||
-rw-r--r-- | gmon/mcount.c | 2 | ||||
-rw-r--r-- | gmon/prof-freq.c | 55 | ||||
-rw-r--r-- | gmon/profil.c | 42 | ||||
-rw-r--r-- | gmon/sprofil.c | 36 | ||||
-rw-r--r-- | gmon/tst-profile-static.c | 10 |
8 files changed, 212 insertions, 13 deletions
diff --git a/gmon/Makefile b/gmon/Makefile index 80a79456f7..969edd5575 100644 --- a/gmon/Makefile +++ b/gmon/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1995, 1996, 1997, 2001, 2002 Free Software Foundation, Inc. +# Copyright (C) 1995,1996,1997,2001,2002,2005 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -27,7 +27,15 @@ routines := gmon mcount profil sprofil bb_init_func bb_exit_func prof-freq elide-routines.os = bb_init_func bb_exit_func -tests := tst-sprofil +include ../Makeconfig + +tests = tst-sprofil +ifeq ($(build-profile),yes) +tests += tst-profile-static +tests-static += tst-profile-static + +LDFLAGS-tst-profile-static = -profile +endif # The mcount code won't work without a frame pointer. CFLAGS-mcount.c := -fno-omit-frame-pointer diff --git a/gmon/bb_init_func.c b/gmon/bb_init_func.c new file mode 100644 index 0000000000..19901d8d09 --- /dev/null +++ b/gmon/bb_init_func.c @@ -0,0 +1,54 @@ +/* Copyright (C) 1996, 1997, 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Mosberger (davidm@cs.arizona.edu). + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* __bb_init_func is invoked at the beginning of each function, before + any registers have been saved. This generic routine should work + provided that calling this function doesn't mangle the arguments + passed to the function being called. If that's not the case, a + system specific routine must be provided. */ + +#include <sys/types.h> +#include <sys/gmon.h> + +#include <stdlib.h> + +void +__bb_init_func (struct __bb *bb) +{ + struct gmonparam *p = &_gmonparam; + + if (bb->zero_word != 0) + { + return; /* handle common case quickly */ + } + + /* insert this basic-block into basic-block list: */ + bb->zero_word = 1; + bb->next = __bb_head; + __bb_head = bb; + + if (bb->next == 0 && p->state != GMON_PROF_ON) + { + /* we didn't register _mcleanup yet and pc profiling doesn't seem + to be active, so let's register it now: */ + extern void *__dso_handle __attribute__ ((__weak__)); + __cxa_atexit ((void (*) (void *)) _mcleanup, NULL, + &__dso_handle ? __dso_handle : NULL); + } +} diff --git a/gmon/gmon.c b/gmon/gmon.c index 575adbcd8b..1e94aaba5f 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -171,7 +171,7 @@ __monstartup (lowpc, highpc) __moncontrol(1); } -weak_alias(__monstartup, monstartup) +weak_alias (__monstartup, monstartup) static void @@ -331,7 +331,7 @@ write_gmon (void) { size_t len = strlen (env); char buf[len + 20]; - sprintf (buf, "%s.%u", env, __getpid ()); + __snprintf (buf, sizeof (buf), "%s.%u", env, __getpid ()); fd = open_not_cancel (buf, O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666); } @@ -343,14 +343,8 @@ write_gmon (void) { char buf[300]; int errnum = errno; -#ifdef USE_IN_LIBIO - if (_IO_fwide (stderr, 0) > 0) - __fwprintf (stderr, L"_mcleanup: gmon.out: %s\n", - __strerror_r (errnum, buf, sizeof buf)); - else -#endif - fprintf (stderr, "_mcleanup: gmon.out: %s\n", - __strerror_r (errnum, buf, sizeof buf)); + __fxprintf (NULL, "_mcleanup: gmon.out: %s\n", + __strerror_r (errnum, buf, sizeof buf)); return; } } diff --git a/gmon/mcount.c b/gmon/mcount.c index e18bf86e83..32a5f1ea0f 100644 --- a/gmon/mcount.c +++ b/gmon/mcount.c @@ -37,7 +37,7 @@ static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93"; /* This file provides the machine-dependent definitions of the _MCOUNT_DECL and MCOUNT macros. */ -#include "machine-gmon.h" +#include <machine-gmon.h> #include <atomic.h> diff --git a/gmon/prof-freq.c b/gmon/prof-freq.c new file mode 100644 index 0000000000..ffcc67931b --- /dev/null +++ b/gmon/prof-freq.c @@ -0,0 +1,55 @@ +/* Return frequency of ticks reported by profil. Generic version. */ +/*- + * Copyright (c) 1983, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include <sys/types.h> +#include <sys/time.h> +#include <libc-internal.h> + +int +__profile_frequency (void) +{ + /* + * Discover the tick frequency of the machine if something goes wrong, + * we return 0, an impossible hertz. + */ + struct itimerval tim; + + tim.it_interval.tv_sec = 0; + tim.it_interval.tv_usec = 1; + tim.it_value.tv_sec = 0; + tim.it_value.tv_usec = 0; + __setitimer(ITIMER_REAL, &tim, 0); + __setitimer(ITIMER_REAL, 0, &tim); + if (tim.it_interval.tv_usec < 2) + return 0; + return (1000000 / tim.it_interval.tv_usec); +} +libc_hidden_def (__profile_frequency) diff --git a/gmon/profil.c b/gmon/profil.c new file mode 100644 index 0000000000..8736375858 --- /dev/null +++ b/gmon/profil.c @@ -0,0 +1,42 @@ +/* Low-level statistical profiling support function. Stub version. + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> + +/* Enable statistical profiling, writing samples of the PC into at most + SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling + is enabled, the system examines the user PC and increments + SAMPLE_BUFFER[((PC - OFFSET) / 2) * SCALE / 65536]. If SCALE is zero, + disable profiling. Returns zero on success, -1 on error. */ + +int +__profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale) +{ + if (scale == 0) + /* Disable profiling. */ + return 0; + + __set_errno (ENOSYS); + return -1; +} +weak_alias (__profil, profil) +stub_warning (profil) +#include <stub-tag.h> diff --git a/gmon/sprofil.c b/gmon/sprofil.c new file mode 100644 index 0000000000..037ed4672e --- /dev/null +++ b/gmon/sprofil.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + Contributed by David Mosberger-Tang <davidm@hpl.hp.com>. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> + +#include <sys/profil.h> +#include <sys/time.h> + +int +__sprofil (struct prof *profp, int profcnt, struct timeval *tvp, + unsigned int flags) +{ + if (profcnt == 0) + return 0; + + __set_errno (ENOSYS); + return -1; +} + +weak_alias (__sprofil, sprofil) diff --git a/gmon/tst-profile-static.c b/gmon/tst-profile-static.c new file mode 100644 index 0000000000..b2f371e782 --- /dev/null +++ b/gmon/tst-profile-static.c @@ -0,0 +1,10 @@ +#include <stdio.h> +static int +do_test (void) +{ + puts ("Hello world"); + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |