sprofil() implementation
Attached below is an implementation of the sprofil() call. My main motivation for adding this was to be able to support profiling with 32-bit counters (16-bit counters would overflow after just one minute on IA-64 Linux...), but the routine is designed to also work well with lots of text sections, so this could provide the foundation for profiling shared binaries.
Some comments:
- it hasn't been tested very much so far, though the included test program works as expected and it does attempt to stress some of the more complex aspects of sprofil()
- the patch for the Makefile isn't quite right; I couldn't figure out what I needed to do to get "make check" to build and run the tst-sprofil program
- the code has been tested on IA-64 Linux only, though I did try to make it as portable as the profil() implementation
- when a histogram counter exceeds the maximum value, instead of wrapping around, this implementation of sprofil() leaves the counter at the saturated value; this is different from profil() but I think it's a better behavior and I didn't see it precluded in any of the documentation I had access to
Note that in order to use the 32-bit profiling counters, you'll also need a gprof patch (and a few more patches to the gmon support). Unfortunately, those patches are not ready yet...
Enjoy,
--david
2001-03-20 David Mosberger <[email protected]>
* sysdeps/generic/sprofil.c: New file.
* sysdeps/posix/sprofil.c: Ditto.
* gmon/tst-sprofil.c: Ditto.
* gmon/sys/profil.h: Ditto.
gmon/Makefile +4 -2
@@ -23,7 +23,7 @@ headers := sys/gmon.h sys/gmon_out.h distribute := machine-gmon.h profil-counter.h -routines := gmon mcount profil bb_init_func bb_exit_func prof-freq +routines := gmon mcount profil sprofil bb_init_func bb_exit_func prof-freq include ../Rules
@@ -35,9 +35,11 @@ # On systems where `profil' is not a system call, the same # problem exists for the internal functions in profil.c. +tests := tst-sprofil + noprof := mcount ifeq (,$(filter profil,$(unix-syscalls))) -noprof += profil +noprof += profil sprofil endif $(noprof:%=$(objpfx)%.op): %.op: %.o
gmon/sys/profil.h +61 -0
61 lines not on this page · raw message
gmon/tst-sprofil.c +164 -0
164 lines not on this page · raw message
sysdeps/generic/sprofil.c +37 -0
@@ -0,0 +1,37 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. +Contributed by David Mosberger-Tang <[email protected]>. + +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 Library General Public License as +published by the Free Software Foundation; either version 2 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. 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)
sysdeps/posix/sprofil.c +354 -0
354 lines not on this page · raw message
David Mosberger <[email protected]> writes:
|> +size_t taddr[] |> + {
|> + 0x00001000, /* elf32/hppa */
|> + 0x08048000, /* elf32/x86 */
|> + 0x00400000, /* elf32/mips */
|> + 0x01800000, /* elf32/ppc */
|> + 0x00010000, /* elf32/sparc */
|> + 0x4000000000000000, /* elf64/ia64 */
|> + 0x0000000120000000, /* elf64/alpha */
|> + 0x4000000000001000, /* elf64/hppa */
|> + 0x0000000100000000 /* elf64/sparc */
|> + };This is missing the address for elf32/m68k, which is 0x80000000. Note that you will get a warning on 32 bit systems for the 64 bit constants.
|> + prof[profcnt].pr_off = (size_t) taddr[i];
The cast is useless.
Andreas.
Signature · 5 lines
Andreas Schwab "And now for something SuSE Labs completely different." [email protected] SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andreas Schwab
Andreas> This is missing the address for elf32/m68k, which is Andreas> 0x80000000. Note that you will get a warning on 32 bit Andreas> systems for the 64 bit constants.
There is no harm in that. The list is not meant to be complete, nor does it have to be.
--david