fxos: show memory usage after project load

This commit is contained in:
Lephenixnoir 2024-01-11 19:47:06 +01:00
parent 64a3df8e17
commit 7a656c3b3e
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,25 @@
//---------------------------------------------------------------------------//
// 1100101 |_ mov #0, r4 __ //
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
// |_ base# + offset |_| /_\_\___/__/ //
//---------------------------------------------------------------------------//
// fxos/util/system: System-specific functions
#ifndef FXOS_UTIL_SYSTEM_H
#define FXOS_UTIL_SYSTEM_H
#include <unistd.h>
static inline long systemGetCurrentRSS()
{
FILE *fp = fopen("/proc/self/statm", "r");
if(!fp)
return 0;
long rss = 0;
int rc = fscanf(fp, "%*s %ld", &rss);
fclose(fp);
return (rc == 1) ? rss * sysconf(_SC_PAGESIZE) : 0;
}
#endif /* FXOS_UTIL_SYSTEM_H */

View File

@ -327,6 +327,7 @@ bool Function::exploreFunctionAt(u32 functionAddress)
/* Sort blocks now before creating CFG nodes, which are index-based */
sortBasicBlocks();
m_blocks.shrink_to_fit();
/* Set block predecessors */
for(auto &[pc, succ]: successorAddresses) {

View File

@ -1,6 +1,7 @@
#include <fxos/project.h>
#include <fxos/util/log.h>
#include <fxos/util/Timer.h>
#include <fxos/util/system.h>
#include <filesystem>
#include <algorithm>
#include <string>
@ -197,7 +198,8 @@ bool Project::load(std::string const &path0, bool verbose)
t.stop();
if(verbose)
printf("Loaded %s in %s\n", m_name.c_str(), t.format_time().c_str());
printf("Loaded %s in %s (%ld MB used)\n", m_name.c_str(),
t.format_time().c_str(), systemGetCurrentRSS() / 1000000);
return true;
}