diff options
author | Clifford Wolf <clifford@clifford.at> | 2014-12-27 11:25:51 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2014-12-27 11:25:51 +0100 |
commit | 2c2f8e6e9f4eadbb191df8a8dbeee95443fc9f08 (patch) | |
tree | 65105a9e3d29826d297c7aa4a39383d909212349 /kernel/driver.cc | |
parent | d6ee6f653fa795efcea910fd4ad4bc6ee09a4784 (diff) | |
download | yosys-2c2f8e6e9f4eadbb191df8a8dbeee95443fc9f08.tar.gz yosys-2c2f8e6e9f4eadbb191df8a8dbeee95443fc9f08.tar.bz2 yosys-2c2f8e6e9f4eadbb191df8a8dbeee95443fc9f08.zip |
Added memory statistics (at least on linux)
Diffstat (limited to 'kernel/driver.cc')
-rw-r--r-- | kernel/driver.cc | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc index 90f479307..4700bf61b 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -30,6 +30,11 @@ #include <limits.h> #include <errno.h> +#ifdef __linux__ +# include <sys/types.h> +# include <unistd.h> +#endif + #if !defined(_WIN32) || defined(__MINGW32__) # include <unistd.h> #else @@ -320,11 +325,26 @@ int main(int argc, char **argv) #ifdef _WIN32 log("End of script. Logfile hash: %s\n", hash.c_str()); #else + std::string meminfo; + std::string stats_divider = ", "; +# ifdef __linux__ + std::ifstream statm; + statm.open(stringf("/proc/%lld/statm", (long long)getpid())); + if (statm.is_open()) { + int sz_total, sz_resident; + statm >> sz_total >> sz_resident; + meminfo = stringf(", MEM: %.2f MB total, %.2f MB resident", + sz_total * (getpagesize() / 1024.0 / 1024.0), + sz_resident * (getpagesize() / 1024.0 / 1024.0)); + stats_divider = "\n"; + } +# endif + struct rusage ru_buffer; getrusage(RUSAGE_SELF, &ru_buffer); - log("End of script. Logfile hash: %s, CPU: user %.2fs system %.2fs\n", hash.c_str(), - ru_buffer.ru_utime.tv_sec + 1e-6 * ru_buffer.ru_utime.tv_usec, - ru_buffer.ru_stime.tv_sec + 1e-6 * ru_buffer.ru_stime.tv_usec); + log("End of script. Logfile hash: %s%sCPU: user %.2fs system %.2fs%s\n", hash.c_str(), + stats_divider.c_str(), ru_buffer.ru_utime.tv_sec + 1e-6 * ru_buffer.ru_utime.tv_usec, + ru_buffer.ru_stime.tv_sec + 1e-6 * ru_buffer.ru_stime.tv_usec, meminfo.c_str()); #endif log("%s\n", yosys_version_str); |