Skip to content

Commit

Permalink
fix:caculate memory (#2899)
Browse files Browse the repository at this point in the history
Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin committed Sep 24, 2024
1 parent a15aac9 commit 6127c59
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,12 +1403,8 @@ void InfoCmd::InfoData(std::string& info) {
uint64_t total_background_errors = 0;
uint64_t total_memtable_usage = 0;
uint64_t total_table_reader_usage = 0;
uint64_t total_redis_cache_usage = 0;
uint64_t total_block_cache_usage = 0;
uint64_t memtable_usage = 0;
uint64_t table_reader_usage = 0;
uint64_t redis_cache_usage = 0;
uint64_t block_cache_usage = 0;
std::shared_lock db_rwl(g_pika_server->dbs_rw_);
for (const auto& db_item : g_pika_server->dbs_) {
if (!db_item.second) {
Expand All @@ -1419,14 +1415,10 @@ void InfoCmd::InfoData(std::string& info) {
db_item.second->DBLockShared();
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_CUR_SIZE_ALL_MEM_TABLES, &memtable_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_ESTIMATE_TABLE_READER_MEM, &table_reader_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BlOCK_CACHE_USAGE, &block_cache_usage);
db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors);
redis_cache_usage = db_item.second->GetCacheInfo().used_memory;
db_item.second->DBUnlockShared();
total_memtable_usage += memtable_usage;
total_table_reader_usage += table_reader_usage;
total_block_cache_usage += block_cache_usage;
total_redis_cache_usage += redis_cache_usage;
for (const auto& item : background_errors) {
if (item.second != 0) {
db_fatal_msg_stream << (total_background_errors != 0 ? "," : "");
Expand All @@ -1436,12 +1428,11 @@ void InfoCmd::InfoData(std::string& info) {
}
}

tmp_stream << "used_memory:" << (total_memtable_usage + total_table_reader_usage + total_redis_cache_usage + total_block_cache_usage) << "\r\n";
tmp_stream << "used_memory_human:" << ((total_memtable_usage + total_table_reader_usage + total_redis_cache_usage + total_block_cache_usage) >> 20) << "M\r\n";
tmp_stream << "used_memory:" << (total_memtable_usage + total_table_reader_usage) << "\r\n";
tmp_stream << "used_memory_human:" << ((total_memtable_usage + total_table_reader_usage) >> 20) << "M\r\n";

tmp_stream << "db_memtable_usage:" << total_memtable_usage << "\r\n";
tmp_stream << "db_tablereader_usage:" << total_table_reader_usage << "\r\n";
tmp_stream << "db_block_cache_usage:" << total_block_cache_usage << "\r\n";
tmp_stream << "db_redis_cache_usage:" << total_redis_cache_usage << "\r\n";
tmp_stream << "db_fatal:" << (total_background_errors != 0 ? "1" : "0") << "\r\n";
tmp_stream << "db_fatal_msg:" << (total_background_errors != 0 ? db_fatal_msg_stream.str() : "nullptr") << "\r\n";

Expand Down

0 comments on commit 6127c59

Please sign in to comment.