1 /* ANSI-compatible clock function.
2 Copyright (C) 1994, 1995, 1999 Free Software Foundation, Inc.
4 This file is part of the libiberty library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU CC; see the file COPYING. If not, write to
17 the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
27 @deftypefn Supplemental long clock (void)
29 Returns an approximation of the CPU time used by the process as a
30 @code{clock_t}; divide this number by @samp{CLOCKS_PER_SEC} to get the
31 number of seconds used.
41 #include <sys/resource.h>
45 #ifdef HAVE_SYS_PARAM_H
46 #include <sys/param.h>
48 #include <sys/times.h>
56 #define GNU_HZ sysconf(_SC_CLK_TCK)
62 #define GNU_HZ CLOCKS_PER_SEC
67 /* FIXME: should be able to declare as clock_t. */
75 getrusage (0, &rusage
);
76 return (rusage
.ru_utime
.tv_sec
* 1000000 + rusage
.ru_utime
.tv_usec
77 + rusage
.ru_stime
.tv_sec
* 1000000 + rusage
.ru_stime
.tv_usec
);
83 return (tms
.tms_utime
+ tms
.tms_stime
) * (1000000 / GNU_HZ
);
91 int child_system_time
;
95 return (vms_times
.proc_user_time
+ vms_times
.proc_system_time
) * 10000;
97 /* A fallback, if nothing else available. */
100 #endif /* HAVE_TIMES */
101 #endif /* HAVE_GETRUSAGE */