aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiesh1oo <siesh1oo@siesh1oo.no>2014-03-10 14:36:07 +0100
committerSiesh1oo <siesh1oo@siesh1oo.no>2014-03-10 14:36:07 +0100
commit8111938e962b60294e51d5f0d10b6d1855bc1b91 (patch)
treed1696423105b392520e8f77327ae4410222a1354
parent40e0b79495195eaa2bc6bf32e8d52a5aa956a2b4 (diff)
downloadyosys-8111938e962b60294e51d5f0d10b6d1855bc1b91.tar.gz
yosys-8111938e962b60294e51d5f0d10b6d1855bc1b91.tar.bz2
yosys-8111938e962b60294e51d5f0d10b6d1855bc1b91.zip
- kernel/log.h: add rusage()-based fallback for systems without clock_gettime().
-rw-r--r--kernel/log.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/kernel/log.h b/kernel/log.h
index c4c03352a..fbc3c1c39 100644
--- a/kernel/log.h
+++ b/kernel/log.h
@@ -23,6 +23,8 @@
#include "kernel/rtlil.h"
#include <stdio.h>
#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <vector>
extern std::vector<FILE*> log_files;
@@ -65,9 +67,23 @@ struct PerformanceTimer
}
static int64_t query() {
+#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
struct timespec ts;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
return int64_t(ts.tv_sec)*1000000000 + ts.tv_nsec;
+#elif defined(RUSAGE_SELF)
+ struct rusage rusage;
+ int64_t t;
+ if (getrusage(RUSAGE_SELF, &rusage) == -1) {
+ log_cmd_error("getrusage failed!\n");
+ log_abort();
+ }
+ t = 1000000000ULL * (int64_t) rusage.ru_utime.tv_sec + (int64_t) rusage.ru_utime.tv_usec * 1000ULL;
+ t += 1000000000ULL * (int64_t) rusage.ru_stime.tv_sec + (int64_t) rusage.ru_stime.tv_usec * 1000ULL;
+ return t;
+#else
+ #error Dont know how to measure per-process CPU time. Need alternative method (times()/clocks()/gettimeofday()?).
+#endif
}
void reset() {