Loading cmds/statsd/src/guardrail/StatsdStats.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <android/util/ProtoOutputStream.h> #include "../stats_log_util.h" #include "statslog.h" #include "storage/StorageManager.h" namespace android { namespace os { Loading Loading @@ -403,6 +404,8 @@ void StatsdStats::dumpStats(FILE* out) const { fprintf(out, "alert %lld declared %d times\n", (long long)stats.first, stats.second); } } fprintf(out, "********Disk Usage stats***********\n"); StorageManager::printStats(out); fprintf(out, "********Pushed Atom stats***********\n"); const size_t atomCounts = mPushedAtomStats.size(); for (size_t i = 2; i < atomCounts; i++) { Loading cmds/statsd/src/storage/StorageManager.cpp +47 −0 Original line number Diff line number Diff line Loading @@ -345,6 +345,53 @@ void StorageManager::trimToFit(const char* path) { } } void StorageManager::printStats(FILE* out) { printDirStats(out, STATS_SERVICE_DIR); printDirStats(out, STATS_DATA_DIR); } void StorageManager::printDirStats(FILE* out, const char* path) { fprintf(out, "Printing stats of %s\n", path); unique_ptr<DIR, decltype(&closedir)> dir(opendir(path), closedir); if (dir == NULL) { VLOG("Path %s does not exist", path); return; } dirent* de; int fileCount = 0; int totalFileSize = 0; while ((de = readdir(dir.get()))) { char* name = de->d_name; if (name[0] == '.') { continue; } int64_t result[3]; parseFileName(name, result); if (result[0] == -1) continue; int64_t timestamp = result[0]; int64_t uid = result[1]; int64_t configID = result[2]; fprintf(out, "\t #%d, Last updated: %lld, UID: %d, Config ID: %lld", fileCount + 1, (long long)timestamp, (int)uid, (long long)configID); string file_name = getFilePath(path, timestamp, uid, configID); ifstream file(file_name.c_str(), ifstream::in | ifstream::binary); if (file.is_open()) { file.seekg(0, ios::end); int fileSize = file.tellg(); file.close(); fprintf(out, ", File Size: %d bytes", fileSize); totalFileSize += fileSize; } fprintf(out, "\n"); fileCount++; } fprintf(out, "\tTotal number of files: %d, Total size of files: %d bytes.\n", fileCount, totalFileSize); } } // namespace statsd } // namespace os } // namespace android cmds/statsd/src/storage/StorageManager.h +11 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,17 @@ public: */ static bool hasIdenticalConfig(const ConfigKey& key, const vector<uint8_t>& config); /** * Prints disk usage statistics related to statsd. */ static void printStats(FILE* out); private: /** * Prints disk usage statistics about a directory related to statsd. */ static void printDirStats(FILE* out, const char* path); }; } // namespace statsd Loading Loading
cmds/statsd/src/guardrail/StatsdStats.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include <android/util/ProtoOutputStream.h> #include "../stats_log_util.h" #include "statslog.h" #include "storage/StorageManager.h" namespace android { namespace os { Loading Loading @@ -403,6 +404,8 @@ void StatsdStats::dumpStats(FILE* out) const { fprintf(out, "alert %lld declared %d times\n", (long long)stats.first, stats.second); } } fprintf(out, "********Disk Usage stats***********\n"); StorageManager::printStats(out); fprintf(out, "********Pushed Atom stats***********\n"); const size_t atomCounts = mPushedAtomStats.size(); for (size_t i = 2; i < atomCounts; i++) { Loading
cmds/statsd/src/storage/StorageManager.cpp +47 −0 Original line number Diff line number Diff line Loading @@ -345,6 +345,53 @@ void StorageManager::trimToFit(const char* path) { } } void StorageManager::printStats(FILE* out) { printDirStats(out, STATS_SERVICE_DIR); printDirStats(out, STATS_DATA_DIR); } void StorageManager::printDirStats(FILE* out, const char* path) { fprintf(out, "Printing stats of %s\n", path); unique_ptr<DIR, decltype(&closedir)> dir(opendir(path), closedir); if (dir == NULL) { VLOG("Path %s does not exist", path); return; } dirent* de; int fileCount = 0; int totalFileSize = 0; while ((de = readdir(dir.get()))) { char* name = de->d_name; if (name[0] == '.') { continue; } int64_t result[3]; parseFileName(name, result); if (result[0] == -1) continue; int64_t timestamp = result[0]; int64_t uid = result[1]; int64_t configID = result[2]; fprintf(out, "\t #%d, Last updated: %lld, UID: %d, Config ID: %lld", fileCount + 1, (long long)timestamp, (int)uid, (long long)configID); string file_name = getFilePath(path, timestamp, uid, configID); ifstream file(file_name.c_str(), ifstream::in | ifstream::binary); if (file.is_open()) { file.seekg(0, ios::end); int fileSize = file.tellg(); file.close(); fprintf(out, ", File Size: %d bytes", fileSize); totalFileSize += fileSize; } fprintf(out, "\n"); fileCount++; } fprintf(out, "\tTotal number of files: %d, Total size of files: %d bytes.\n", fileCount, totalFileSize); } } // namespace statsd } // namespace os } // namespace android
cmds/statsd/src/storage/StorageManager.h +11 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,17 @@ public: */ static bool hasIdenticalConfig(const ConfigKey& key, const vector<uint8_t>& config); /** * Prints disk usage statistics related to statsd. */ static void printStats(FILE* out); private: /** * Prints disk usage statistics about a directory related to statsd. */ static void printDirStats(FILE* out, const char* path); }; } // namespace statsd Loading