From e77bbc7ffc0171d2ea041f303d8e81bc4f84b9df Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 21 Apr 2019 19:22:58 +0300 Subject: [PATCH] Add separate field for log size in fast storage statistics. GitOrigin-RevId: 6e76c7ac995db6599a927d54e8d85aed95f020c0 --- td/generate/scheme/td_api.tl | 4 ++-- td/generate/scheme/td_api.tlo | Bin 151192 -> 151228 bytes td/telegram/StorageManager.cpp | 32 +++++++++++++++++++------------- td/telegram/StorageManager.h | 4 +++- td/telegram/files/FileStats.cpp | 2 +- td/telegram/files/FileStats.h | 6 ++++-- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 069255a9..21dff86e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2260,8 +2260,8 @@ storageStatisticsByChat chat_id:int53 size:int53 count:int32 by_file_type:vector //@description Contains the exact storage usage statistics split by chats and file type @size Total size of files @count Total number of files @by_chat Statistics split by chats storageStatistics size:int53 count:int32 by_chat:vector = StorageStatistics; -//@description Contains approximate storage usage statistics, excluding files of unknown file type @files_size Approximate total size of files @file_count Approximate number of files @database_size Size of the database -storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 = StorageStatisticsFast; +//@description Contains approximate storage usage statistics, excluding files of unknown file type @files_size Approximate total size of files @file_count Approximate number of files @database_size Size of the database @log_size Size of the TDLib interna log +storageStatisticsFast files_size:int53 file_count:int32 database_size:int53 log_size:int53 = StorageStatisticsFast; //@description Contains database statistics //@statistics Database statistics in an unspecified human-readable format diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 8414d58dc41db2528be9f3bbcdf6fd2c890551f9..e1458e7b33b38fe3d7228fa88ad5af286a20f897 100644 GIT binary patch delta 108 zcmbO+mvhft&J8okbMhQ-k_|0QNJ}lE01~C>-zVLvR wB_}^UetKa5qx9s01P-v$?Fzw+F>54XY8il_$eB%t!?x`pNNoF*|BNjD02ih%3;+NC delta 94 zcmdlpmvhEk&J8o pr } void StorageManager::get_storage_stats_fast(Promise promise) { - promise.set_value(FileStatsFast(fast_stat_.size, fast_stat_.cnt, get_db_size())); + promise.set_value(FileStatsFast(fast_stat_.size, fast_stat_.cnt, get_database_size(), get_log_size())); } void StorageManager::get_database_stats(Promise promise) { @@ -145,21 +145,27 @@ void StorageManager::on_all_files(Result r_file_stats, bool dummy) { })); } -int64 StorageManager::get_db_size() { +int64 StorageManager::get_file_size(CSlice path) { + auto r_info = stat(path); + if (r_info.is_error()) { + return 0; + } + + auto size = r_info.ok().size_; + LOG(DEBUG) << "Add file \"" << path << "\" of size " << size << " to fast storage statistics"; + return size; +} + +int64 StorageManager::get_database_size() { int64 size = 0; - auto add_path = [&](CSlice path) { - TRY_RESULT(info, stat(path)); + G()->td_db()->with_db_path([&size](CSlice path) { size += get_file_size(path); }); + return size; +} - LOG(DEBUG) << "Add database file \"" << path << "\" of size " << info.size_ - << " to database storage size statistics"; - size += info.size_; - - return Status::OK(); - }; - - G()->td_db()->with_db_path([&](CSlice path) { add_path(path).ignore(); }); +int64 StorageManager::get_log_size() { + int64 size = 0; for (auto &log_path : log_interface->get_file_paths()) { - add_path(log_path).ignore(); + size += get_file_size(log_path); } return size; } diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index c42f669a..67511249 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -62,7 +62,9 @@ class StorageManager : public Actor { void save_fast_stat(); void load_fast_stat(); - static int64 get_db_size(); + static int64 get_database_size(); + static int64 get_log_size(); + static int64 get_file_size(CSlice path); // RefCnt int32 ref_cnt_{1}; diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index 8fc5bb6a..7679521d 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -20,7 +20,7 @@ namespace td { tl_object_ptr FileStatsFast::as_td_api() const { - return make_tl_object(size, count, db_size); + return make_tl_object(size, count, database_size, log_size); } void FileStats::add(StatByType &by_type, FileType file_type, int64 size) { diff --git a/td/telegram/files/FileStats.h b/td/telegram/files/FileStats.h index 3e801bb0..2d3f7d53 100644 --- a/td/telegram/files/FileStats.h +++ b/td/telegram/files/FileStats.h @@ -55,8 +55,10 @@ struct FullFileInfo { struct FileStatsFast { int64 size{0}; int32 count{0}; - int64 db_size{0}; - FileStatsFast(int64 size, int32 count, int64 db_size) : size(size), count(count), db_size(db_size) { + int64 database_size{0}; + int64 log_size{0}; + FileStatsFast(int64 size, int32 count, int64 database_size, int64 log_size) + : size(size), count(count), database_size(database_size), log_size(log_size) { } tl_object_ptr as_td_api() const; };