You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9 KiB

  1. dnl -*- Autoconf -*-
  2. dnl Copyright (C) 1993-2003 Free Software Foundation, Inc.
  3. dnl This file is free software, distributed under the terms of the GNU
  4. dnl General Public License. As a special exception to the GNU General
  5. dnl Public License, this file may be distributed as part of a program
  6. dnl that contains a configuration script generated by Autoconf, under
  7. dnl the same distribution terms as the rest of that program.
  8. dnl From Bruno Haible, Marcus Daniels, Sam Steingold, Peter Burwood, Sam Steingold.
  9. AC_PREREQ(2.57)
  10. AC_DEFUN([CL_RUSAGE],
  11. [AC_CHECK_HEADERS(sys/resource.h sys/times.h)dnl
  12. if test $ac_cv_header_sys_resource_h = yes; then
  13. dnl HAVE_SYS_RESOURCE_H defined
  14. CL_LINK_CHECK([getrusage], cl_cv_func_getrusage,
  15. [#include <sys/types.h> /* NetBSD 1.0 needs this */
  16. #include <sys/time.h>
  17. #include <sys/resource.h>],
  18. [struct rusage x; int y = RUSAGE_SELF; getrusage(y,&x); x.ru_utime.tv_sec;])dnl
  19. if test $cl_cv_func_getrusage = yes; then
  20. CL_PROTO([getrusage], [
  21. CL_PROTO_TRY([
  22. #include <stdlib.h>
  23. #ifdef HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #include <sys/types.h> /* NetBSD 1.0 needs this */
  27. #include <sys/time.h>
  28. #include <sys/resource.h>
  29. ],
  30. [int getrusage (int who, struct rusage * rusage);],
  31. [int getrusage();],
  32. [cl_cv_proto_getrusage_arg1="int"],
  33. [cl_cv_proto_getrusage_arg1="enum __rusage_who"])
  34. ], [extern int getrusage ($cl_cv_proto_getrusage_arg1, struct rusage *);])dnl
  35. AC_CACHE_CHECK(whether getrusage works, cl_cv_func_getrusage_works, [
  36. AC_TRY_RUN([
  37. #include <stdio.h>
  38. #include <sys/types.h> /* NetBSD 1.0 needs this */
  39. #include <sys/time.h>
  40. #include <time.h> /* for time(2) */
  41. #include <sys/resource.h>
  42. int main ()
  43. {
  44. struct rusage used, prev;
  45. time_t end = time(NULL)+2;
  46. int count = 0;
  47. if ((count = getrusage(RUSAGE_SELF, &prev))) {
  48. /* getrusage is defined but does not do anything. */
  49. /*fprintf(stderr,"getrusage failed: return=%d\n",count);*/
  50. return 1;
  51. }
  52. while (time(NULL) < end) {
  53. count++;
  54. getrusage(RUSAGE_SELF, &used);
  55. if ((used.ru_utime.tv_usec != prev.ru_utime.tv_usec)
  56. || (used.ru_utime.tv_sec != prev.ru_utime.tv_sec)
  57. || (used.ru_stime.tv_usec != prev.ru_stime.tv_usec)
  58. || (used.ru_stime.tv_sec != prev.ru_stime.tv_sec)) {
  59. /*fprintf(stderr,"success after %d runs\n",count);*/
  60. return 0;
  61. }
  62. }
  63. /* getrusage is defined but does not work. */
  64. /*fprintf(stderr,"failure after %d runs\n",count);*/
  65. return 1;
  66. }],
  67. cl_cv_func_getrusage_works=yes,
  68. cl_cv_func_getrusage_works=no,
  69. dnl When cross-compiling, don't assume anything.
  70. cl_cv_func_getrusage_works="guessing no")])
  71. fi
  72. if test "$cl_cv_func_getrusage_works" = yes; then
  73. AC_DEFINE(HAVE_GETRUSAGE,,[have <sys/time.h>, the getrusage() function, the struct rusage type, and <sys/resource.h> defines RUSAGE_SELF])
  74. AC_DEFINE_UNQUOTED(RUSAGE_WHO_T,$cl_cv_proto_getrusage_arg1,[type of `who' in getrusage() declaration])
  75. fi
  76. fi
  77. ])