]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/clock.c
Update from Cygnus libiberty.
[thirdparty/gcc.git] / libiberty / clock.c
CommitLineData
6599da04
JM
1/* ANSI-compatible clock function.
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
3
4This file is part of the libiberty library. This library is free
5software; you can redistribute it and/or modify it under the
6terms of the GNU General Public License as published by the
7Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GNU CC; see the file COPYING. If not, write to
17the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19As a special exception, if you link this library with files
20compiled with a GNU compiler to produce an executable, this does not cause
21the resulting executable to be covered by the GNU General Public License.
22This exception does not however invalidate any other reasons why
23the 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
41long
42clock ()
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