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

@ -22,6 +22,7 @@
#if TD_HAVE_ABSL
#include <absl/container/flat_hash_map.h>
#include <absl/container/node_hash_map.h>
#else
#include <unordered_map>
#endif
@ -31,9 +32,13 @@ namespace td {
#if TD_HAVE_ABSL
template <class Key, class Value, class H = Hash<Key>>
using HashMap = absl::flat_hash_map<Key, Value, H>;
template <class Key, class Value, class H = Hash<Key>, class E = std::equal_to<>>
using NodeHashMap = absl::node_hash_map<Key, Value, H, E>;
#else
template <class Key, class Value, class H = Hash<Key>>
using HashMap = std::unordered_map<Key, Value, H>;
template <class Key, class Value, class H = Hash<Key>>
using NodeHashMap = std::unordered_map<Key, Value, H>;
#endif
} // namespace td

View file

@ -22,6 +22,7 @@
#if TD_HAVE_ABSL
#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_set.h>
#else
#include <unordered_set>
#endif
@ -29,11 +30,15 @@
namespace td {
#if TD_HAVE_ABSL
template <class Key, class H = Hash<Key>>
using HashSet = absl::flat_hash_set<Key, H>;
template <class Key, class H = Hash<Key>, class E = std::equal_to<>>
using HashSet = absl::flat_hash_set<Key, H, E>;
template <class Key, class H = Hash<Key>, class E = std::equal_to<>>
using NodeHashSet = absl::node_hash_set<Key, H, E>;
#else
template <class Key, class H = Hash<Key>>
using HashSet = std::unordered_set<Key, H>;
template <class Key, class H = Hash<Key>, class E = std::equal_to<>>
using HashSet = std::unordered_set<Key, H, E>;
template <class Key, class H = Hash<Key>, class E = std::equal_to<>>
using NodeHashSet = HashSet<Key, H, E>;
#endif
} // namespace td

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;

View file

@ -64,6 +64,10 @@ Status update_atime(CSlice path) TD_WARN_UNUSED_RESULT;
#endif
Result<uint64> get_total_ram() TD_WARN_UNUSED_RESULT;
struct TotalMemStat {
uint64 total_ram;
uint64 available_ram;
};
Result<TotalMemStat> get_total_mem_stat() TD_WARN_UNUSED_RESULT;
} // namespace td