gmon-start.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Code to enable profiling at program startup.
  2. Copyright (C) 1995,1996,1997,2000,2001,2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <features.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <sys/gmon.h>
  21. #ifdef __UCLIBC_PROFILING__
  22. /* Beginning and end of our code segment. We cannot declare them
  23. as the external functions since we want the addresses of those
  24. labels. Taking the address of a function may have different
  25. meanings on different platforms. */
  26. extern void _start;
  27. extern void etext;
  28. void __gmon_start__ (void)
  29. {
  30. #ifdef __UCLIBC_CTOR_DTOR__
  31. /* Protect from being called more than once. Since crti.o is linked
  32. into every shared library, each of their init functions will call us. */
  33. static int called;
  34. if (called)
  35. return;
  36. called = 1;
  37. #endif
  38. /* Start keeping profiling records. */
  39. monstartup ((u_long) &_start, (u_long) &etext);
  40. /* Call _mcleanup before exiting; it will write out gmon.out from the
  41. collected data. */
  42. atexit (&_mcleanup);
  43. }
  44. #endif