00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #include "ansidecl.h"
00023 #include "libiberty.h"
00024
00025
00026
00027 #include <sys/types.h>
00028
00029
00030
00031
00032
00033 #ifdef TIME_WITH_SYS_TIME
00034 # include <sys/time.h>
00035 # include <time.h>
00036 #else
00037 # if HAVE_SYS_TIME_H
00038 # include <sys/time.h>
00039 # else
00040 # ifdef HAVE_TIME_H
00041 # include <time.h>
00042 # endif
00043 # endif
00044 #endif
00045
00046 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
00047 #include <sys/resource.h>
00048 #endif
00049
00050 #ifdef HAVE_TIMES
00051 #ifdef HAVE_SYS_PARAM_H
00052 #include <sys/param.h>
00053 #endif
00054 #include <sys/times.h>
00055 #endif
00056
00057 #ifdef HAVE_UNISTD_H
00058 #include <unistd.h>
00059 #endif
00060
00061
00062
00063
00064 #ifndef CLOCKS_PER_SEC
00065 #define CLOCKS_PER_SEC 1
00066 #endif
00067
00068 #ifdef _SC_CLK_TCK
00069 #define GNU_HZ sysconf(_SC_CLK_TCK)
00070 #else
00071 #ifdef HZ
00072 #define GNU_HZ HZ
00073 #else
00074 #ifdef CLOCKS_PER_SEC
00075 #define GNU_HZ CLOCKS_PER_SEC
00076 #endif
00077 #endif
00078 #endif
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 long
00093 get_run_time ()
00094 {
00095 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
00096 struct rusage rusage;
00097
00098 getrusage (0, &rusage);
00099 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
00100 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
00101 #else
00102 #ifdef HAVE_TIMES
00103 struct tms tms;
00104
00105 times (&tms);
00106 return (tms.tms_utime + tms.tms_stime) * (1000000 / GNU_HZ);
00107 #else
00108
00109 const long clocks_per_sec = CLOCKS_PER_SEC;
00110 if (clocks_per_sec <= 1000000)
00111 return clock () * (1000000 / clocks_per_sec);
00112 else
00113 return clock () / clocks_per_sec;
00114 #endif
00115 #endif
00116 }