* tcoff.h (USER_LABEL_PREFIX): Make it empty to match coff.h.
[official-gcc.git] / libf2c / libU77 / etime_.c
blob269d964c75b0fa71eeec7864e942bfcc6ed88803
1 /* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
2 This file is part of GNU Fortran libU77 library.
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 GNU Fortran is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with GNU Fortran; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 #if HAVE_UNISTD_H
23 # include <unistd.h>
24 #endif
25 #include <sys/types.h>
26 #if HAVE_SYS_TIMES_H
27 # include <sys/times.h>
28 #endif
29 #if HAVE_SYS_PARAM_H
30 # include <sys/param.h>
31 #endif
32 #if HAVE_GETRUSAGE
33 # include <sys/time.h>
34 # include <sys/resource.h>
35 #endif
36 #include <errno.h> /* for ENOSYS */
37 #include "f2c.h"
39 /* For dtime, etime we store the clock tick parameter (clk_tck) the
40 first time either of them is invoked rather than each time. This
41 approach probably speeds up each invocation by avoiding a system
42 call each time, but means that the overhead of the first call is
43 different to all others. */
44 static long clk_tck = 0;
46 #ifdef KR_headers
47 double G77_etime_0 (tarray)
48 real tarray[2];
49 #else
50 double G77_etime_0 (real tarray[2])
51 #endif
53 #if defined (HAVE_GETRUSAGE) || defined (HAVE_TIMES)
54 /* The getrusage version is only the default for convenience. */
55 #ifdef HAVE_GETRUSAGE
56 struct rusage rbuff;
58 if (getrusage (RUSAGE_SELF, &rbuff) != 0)
59 abort ();
60 tarray[0] = ((float) (rbuff.ru_utime).tv_sec +
61 (float) (rbuff.ru_utime).tv_usec/1000000.0);
62 tarray[1] = ((float) (rbuff.ru_stime).tv_sec +
63 (float) (rbuff.ru_stime).tv_usec/1000000.0);
64 #else /* HAVE_GETRUSAGE */
65 struct tms buffer;
67 /* NeXTStep seems to define _SC_CLK_TCK but not to have sysconf;
68 fixme: does using _POSIX_VERSION help? */
69 # if defined _SC_CLK_TCK && defined _POSIX_VERSION
70 if (! clk_tck) clk_tck = sysconf(_SC_CLK_TCK);
71 # elif defined CLOCKS_PER_SECOND
72 if (! clk_tck) clk_tck = CLOCKS_PER_SECOND;
73 # elif defined CLK_TCK
74 if (! clk_tck) clk_tck = CLK_TCK;
75 # elif defined HZ
76 if (! clk_tck) clk_tck = HZ;
77 # elif defined HAVE_GETRUSAGE
78 # else
79 #error Dont know clock tick length
80 # endif
81 if (times(&buffer) < 0) return -1.0;
82 tarray[0] = (float) buffer.tms_utime / (float)clk_tck;
83 tarray[1] = (float) buffer.tms_stime / (float)clk_tck;
84 #endif /* HAVE_GETRUSAGE */
85 return (tarray[0]+tarray[1]);
86 #else /* ! HAVE_GETRUSAGE && ! HAVE_TIMES */
87 errno = ENOSYS;
88 return 0.0;
89 #endif /* ! HAVE_GETRUSAGE && ! HAVE_TIMES */