]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/getruntime.c
vect-80.c: Add xfail for no_align targets.
[thirdparty/gcc.git] / libiberty / getruntime.c
CommitLineData
6599da04 1/* Return time used so far, in microseconds.
deae2ed9 2 Copyright (C) 1994, 1999, 2002 Free Software Foundation, Inc.
6599da04
JM
3
4This file is part of the libiberty library.
5Libiberty is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public
7License as published by the Free Software Foundation; either
8version 2 of the License, or (at your option) any later version.
9
10Libiberty 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 GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with libiberty; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18Boston, MA 02111-1307, USA. */
19
3affd5f0
JL
20#include "config.h"
21
6599da04
JM
22#include "ansidecl.h"
23#include "libiberty.h"
24
deae2ed9
MM
25/* On some systems (such as WindISS), you must include <sys/types.h>
26 to get the definition of "time_t" before you include <time.h>. */
27#include <sys/types.h>
28
6599da04
JM
29/* There are several ways to get elapsed execution time; unfortunately no
30 single way is available for all host systems, nor are there reliable
31 ways to find out which way is correct for a given host. */
32
c6451ce1
MS
33#ifdef TIME_WITH_SYS_TIME
34# include <sys/time.h>
35# include <time.h>
36#else
37# if HAVE_SYS_TIME_H
38# include <sys/time.h>
39# else
40# ifdef HAVE_TIME_H
41# include <time.h>
42# endif
43# endif
44#endif
6599da04 45
6a071f4a 46#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
6599da04
JM
47#include <sys/resource.h>
48#endif
49
50#ifdef HAVE_TIMES
3affd5f0 51#ifdef HAVE_SYS_PARAM_H
6599da04
JM
52#include <sys/param.h>
53#endif
54#include <sys/times.h>
55#endif
56
2c45d1a0
RH
57#ifdef HAVE_UNISTD_H
58#include <unistd.h>
59#endif
60
6599da04
JM
61/* This is a fallback; if wrong, it will likely make obviously wrong
62 results. */
63
64#ifndef CLOCKS_PER_SEC
65#define CLOCKS_PER_SEC 1
66#endif
67
2c45d1a0
RH
68#ifdef _SC_CLK_TCK
69#define GNU_HZ sysconf(_SC_CLK_TCK)
70#else
71#ifdef HZ
72#define GNU_HZ HZ
73#else
74#ifdef CLOCKS_PER_SEC
75#define GNU_HZ CLOCKS_PER_SEC
76#endif
77#endif
b207e09c
MK
78#endif
79
aac04c15
DD
80/*
81
5bed56d9 82@deftypefn Replacement long get_run_time (void)
aac04c15
DD
83
84Returns the time used so far, in microseconds. If possible, this is
85the time used by this process, else it is the elapsed time since the
86process started.
87
88@end deftypefn
89
90*/
91
6599da04
JM
92long
93get_run_time ()
94{
6a071f4a 95#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
6599da04
JM
96 struct rusage rusage;
97
98 getrusage (0, &rusage);
99 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
100 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
101#else /* ! HAVE_GETRUSAGE */
102#ifdef HAVE_TIMES
103 struct tms tms;
104
105 times (&tms);
2c45d1a0 106 return (tms.tms_utime + tms.tms_stime) * (1000000 / GNU_HZ);
6599da04
JM
107#else /* ! HAVE_TIMES */
108 /* Fall back on clock and hope it's correctly implemented. */
109 const long clocks_per_sec = CLOCKS_PER_SEC;
110 if (clocks_per_sec <= 1000000)
111 return clock () * (1000000 / clocks_per_sec);
112 else
113 return clock () / clocks_per_sec;
114#endif /* HAVE_TIMES */
115#endif /* HAVE_GETRUSAGE */
116}