Changeset fba1d9c in git
- Timestamp:
- Sep 13, 2010, 10:11:12 AM (13 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 5e9e9c1562faf9f0fa575cfb990e24bbcd147a43
- Parents:
- 0c21f8c3eae19427d116ea966f29a8d6bffff26a
- Location:
- kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/timer.cc
r0c21f8 rfba1d9c 7 7 * ABSTRACT - get the computing time 8 8 */ 9 #include <sys/resource.h> 10 #include <unistd.h> 9 11 10 12 #include <kernel/mod2.h> 11 // undef GETRUSAGE to get the original timer code (w.r.t. CLOCK_TICKS)12 #define GETRUSAGE13 #ifdef GETRUSAGE14 #include <sys/time.h>15 #include <sys/resource.h>16 #include <unistd.h>17 #endif18 13 19 14 int timerv = 0; … … 33 28 34 29 #include <stdio.h> 35 #include <math.h>36 #include <unistd.h>37 #include <float.h>38 #include <mylimits.h>39 #include <sys/types.h>40 30 41 31 #ifdef TIME_WITH_SYS_TIME … … 57 47 58 48 59 // need to be adjusted on your machine: the number of ticks per second: HZ60 #ifndef HZ61 #include <sys/param.h>62 #endif63 64 #if !defined(HZ) && defined(CLOCKS_PER_SEC)65 #define HZ CLOCKS_PER_SEC66 #endif67 68 #if !defined(HZ) && defined(CLK_TCK)69 #define HZ CLK_TCK70 #endif71 72 #if !defined(HZ) && defined(HAVE_SYSCONF)73 #define HZ sysconf(_SC_CLK_TCK)74 #endif75 76 #ifndef HZ77 // last resort78 #ifdef sun79 #define HZ 60.080 #else81 #define HZ 100.082 #endif83 #endif84 85 49 #include <kernel/timer.h> 86 50 #include <kernel/febase.h> 51 87 52 /*3 88 53 * the start time of the timer 89 54 */ 90 #ifdef GETRUSAGE91 55 static int64 siStartTime; 92 56 static int64 startl; 93 #else94 static clock_t siStartTime;95 static clock_t startl;96 #endif97 57 98 58 /*3 99 59 * temp structure to get the time 100 60 */ 101 #ifdef GETRUSAGE102 61 static struct rusage t_rec; 103 #else104 static struct tms t_rec;105 #endif106 62 /*0 implementation*/ 107 63 108 64 int initTimer() 109 65 { 110 #ifdef GETRUSAGE 111 getrusage(RUSAGE_SELF,&t_rec); 66 getrusage(RUSAGE_SELF,&t_rec); 112 67 siStartTime = (t_rec.ru_utime.tv_sec*1000000+t_rec.ru_utime.tv_usec 113 68 +t_rec.ru_stime.tv_sec*1000000+t_rec.ru_stime.tv_usec 114 69 +5000)/10000; // unit is 1/100 sec 115 getrusage(RUSAGE_CHILDREN,&t_rec); 70 getrusage(RUSAGE_CHILDREN,&t_rec); 116 71 siStartTime += (t_rec.ru_utime.tv_sec*1000000+t_rec.ru_utime.tv_usec 117 72 +t_rec.ru_stime.tv_sec*1000000+t_rec.ru_stime.tv_usec 118 73 +5000)/10000; // unit is 1/100 sec 119 #else120 times(&t_rec);121 siStartTime = t_rec.tms_utime+t_rec.tms_stime;122 #endif123 74 return (int)time(NULL); 124 75 } … … 126 77 void startTimer() 127 78 { 128 #ifdef GETRUSAGE 129 getrusage(RUSAGE_SELF,&t_rec); 79 getrusage(RUSAGE_SELF,&t_rec); 130 80 startl = ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 131 81 +(int64)t_rec.ru_stime.tv_sec*1000000+t_rec.ru_stime.tv_usec 132 82 +(int64)5000)/(int64)10000; // unit is 1/100 sec 133 getrusage(RUSAGE_CHILDREN,&t_rec); 83 getrusage(RUSAGE_CHILDREN,&t_rec); 134 84 startl += ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 135 85 +(int64)t_rec.ru_stime.tv_sec*1000000+t_rec.ru_stime.tv_usec 136 86 +(int64)5000)/(int64)10000; // unit is 1/100 sec 137 #else138 times(&t_rec);139 startl = t_rec.tms_utime+t_rec.tms_stime;140 #endif141 87 } 142 88 … … 146 92 int getTimer() 147 93 { 148 #ifdef GETRUSAGE149 94 int64 curr; 150 getrusage(RUSAGE_SELF,&t_rec); 95 getrusage(RUSAGE_SELF,&t_rec); 151 96 curr = ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 152 97 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec 153 98 +(int64)5000)/(int64)10000; // unit is 1/100 sec 154 getrusage(RUSAGE_CHILDREN,&t_rec); 99 getrusage(RUSAGE_CHILDREN,&t_rec); 155 100 curr += ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 156 101 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec … … 158 103 curr -= siStartTime; 159 104 double f = ((double)curr) * timer_resolution / (double)100; 160 #else161 clock_t curr;162 163 times(&t_rec);164 curr = t_rec.tms_utime+t_rec.tms_stime - siStartTime;165 166 double f = ((double)curr) * timer_resolution / (double)HZ;167 #endif168 105 return (int)(f+0.5); 169 106 } … … 177 114 #endif 178 115 179 char* dateTime()180 {181 #ifdef GETRUSAGE182 time_t rawtime;183 time(&rawtime);184 char* s = ctime(&rawtime); // s: with linefeed at the end185 int l = strlen(s);186 char* ss = (char*)omAlloc(l);187 strncpy(ss, s, l - 1);188 ss[l - 1] = '\0'; // ss: without linefeed at the end189 return ss;190 #else191 char* s = "Warning: date/time not available on your system";192 int l = strlen(s) + 1;193 char* ss = (char*)omAlloc(l);194 strncpy(ss, s, l - 1);195 ss[l - 1] = '\0';196 return ss;197 #endif198 }199 200 116 void writeTime(const char* v) 201 117 { 202 203 #ifdef GETRUSAGE204 118 int64 curr; 205 getrusage(RUSAGE_SELF,&t_rec); 119 getrusage(RUSAGE_SELF,&t_rec); 206 120 curr = ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 207 121 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec 208 122 +(int64)5000)/(int64)10000; // unit is 1/100 sec 209 getrusage(RUSAGE_CHILDREN,&t_rec); 123 getrusage(RUSAGE_CHILDREN,&t_rec); 210 124 curr += ((int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec 211 125 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec … … 213 127 curr -= startl; 214 128 double f = ((double)curr) * timer_resolution / (double)100; 215 #else216 clock_t curr;217 times(&t_rec);218 curr = t_rec.tms_utime+t_rec.tms_stime - startl;219 220 double f = ((double)curr) / (double)HZ;221 #endif222 129 if (f/timer_resolution > mintime) 223 130 { -
kernel/timer.h
r0c21f8 rfba1d9c 12 12 void startTimer(void); 13 13 void writeTime(const char* s); 14 char* dateTime(); // (local) date and local time as a string15 14 16 15 int initTimer();
Note: See TracChangeset
for help on using the changeset viewer.