]> www.ginac.de Git - cln.git/blob - m4/rusage.m4
Git-ify some documentation.
[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 [int getrusage();],
35 [cl_cv_proto_getrusage_arg1="int"],
36 [cl_cv_proto_getrusage_arg1="enum __rusage_who"])
37 ], [extern int getrusage ($cl_cv_proto_getrusage_arg1, struct rusage *);])dnl
38     AC_CACHE_CHECK(whether getrusage works, cl_cv_func_getrusage_works, [
39     AC_TRY_RUN([
40 #include <stdio.h>
41 #include <sys/types.h> /* NetBSD 1.0 needs this */
42 #include <sys/time.h>
43 #include <time.h> /* for time(2) */
44 #include <sys/resource.h>
45 int main ()
46 {
47   struct rusage used, prev;
48   time_t end = time(NULL)+2;
49   int count = 0;
50
51   if ((count = getrusage(RUSAGE_SELF, &prev))) {
52     /* getrusage is defined but does not do anything. */
53     /*fprintf(stderr,"getrusage failed: return=%d\n",count);*/
54     return 1;
55   }
56   while (time(NULL) < end) {
57     count++;
58     getrusage(RUSAGE_SELF, &used);
59     if ((used.ru_utime.tv_usec != prev.ru_utime.tv_usec)
60         || (used.ru_utime.tv_sec != prev.ru_utime.tv_sec)
61         || (used.ru_stime.tv_usec != prev.ru_stime.tv_usec)
62         || (used.ru_stime.tv_sec != prev.ru_stime.tv_sec)) {
63       /*fprintf(stderr,"success after %d runs\n",count);*/
64       return 0;
65     }
66   }
67   /* getrusage is defined but does not work. */
68   /*fprintf(stderr,"failure after %d runs\n",count);*/
69   return 1;
70 }],
71 cl_cv_func_getrusage_works=yes,
72 cl_cv_func_getrusage_works=no,
73 dnl When cross-compiling, don't assume anything.
74 cl_cv_func_getrusage_works="guessing no")])
75   fi
76   if test "$cl_cv_func_getrusage_works" = yes; then
77     AC_DEFINE(HAVE_GETRUSAGE,,[have <sys/time.h>, the getrusage() function, the struct rusage type, and <sys/resource.h> defines RUSAGE_SELF])
78     AC_DEFINE_UNQUOTED(RUSAGE_WHO_T,$cl_cv_proto_getrusage_arg1,[type of `who' in getrusage() declaration])
79   fi
80 fi
81 ])