#include <algorithm>
#include <chrono>
#include <cstdlib>
+#include <cstring>
#include <ctime>
-#include <deque>
+#include <deque>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
+#include <sys/statfs.h>
#include <sys/time.h>
#include <thread>
+#include <vector>
#define SYSTEM_LOG_FILE_PATH "/system/system_log.txt"
// while (logData.size() > 50) {
// logData.pop_front(); // 从前端删除最早的日志
// }
-
+
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Loaded %d logs from file",
logData.size());
// 获取日志记录,返回deque
const std::deque<SystemLogData> &SystemLogModel::getLogData() const {
- return logData;
+ return logData;
}
// 获取日志大小
size_t SystemLogModel::getLogSize() const { return logData.size(); }
+//获取系统内存
+/*
+[FS INFO]total size=12416KB used size=8114KB free size=4302KB
+[FS INFO]/update/:
+[FS INFO]total size=12416KB used size=552KB free size=11864KB
+[FS INFO]/music/:
+[FS INFO]total size=12416KB used size=1270KB free size=11146KB
+[FS INFO]/user/:
+[FS INFO]total size=91264KB used size=64596KB free size=26668KB
+*/
+std::string SystemLogModel::get_system_mem_info() {
+ struct statfs file_buf = {0};
+ std::stringstream result; // 使用 stringstream 来构建返回的字符串
+ const std::vector<std::string> volume_names = {"/system/", "/update/",
+ "/music/", "/user/"};
+
+ for (const auto &volume : volume_names) {
+ // 获取文件系统状态
+ if (statfs(volume.c_str(), &file_buf) != 0) {
+ result << "Error retrieving info for " << volume << std::endl;
+ continue;
+ }
+
+ // 计算总大小、已用大小和自由空间
+ uint64_t total_size =
+ static_cast<uint64_t>(file_buf.f_blocks) * file_buf.f_bsize;
+ uint64_t free_size =
+ static_cast<uint64_t>(file_buf.f_bfree) * file_buf.f_bsize;
+ uint64_t used_size = total_size - free_size;
+
+ // 按照所需格式输出
+ result << "[" << volume << "]" << std::endl;
+ result << "Total size=" << total_size / 1024 << "KB " << std::endl;
+ result << "Used size=" << used_size / 1024 << "KB " << std::endl;
+ result << "Free size=" << free_size / 1024 << "KB" << std::endl;
+ }
+
+ // 返回所有分区的自由空间信息,如果没有信息,则返回说明信息
+ return result.str().empty() ? "No volumes found or accessible."
+ : result.str();
+}
} // namespace OHOS
\ No newline at end of file
debugOutputItemInfo[index++] = {6, "shutdown_file_list"};
//睡眠数据
debugOutputItemInfo[index++] = {7, "sleep_time"};
+ //系统空闲内存
+ debugOutputItemInfo[index++] = {8, "system_free_memory"};
usedLen = index;
/* -------------------------------- Add data -------------------------------- */
for (uint8_t i = 0; i < usedLen; i++)
return oss.str();
}
+ //获取死机列表
static const char *SHUTDOWN_PATH = "/user/tar";
-
std::string DebugOutputViewEventListener::get_shutdown_info() {
std::ostringstream oss;
return result;
}
+ //获取系统free内存
+ std::string DebugOutputViewEventListener::get_free_memory()
+ {
+ auto logModel = SystemLogModel::GetInstance();
+ std::string result = logModel->get_system_mem_info();
+ return result;
+ }
+
bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
std::string viewId = view.GetViewId();
case 7:
str = get_sleep_time();
break;
+ case 8:
+ str = get_free_memory();
+ break;
default:
str = "--";
break;