]>
Commit | Line | Data |
---|---|---|
6599da04 JM |
1 | /* ANSI-compatible clock function. |
2 | Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
3 | ||
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) | |
8 | any later version. | |
9 | ||
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. | |
14 | ||
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
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. */ | |
24 | ||
3affd5f0 JL |
25 | #include "config.h" |
26 | ||
6599da04 JM |
27 | #ifdef HAVE_GETRUSAGE |
28 | #include <sys/time.h> | |
29 | #include <sys/resource.h> | |
30 | #endif | |
31 | ||
32 | #ifdef HAVE_TIMES | |
3affd5f0 | 33 | #ifdef HAVE_SYS_PARAM_H |
6599da04 JM |
34 | #include <sys/param.h> |
35 | #endif | |
36 | #include <sys/times.h> | |
37 | #endif | |
38 | ||
39 | /* FIXME: should be able to declare as clock_t. */ | |
40 | ||
41 | long | |
42 | clock () | |
43 | { | |
44 | #ifdef HAVE_GETRUSAGE | |
45 | struct rusage rusage; | |
46 | ||
47 | getrusage (0, &rusage); | |
48 | return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec | |
49 | + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec); | |
50 | #else | |
51 | #ifdef HAVE_TIMES | |
52 | struct tms tms; | |
53 | ||
54 | times (&tms); | |
55 | return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ); | |
56 | #else | |
57 | #ifdef VMS | |
58 | struct | |
59 | { | |
60 | int proc_user_time; | |
61 | int proc_system_time; | |
62 | int child_user_time; | |
63 | int child_system_time; | |
64 | } vms_times; | |
65 | ||
66 | times (&vms_times); | |
67 | return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000; | |
68 | #else | |
69 | /* A fallback, if nothing else available. */ | |
70 | return 0; | |
71 | #endif /* VMS */ | |
72 | #endif /* HAVE_TIMES */ | |
73 | #endif /* HAVE_GETRUSAGE */ | |
74 | } | |
75 |