]> www.ginac.de Git - cln.git/blob - m4/rusage.m4
Finalize CLN 1.3.7 release.
[cln.git] / m4 / rusage.m4
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
9 dnl From Bruno Haible, Marcus Daniels, Sam Steingold, Peter Burwood, Sam Steingold.
10
11 AC_PREREQ([2.57])
12
13 AC_DEFUN([CL_RUSAGE],
14 [AC_CHECK_HEADERS(sys/resource.h sys/times.h)dnl
15 if test $ac_cv_header_sys_resource_h = yes; then
16   dnl HAVE_SYS_RESOURCE_H defined
17   CL_LINK_CHECK([getrusage], cl_cv_func_getrusage,
18 [#include <sys/types.h> /* NetBSD 1.0 needs this */
19 #include <sys/time.h>
20 #include <sys/resource.h>],
21     [struct rusage x; int y = RUSAGE_SELF; getrusage(y,&x); x.ru_utime.tv_sec;])dnl
22   if test $cl_cv_func_getrusage = yes; then
23     CL_PROTO([getrusage], [
24     CL_PROTO_TRY([
25 #include <stdlib.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 #include <sys/types.h> /* NetBSD 1.0 needs this */
30 #include <sys/time.h>
31 #include <sys/resource.h>
32 ],
33 [int getrusage (int who, struct rusage * rusage);],
34 [cl_cv_proto_getrusage_arg1="int"],
35 [cl_cv_proto_getrusage_arg1="enum __rusage_who"])
36 ], [extern int getrusage ($cl_cv_proto_getrusage_arg1, struct rusage *);])dnl
37     AC_CACHE_CHECK(whether getrusage works, cl_cv_func_getrusage_works, [
38     AC_RUN_IFELSE([AC_LANG_SOURCE([[
39 #include <stdio.h>
40 #include <sys/types.h> /* NetBSD 1.0 needs this */
41 #include <sys/time.h>
42 #include <time.h> /* for time(2) */
43 #include <sys/resource.h>
44 int main ()
45 {
46   struct rusage used, prev;
47   time_t end = time(NULL)+2;
48   int count = 0;
49
50   if ((count = getrusage(RUSAGE_SELF, &prev))) {
51     /* getrusage is defined but does not do anything. */
52     /*fprintf(stderr,"getrusage failed: return=%d\n",count);*/
53     return 1;
54   }
55   while (time(NULL) < end) {
56     count++;
57     getrusage(RUSAGE_SELF, &used);
58     if ((used.ru_utime.tv_usec != prev.ru_utime.tv_usec)
59         || (used.ru_utime.tv_sec != prev.ru_utime.tv_sec)
60         || (used.ru_stime.tv_usec != prev.ru_stime.tv_usec)
61         || (used.ru_stime.tv_sec != prev.ru_stime.tv_sec)) {
62       /*fprintf(stderr,"success after %d runs\n",count);*/
63       return 0;
64     }
65   }
66   /* getrusage is defined but does not work. */
67   /*fprintf(stderr,"failure after %d runs\n",count);*/
68   return 1;
69 }]])],
70 [cl_cv_func_getrusage_works=yes],
71 [cl_cv_func_getrusage_works=no],
72 dnl When cross-compiling, don't assume anything.
73 [cl_cv_func_getrusage_works="guessing no"])])
74   fi
75   if test "$cl_cv_func_getrusage_works" = yes; then
76     AC_DEFINE(HAVE_GETRUSAGE,,[have <sys/time.h>, the getrusage() function, the struct rusage type, and <sys/resource.h> defines RUSAGE_SELF])
77     AC_DEFINE_UNQUOTED(RUSAGE_WHO_T,$cl_cv_proto_getrusage_arg1,[type of `who' in getrusage() declaration])
78   fi
79 fi
80 ])