mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Add performance information to --stats file.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "verilatedos.h"
|
||||
#include <cstdarg>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
@@ -186,3 +187,36 @@ void V3Os::unlinkRegexp(const string& dir, const string& regexp) {
|
||||
closedir(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
// METHODS (performance)
|
||||
|
||||
uint64_t V3Os::timeUsecs() {
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
return 0;
|
||||
#else
|
||||
timeval tv;
|
||||
if (gettimeofday(&tv, NULL) < 0) return 0;
|
||||
return static_cast<uint64_t>(tv.tv_sec)*1000000 + tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t V3Os::memUsageBytes() {
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
return 0;
|
||||
#else
|
||||
// Highly unportable. Sorry
|
||||
const char* statmFilename = "/proc/self/statm";
|
||||
FILE* fp = fopen(statmFilename,"r");
|
||||
if (!fp) {
|
||||
return 0;
|
||||
}
|
||||
uint64_t size, resident, share, text, lib, data, dt; // All in pages
|
||||
if (7 != fscanf(fp, "%" VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d %"
|
||||
VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d %" VL_PRI64 "d",
|
||||
&size, &resident, &share, &text, &lib, &data, &dt)) {
|
||||
return 0;
|
||||
}
|
||||
return (text + data) * getpagesize();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user