1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

celldb in-memory mode (--celldb-in-memory option)

This commit is contained in:
birydrad 2024-09-09 18:08:15 +02:00
parent 420029b056
commit 1723562748
48 changed files with 1966 additions and 201 deletions

View file

@ -58,8 +58,7 @@
#define PSAPI_VERSION 1
#endif
#include <psapi.h>
#pragma comment( lib, "psapi.lib" )
#pragma comment(lib, "psapi.lib")
#endif
@ -413,7 +412,7 @@ Result<CpuStat> cpu_stat() {
#endif
}
Result<uint64> get_total_ram() {
Result<TotalMemStat> get_total_mem_stat() {
#if TD_LINUX
TRY_RESULT(fd, FileFd::open("/proc/meminfo", FileFd::Read));
SCOPE_EXIT {
@ -425,8 +424,10 @@ Result<uint64> get_total_ram() {
if (size >= TMEM_SIZE - 1) {
return Status::Error("Failed for read /proc/meminfo");
}
TotalMemStat stat;
mem[size] = 0;
const char* s = mem;
const char *s = mem;
size_t got = 0;
while (*s) {
const char *name_begin = s;
while (*s != 0 && *s != '\n') {
@ -437,18 +438,28 @@ Result<uint64> get_total_ram() {
name_end++;
}
Slice name(name_begin, name_end);
td::uint64 *dest = nullptr;
if (name == "MemTotal") {
dest = &stat.total_ram;
} else if (name == "MemAvailable") {
dest = &stat.available_ram;
}
if (dest != nullptr) {
Slice value(name_end, s);
if (!value.empty() && value[0] == ':') {
value.remove_prefix(1);
}
value = trim(value);
value = split(value).first;
TRY_RESULT_PREFIX(mem, to_integer_safe<uint64>(value), "Invalid value of MemTotal");
TRY_RESULT_PREFIX(mem, to_integer_safe<uint64>(value), PSLICE() << "Invalid value of " << name);
if (mem >= 1ULL << (64 - 10)) {
return Status::Error("Invalid value of MemTotal");
}
return mem * 1024;
*dest = mem * 1024;
got++;
if (got == 2) {
return stat;
}
}
if (*s == 0) {
break;