Add printing summary reports (#4909) (#5018)

This commit is contained in:
Wilson Snyder
2024-03-25 07:03:17 -04:00
committed by GitHub
parent 34e4cffb62
commit 4df9e2e0e5
25 changed files with 585 additions and 32 deletions
+4 -26
View File
@@ -61,7 +61,6 @@ VL_DEFINE_DEBUG_FUNCTIONS;
# include <chrono>
# include <direct.h> // mkdir
# include <io.h> // open, read, write, close
# include <psapi.h> // GetProcessMemoryInfo
# include <thread>
// These macros taken from gdbsupport/gdb_wait.h in binutils-gdb
# ifndef WIFEXITED
@@ -80,6 +79,9 @@ VL_DEFINE_DEBUG_FUNCTIONS;
#endif
// clang-format on
#define VL_ALLOW_VERILATEDOS_C
#include "verilatedos_c.h"
//######################################################################
// Environment
@@ -397,7 +399,7 @@ uint64_t V3Os::timeUsecs() {
FILETIME ft; // contains number of 0.1us intervals since the beginning of 1601 UTC.
GetSystemTimeAsFileTime(&ft);
uint64_t us
const uint64_t us
= ((static_cast<uint64_t>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime + 5ULL) / 10ULL;
return us - EPOCH_DIFFERENCE_USECS;
#else
@@ -408,30 +410,6 @@ uint64_t V3Os::timeUsecs() {
#endif
}
uint64_t V3Os::memUsageBytes() {
#if defined(_WIN32) || defined(__MINGW32__)
const HANDLE process = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(process, &pmc, sizeof(pmc))) {
// The best we can do using simple Windows APIs is to get the size of the working set.
return pmc.WorkingSetSize;
}
return 0;
#else
// Highly unportable. Sorry
const char* const statmFilename = "/proc/self/statm";
FILE* const fp = fopen(statmFilename, "r");
if (!fp) return 0;
uint64_t size, resident, share, text, lib, data, dt; // All in pages
const int items = fscanf(
fp, "%" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64,
&size, &resident, &share, &text, &lib, &data, &dt);
fclose(fp);
if (VL_UNCOVERABLE(7 != items)) return 0;
return (text + data) * getpagesize();
#endif
}
void V3Os::u_sleep(int64_t usec) {
#if defined(_WIN32) || defined(__MINGW32__)
std::this_thread::sleep_for(std::chrono::microseconds(usec));