From e4d6fd65173a971e3cf8ae8243deb19b0d47e5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 28 Aug 2025 11:47:36 +0800 Subject: [PATCH 01/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 14 ++ .../src/cloud_disk/io_message_listener.cpp | 152 +++++++++++++++++- .../cloudfiledaemon/src/ipc/cloud_daemon.cpp | 9 ++ 3 files changed, 173 insertions(+), 2 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 655fe644a..534258b87 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -51,6 +51,7 @@ class IoMessageManager { private: std::string currentBundleName = ""; std::atomic isThreadRunning{false}; + std::atomic reportThreadRunning{false}; std::thread ioThread; std::mutex sleepMutex; std::mutex cvMute; @@ -61,11 +62,24 @@ private: IoDataToWrite dataToWrite; AppExecFwk::AppStateData lastestAppStateData; + std::vector ioTimes; + std::vector ioBundleName; + std::vector ioReadCharDiff; + std::vector ioSyscReadDiff; + std::vector ioReadBytesDiff; + std::vector ioSyscOpenDiff; + std::vector ioSyscStatDiff; + std::vector ioResult; + bool ReadIoDataFromFile(const std::string &path); void RecordDataToFile(const std::string &path); bool IsFirstLineHeader(const std::string &path); void RecordIoData(); void ProcessIoData(const std::string &path); + void PushData(const std::vector &fields); + void ReadAndReportIoMessage(); + void CheckMaxSizeAndReport(); + void Report(); public: static IoMessageManager &GetInstance(); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 8bf0b017a..c19ee8674 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -14,6 +14,7 @@ */ #include "io_message_listener.h" +#include "hisysevent.h" #include "utils_log.h" using namespace std; @@ -28,9 +29,13 @@ const int32_t GET_FREQUENCY = 5; const int32_t READ_THRESHOLD = 1000; const int32_t OPEN_THRESHOLD = 1000; const int32_t STAT_THRESHOLD = 1000; -const string IO_DATA_FILE_PATH = "/data/service/el1/public/cloudfile/rdb/io_message.csv"; +const string IO_DATA_FILE_PATH = "/data/service/el1/public/cloudfile/io/"; +const string IO_FILE_NAME = "io_message.csv"; +const string IO_NEED_REPORT_PREFIX = "wait_report_"; const int32_t TYPE_FRONT = 2; const int32_t TYPE_BACKGROUND = 4; +const int32_t MAX_IO_FILE_SIZE = 128 * 1024; +int32_t MAX_IO_REPORT_NUMBER = 100; IoMessageManager &IoMessageManager::GetInstance() { @@ -110,6 +115,148 @@ void IoMessageManager::RecordDataToFile(const string &path) LOGI("Write io data success"); } +static vector ConvertToCStringArray(const vector& vec) +{ + vector cstrVec; + for (const auto& str : vec) { + cstrVec.push_back(str.c_str()); + } + return cstrVec; +} + +void IoMessageManager::Report() +{ + auto charIoTimes = ConvertToCStringArray(ioTimes); + auto charIoBundleName = ConvertToCStringArray(ioBundleName); + auto charIoReadCharDiff = ConvertToCStringArray(ioReadCharDiff); + auto charIoSyscReadDiff = ConvertToCStringArray(ioSyscReadDiff); + auto charIoReadBytesDiff = ConvertToCStringArray(ioReadBytesDiff); + auto charIoSyscOpenDiff = ConvertToCStringArray(ioSyscOpenDiff); + auto charIoSyscStatDiff = ConvertToCStringArray(ioSyscStatDiff); + auto charIoResult = ConvertToCStringArray(ioResult); + + HiSysEventParam params[] = { + { "time", HISYSEVENT_STRING_ARRAY, { .array = charIoTimes.data() }, + static_cast(charIoTimes.size()) }, + { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = charIoBundleName.data() }, + static_cast(charIoBundleName.size()) }, + { "ReadCharDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoReadCharDiff.data() }, + static_cast(charIoReadCharDiff.size()) }, + { "SyscReadDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscReadDiff.data() }, + static_cast(charIoSyscReadDiff.size()) }, + { "ReadBytesDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoReadBytesDiff.data() }, + static_cast(charIoReadBytesDiff.size()) }, + { "SyscOpenDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscOpenDiff.data() }, + static_cast(charIoSyscOpenDiff.size()) }, + { "SyscStatDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscStatDiff.data() }, + static_cast(charIoSyscStatDiff.size()) }, + { "Result", HISYSEVENT_STRING_ARRAY, { .array = charIoResult.data() }, + static_cast(charIoResult.size()) }, + }; + + auto ret = OH_HiSysEvent_Write( + "KERNEL_VENDOR", + "CLOUD_DISK_IO", + HISYSEVENT_FAULT, + params, + sizeof(params) / sizeof(params[0]) + ); + + if (ret != 0) { + LOGE("Report failed, err : %{public}d", ret); + } + + ioTimes.clear(); + ioBundleName.clear(); + ioReadCharDiff.clear(); + ioSyscReadDiff.clear(); + ioReadBytesDiff.clear(); + ioSyscOpenDiff.clear(); + ioSyscStatDiff.clear(); + ioResult.clear(); +} + +void IoMessageManager::PushData(const vector &fields) +{ + static const std::map> fieldMap = { + { 0, [this](const std::string& value) { ioTimes.push_back(value); }}, + { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, + { 2, [this](const std::string& value) { ioReadCharDiff.push_back(value); }}, + { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(value); }}, + { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(value); }}, + { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(value); }}, + { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(value); }}, + { 7, [this](const std::string& value) { ioResult.push_back(value); }}, + }; + for (int i = 0; i < fields.size(); ++i) { + auto it = fieldMap.find(i); + if (it == fieldMap.end()) { + LOGE("Unknow field index: %{public}d", i); + continue; + } + it->second(fields[i]); + } +} + +void IoMessageManager::ReadAndReportIoMessage() +{ + ifstream localData(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); + if (!localData) { + LOGE("Open cloud data statistic local data fail : %{public}d", errno); + return; + } + + string line; + int32_t reportCount = 0; + while (getline(localData, line)) { + vector fields; + istringstream iss(line); + string token; + + while (getline(iss, token, ',')) { + fields.push_back(token); + } + + PushData(fields); + reportCount++; + + if (reportCount >= MAX_IO_REPORT_NUMBER) { + Report(); + reportCount = 0; + } + } + if (reportCount > 0) { + Report(); + } + bool ret = filesystem::remove(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); + if (!ret) { + LOGE("Failed to remove need_report_io_file, err:%{public}d", errno); + } + reportThreadRunning.store(false); +} + +void IoMessageManager::CheckMaxSizeAndReport() +{ + try { + auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); + if (fileSize >= MAX_IO_FILE_SIZE) { + if (filesystem::exists(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME)) { + LOGI("Report file exist"); + } + filesystem::rename(IO_DATA_FILE_PATH + IO_FILE_NAME, + IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); + if (!reportThreadRunning.load()) { + reportThreadRunning.store(true); + LOGI("Start report io data"); + thread reportThread(&IoMessageManager::ReadAndReportIoMessage, this); + reportThread.detach(); + } + } + } catch (const filesystem::filesystem_error& e) { + LOGE("Rename or get file size failed, err: %{public}s", e.what()); + } +} + void IoMessageManager::ProcessIoData(const string &path) { if (currentBundleName != lastestAppStateData.bundleName) { @@ -141,7 +288,8 @@ void IoMessageManager::ProcessIoData(const string &path) if (dataToWrite.result >= READ_THRESHOLD || dataToWrite.syscopenDiff >= OPEN_THRESHOLD || dataToWrite.syscstatDiff >= STAT_THRESHOLD) { - RecordDataToFile(IO_DATA_FILE_PATH); + CheckMaxSizeAndReport(); + RecordDataToFile(IO_DATA_FILE_PATH + IO_FILE_NAME); } preData = currentData; diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 98d14d79c..ab7e8a4e3 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -45,6 +45,7 @@ using namespace std; using namespace CloudDisk; namespace { + static const string IO_MESSAGE_DIR = "/data/service/el1/public/cloudfile/io/"; static const string BETA_VERSION = "beta"; static const string CN_REGION = "CN"; static const string GLOBAL_REGION = "const.global.region"; @@ -133,6 +134,14 @@ void CloudDaemon::OnStart() if (ShouldRegisterListener()) { auto bundleNameList = vector{}; std::thread listenThread([bundleNameList] { + if (!filesystem::create_directories(IO_MESSAGE_DIR)) { + try { + filesystem::create_directories(IO_MESSAGE_DIR); + } catch (const filesystem::filesystem_error& e) { + LOGI("Mkdir for io failed"); + return; + } + } CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); }); listenThread.detach(); -- Gitee From 51ecf65fb1337f4bb4efe356d7fa98f4a9254a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Wed, 3 Sep 2025 19:58:39 +0800 Subject: [PATCH 02/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 14 +++---- .../src/cloud_disk/io_message_listener.cpp | 41 ++++++++----------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 534258b87..d1cf11a92 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -62,14 +62,14 @@ private: IoDataToWrite dataToWrite; AppExecFwk::AppStateData lastestAppStateData; - std::vector ioTimes; + std::vector ioTimes; std::vector ioBundleName; - std::vector ioReadCharDiff; - std::vector ioSyscReadDiff; - std::vector ioReadBytesDiff; - std::vector ioSyscOpenDiff; - std::vector ioSyscStatDiff; - std::vector ioResult; + std::vector ioReadCharDiff; + std::vector ioSyscReadDiff; + std::vector ioReadBytesDiff; + std::vector ioSyscOpenDiff; + std::vector ioSyscStatDiff; + std::vector ioResult; bool ReadIoDataFromFile(const std::string &path); void RecordDataToFile(const std::string &path); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index c19ee8674..ae75167f0 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -126,38 +126,31 @@ static vector ConvertToCStringArray(const vector& vec) void IoMessageManager::Report() { - auto charIoTimes = ConvertToCStringArray(ioTimes); auto charIoBundleName = ConvertToCStringArray(ioBundleName); - auto charIoReadCharDiff = ConvertToCStringArray(ioReadCharDiff); - auto charIoSyscReadDiff = ConvertToCStringArray(ioSyscReadDiff); - auto charIoReadBytesDiff = ConvertToCStringArray(ioReadBytesDiff); - auto charIoSyscOpenDiff = ConvertToCStringArray(ioSyscOpenDiff); - auto charIoSyscStatDiff = ConvertToCStringArray(ioSyscStatDiff); - auto charIoResult = ConvertToCStringArray(ioResult); HiSysEventParam params[] = { - { "time", HISYSEVENT_STRING_ARRAY, { .array = charIoTimes.data() }, + { "time", HISYSEVENT_INT32_ARRAY, { .array = charIoTimes.data() }, static_cast(charIoTimes.size()) }, { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = charIoBundleName.data() }, static_cast(charIoBundleName.size()) }, - { "ReadCharDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoReadCharDiff.data() }, + { "ReadCharDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoReadCharDiff.data() }, static_cast(charIoReadCharDiff.size()) }, - { "SyscReadDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscReadDiff.data() }, + { "SyscReadDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscReadDiff.data() }, static_cast(charIoSyscReadDiff.size()) }, - { "ReadBytesDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoReadBytesDiff.data() }, + { "ReadBytesDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoReadBytesDiff.data() }, static_cast(charIoReadBytesDiff.size()) }, - { "SyscOpenDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscOpenDiff.data() }, + { "SyscOpenDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscOpenDiff.data() }, static_cast(charIoSyscOpenDiff.size()) }, - { "SyscStatDiff", HISYSEVENT_STRING_ARRAY, { .array = charIoSyscStatDiff.data() }, + { "SyscStatDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscStatDiff.data() }, static_cast(charIoSyscStatDiff.size()) }, - { "Result", HISYSEVENT_STRING_ARRAY, { .array = charIoResult.data() }, + { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = charIoResult.data() }, static_cast(charIoResult.size()) }, }; auto ret = OH_HiSysEvent_Write( - "KERNEL_VENDOR", - "CLOUD_DISK_IO", - HISYSEVENT_FAULT, + "HM_FS", + "ABNORMAL_IO_STATISTICS_DATA", + HISYSEVENT_STATISTIC, params, sizeof(params) / sizeof(params[0]) ); @@ -179,14 +172,14 @@ void IoMessageManager::Report() void IoMessageManager::PushData(const vector &fields) { static const std::map> fieldMap = { - { 0, [this](const std::string& value) { ioTimes.push_back(value); }}, + { 0, [this](const std::string& value) { ioTimes.push_back(std::stoi(value)); }}, { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, - { 2, [this](const std::string& value) { ioReadCharDiff.push_back(value); }}, - { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(value); }}, - { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(value); }}, - { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(value); }}, - { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(value); }}, - { 7, [this](const std::string& value) { ioResult.push_back(value); }}, + { 2, [this](const std::string& value) { ioReadCharDiff.push_back(std::stoll(value)); }}, + { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(std::stoll(value)); }}, + { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(std::stoll(value)); }}, + { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(std::stoll(value)); }}, + { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(std::stoll(value)); }}, + { 7, [this](const std::string& value) { ioResult.push_back(std::stod(value)); }}, }; for (int i = 0; i < fields.size(); ++i) { auto it = fieldMap.find(i); -- Gitee From 65d2fbcd38d3d2820fa6d4bade8fb36fcb23451c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 11:01:42 +0800 Subject: [PATCH 03/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloud_disk/io_message_listener_test.cpp | 413 ++++++++++++++++++ 1 file changed, 413 insertions(+) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 89faf55bb..82f0cae65 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,9 @@ const int32_t THREAD_SLEEP_TIME = 100; const int32_t FRONT_EVENT = 2; const int32_t BACKGROUND_EVENT = 4; const int32_t UNKNOWN_EVENT = 8; +const string IO_REPORT_FILE = "/data/service/el1/public/cloudfile/io/wait_report_io_message.csv"; +const string IO_FILE = "/data/service/el1/public/cloudfile/io/io_message.csv"; + class IoMessageListenerTest : public testing::Test { public: @@ -1338,4 +1342,413 @@ HWTEST_F(IoMessageListenerTest, OnReceiveEventTest005, TestSize.Level1) GTEST_LOG_(INFO) << "OnReceiveEventTest005 End"; } +/** + * @tc.name: Report001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, Report001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Report001 Start"; + for (int i = 0; i <= 101; i++) { + ioMessageManager_->ioTimes.push_back("tdd"); + ioMessageManager_->ioBundleName.push_back("tdd"); + ioMessageManager_->ioReadCharDiff.push_back("tdd"); + ioMessageManager_->ioSyscReadDiff.push_back("tdd"); + ioMessageManager_->ioReadBytesDiff.push_back("tdd"); + ioMessageManager_->ioSyscOpenDiff.push_back("tdd"); + ioMessageManager_->ioSyscStatDiff.push_back("tdd"); + ioMessageManager_->ioResult.push_back("tdd"); + } + try { + ioMessageManager_->Report(); + EXPECT_FALSE(false); + } catch (...) { + EXPECT_FALSE(true); + GTEST_LOG_(INFO) << "Report001 ERROR"; + } + GTEST_LOG_(INFO) << "Report001 End"; +} + +/** + * @tc.name: Report002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Report002 Start"; + for (int i = 0; i <= 10; i++) { + ioMessageManager_->ioTimes.push_back("tdd"); + ioMessageManager_->ioBundleName.push_back("tdd"); + ioMessageManager_->ioReadCharDiff.push_back("tdd"); + ioMessageManager_->ioSyscReadDiff.push_back("tdd"); + ioMessageManager_->ioReadBytesDiff.push_back("tdd"); + ioMessageManager_->ioSyscOpenDiff.push_back("tdd"); + ioMessageManager_->ioSyscStatDiff.push_back("tdd"); + ioMessageManager_->ioResult.push_back("tdd"); + } + try { + ioMessageManager_->Report(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "Report002 ERROR"; + } + GTEST_LOG_(INFO) << "Report002 End"; +} + +/** + * @tc.name: PushData001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, PushData001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PushData001 Start"; + vector fields; + try { + ioMessageManager_->PushData(fields); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PushData001 ERROR"; + } + GTEST_LOG_(INFO) << "PushData001 End"; +} + +/** + * @tc.name: PushData002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, PushData002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PushData002 Start"; + vector fields; + fields.push_back("tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd"); + try { + ioMessageManager_->PushData(fields); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PushData002 ERROR"; + } + GTEST_LOG_(INFO) << "PushData002 End"; +} + +/** + * @tc.name: PushData003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, PushData003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PushData003 Start"; + vector fields; + fields.push_back("tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd"); + try { + ioMessageManager_->PushData(fields); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PushData003 ERROR"; + } + GTEST_LOG_(INFO) << "PushData003 End"; +} + +/** + * @tc.name: ReadAndReportIoMessage001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadAndReportIoMessage001 Start"; + + try { + if (filesystem::exists(IO_REPORT_FILE)) { + filesystem::remove(IO_REPORT_FILE); + } + ioMessageManager_->Report(); + EXPECT_FALSE(false); + } catch (...) { + EXPECT_FALSE(true); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage001 ERROR"; + } + GTEST_LOG_(INFO) << "ReadAndReportIoMessage001 End"; +} + +/** + * @tc.name: ReadAndReportIoMessage002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadAndReportIoMessage002 Start"; + + try { + int fd = -1; + if (!filesystem::exists(IO_REPORT_FILE)) { + fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + close(fd); + } + + ioMessageManager_->ReadAndReportIoMessage(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage002 ERROR"; + } + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage002 End"; +} + +/** + * @tc.name: ReadAndReportIoMessage003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadAndReportIoMessage003 Start"; + + try { + int fd = -1; + if (!filesystem::exists(IO_REPORT_FILE)) { + fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + } + string line1 = "tdd tdd tdd tdd tdd tdd tdd tdd\n"; + write(fd, line1.c_str(), line1.size()); + close(fd); + + ioMessageManager_->ReadAndReportIoMessage(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage003 ERROR"; + } + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage003 End"; +} + +/** + * @tc.name: ReadAndReportIoMessage004 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadAndReportIoMessage004 Start"; + + try { + int fd = -1; + if (!filesystem::exists(IO_REPORT_FILE)) { + fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + } + string line1 = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line1.c_str(), line1.size()); + close(fd); + + ioMessageManager_->ReadAndReportIoMessage(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage004 ERROR"; + } + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage004 End"; +} + +/** + * @tc.name: ReadAndReportIoMessage005 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadAndReportIoMessage005 Start"; + + try { + int fd = -1; + if (!filesystem::exists(IO_REPORT_FILE)) { + fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + } + for (int i = 0; i <= 101; i++) { + string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line.c_str(), line.size()); + } + close(fd); + + ioMessageManager_->ReadAndReportIoMessage(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage005 ERROR"; + } + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "ReadAndReportIoMessage005 End"; +} + +/** + * @tc.name: CheckMaxSizeAndReport001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport001 Start"; + + try { + int fd = -1; + if (filesystem::exists(IO_FILE)) { + unlink(IO_FILE.c_str()); + } + + ioMessageManager_->CheckMaxSizeAndReport(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport001 ERROR"; + } + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport001 End"; +} + +/** + * @tc.name: CheckMaxSizeAndReport002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport002 Start"; + + try { + int fd = -1; + if (filesystem::exists(IO_FILE)) { + unlink(IO_FILE.c_str()); + } + fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line.c_str(), line.size()); + close(fd); + + ioMessageManager_->CheckMaxSizeAndReport(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport002 ERROR"; + } + unlink(IO_FILE.c_str()); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport002 End"; +} + +/** + * @tc.name: CheckMaxSizeAndReport003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport003 Start"; + + try { + int fd = -1; + if (filesystem::exists(IO_FILE)) { + unlink(IO_FILE.c_str()); + } + fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + for (int i = 0; i <= 20000; i++) { + string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line.c_str(), line.size()); + } + close(fd); + + if (!filesystem::exists(IO_REPORT_FILE)) { + int fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + close(fd); + } + ioMessageManager_->CheckMaxSizeAndReport(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport003 ERROR"; + } + unlink(IO_FILE.c_str()); + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport003 End"; +} + +/** + * @tc.name: CheckMaxSizeAndReport004 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport004 Start"; + + try { + int fd = -1; + if (filesystem::exists(IO_FILE)) { + unlink(IO_FILE.c_str()); + } + fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + for (int i = 0; i <= 20000; i++) { + string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line.c_str(), line.size()); + } + close(fd); + + if (filesystem::exists(IO_REPORT_FILE)) { + unlink(IO_REPORT_FILE.c_str()); + } + ioMessageManager_->CheckMaxSizeAndReport(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport004 ERROR"; + } + unlink(IO_FILE.c_str()); + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport004 End"; +} + +/** + * @tc.name: CheckMaxSizeAndReport005 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport005 Start"; + + try { + int fd = -1; + if (filesystem::exists(IO_FILE)) { + unlink(IO_FILE.c_str()); + } + fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + for (int i = 0; i <= 20000; i++) { + string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; + write(fd, line.c_str(), line.size()); + } + close(fd); + + if (filesystem::exists(IO_REPORT_FILE)) { + unlink(IO_REPORT_FILE.c_str()); + } + ioMessageManager_->reportThreadRunning.store(true); + ioMessageManager_->CheckMaxSizeAndReport(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport005 ERROR"; + } + unlink(IO_FILE.c_str()); + unlink(IO_REPORT_FILE.c_str()); + GTEST_LOG_(INFO) << "CheckMaxSizeAndReport005 End"; +} + } // namespace OHOS::FileManagement::CloudDisk::Test \ No newline at end of file -- Gitee From 5ed083d5024ed9adc4ca5a93bde3d2c673d7eda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 16:11:30 +0800 Subject: [PATCH 04/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 1 - .../src/cloud_disk/io_message_listener.cpp | 124 +++++++++--------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index d1cf11a92..1e3f55bec 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -73,7 +73,6 @@ private: bool ReadIoDataFromFile(const std::string &path); void RecordDataToFile(const std::string &path); - bool IsFirstLineHeader(const std::string &path); void RecordIoData(); void ProcessIoData(const std::string &path); void PushData(const std::vector &fields); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index ae75167f0..c56d04c8f 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -80,17 +80,6 @@ bool IoMessageManager::ReadIoDataFromFile(const std::string &path) return true; } -bool IoMessageManager::IsFirstLineHeader(const string &path) -{ - ifstream inFile(path); - if (!inFile.is_open()) { - return false; - } - - string firstLine; - getline(inFile, firstLine); - return firstLine.find("time") != string::npos; -} void IoMessageManager::RecordDataToFile(const string &path) { @@ -100,10 +89,6 @@ void IoMessageManager::RecordDataToFile(const string &path) return; } - if (!IsFirstLineHeader(path)) { - outFile << "time, bundle_name, rchar_diff, syscr_diff, read_bytes_diff, syscopen_diff, syscstat_diff, result\n"; - } - outFile << bundleTimeMap[dataToWrite.bundleName] << "," << dataToWrite.bundleName << "," << dataToWrite.rcharDiff << "," @@ -129,22 +114,22 @@ void IoMessageManager::Report() auto charIoBundleName = ConvertToCStringArray(ioBundleName); HiSysEventParam params[] = { - { "time", HISYSEVENT_INT32_ARRAY, { .array = charIoTimes.data() }, - static_cast(charIoTimes.size()) }, - { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = charIoBundleName.data() }, + { "time", HISYSEVENT_INT32_ARRAY, { .array = ioTimes.data() }, + static_cast(ioTimes.size()) }, + { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = IoBundleName.data() }, static_cast(charIoBundleName.size()) }, - { "ReadCharDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoReadCharDiff.data() }, - static_cast(charIoReadCharDiff.size()) }, - { "SyscReadDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscReadDiff.data() }, - static_cast(charIoSyscReadDiff.size()) }, - { "ReadBytesDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoReadBytesDiff.data() }, - static_cast(charIoReadBytesDiff.size()) }, - { "SyscOpenDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscOpenDiff.data() }, - static_cast(charIoSyscOpenDiff.size()) }, - { "SyscStatDiff", HISYSEVENT_INT64_ARRAY, { .array = charIoSyscStatDiff.data() }, - static_cast(charIoSyscStatDiff.size()) }, - { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = charIoResult.data() }, - static_cast(charIoResult.size()) }, + { "ReadCharDiff", HISYSEVENT_INT64_ARRAY, { .array = ioReadCharDiff.data() }, + static_cast(ioReadCharDiff.size()) }, + { "SyscReadDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscReadDiff.data() }, + static_cast(ioSyscReadDiff.size()) }, + { "ReadBytesDiff", HISYSEVENT_INT64_ARRAY, { .array = ioReadBytesDiff.data() }, + static_cast(ioReadBytesDiff.size()) }, + { "SyscOpenDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscOpenDiff.data() }, + static_cast(ioSyscOpenDiff.size()) }, + { "SyscStatDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscStatDiff.data() }, + static_cast(ioSyscStatDiff.size()) }, + { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = ioResult.data() }, + static_cast(ioResult.size()) }, }; auto ret = OH_HiSysEvent_Write( @@ -171,23 +156,31 @@ void IoMessageManager::Report() void IoMessageManager::PushData(const vector &fields) { - static const std::map> fieldMap = { - { 0, [this](const std::string& value) { ioTimes.push_back(std::stoi(value)); }}, - { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, - { 2, [this](const std::string& value) { ioReadCharDiff.push_back(std::stoll(value)); }}, - { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(std::stoll(value)); }}, - { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(std::stoll(value)); }}, - { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(std::stoll(value)); }}, - { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(std::stoll(value)); }}, - { 7, [this](const std::string& value) { ioResult.push_back(std::stod(value)); }}, - }; - for (int i = 0; i < fields.size(); ++i) { - auto it = fieldMap.find(i); - if (it == fieldMap.end()) { - LOGE("Unknow field index: %{public}d", i); - continue; + try{ + static const std::map> fieldMap = { + { 0, [this](const std::string& value) { ioTimes.push_back(std::stoi(value)); }}, + { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, + { 2, [this](const std::string& value) { ioReadCharDiff.push_back(std::stoll(value)); }}, + { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(std::stoll(value)); }}, + { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(std::stoll(value)); }}, + { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(std::stoll(value)); }}, + { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(std::stoll(value)); }}, + { 7, [this](const std::string& value) { ioResult.push_back(std::stod(value)); }}, + }; + for (int i = 0; i < fields.size(); ++i) { + auto it = fieldMap.find(i); + if (it == fieldMap.end()) { + LOGE("Unknow field index: %{public}d", i); + continue; + } + it->second(fields[i]); } - it->second(fields[i]); + } catch (const invalid_argument& e) { + LOGE("Invalid argument: %{public}s", e.what()); + return; + } catch (const out_of_range& e) { + LOGE("Out of range: %{public}s", e.what()); + return; } } @@ -305,26 +298,35 @@ void IoMessageManager::RecordIoData() void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateData) { - if (appStateData.bundleName != DESK_BUNDLE_NAME) { - if (appStateData.state == TYPE_FRONT) { - lastestAppStateData = appStateData; - if (!ioThread.joinable()) { + if (appStateData.bundleName == DESK_BUNDLE_NAME) { + return; + } + if (appStateData.state == TYPE_FRONT) { + lastestAppStateData = appStateData; + if (!ioThread.joinable()) { + try { isThreadRunning.store(true); ioThread = thread(&IoMessageManager::RecordIoData, this); - } - return; - } - if (appStateData.state == TYPE_BACKGROUND) { - if (ioThread.joinable()) { - lock_guard lock(cvMute); + } catch (const std::system_error &e) { + LOGE("System error while creating thread: %{public}s", e.what()); + isThreadRunning.store(false); + } catch (const std::exception &e) { + LOGE("Exception while creating thread: %{public}s", e.what()); isThreadRunning.store(false); - sleepCv.notify_all(); - ioThread.join(); - ioThread = thread(); - currentData = {}; - preData = {}; } } + return; + } + if (appStateData.state == TYPE_BACKGROUND) { + if (ioThread.joinable()) { + lock_guard lock(cvMute); + isThreadRunning.store(false); + sleepCv.notify_all(); + ioThread.join(); + ioThread = thread(); + currentData = {}; + preData = {}; + } } } } // namespace CloudDisk -- Gitee From e40dc13e887cff3392362c04c0c731775a5bf989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 16:13:51 +0800 Subject: [PATCH 05/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index c56d04c8f..7b7c36205 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -116,7 +116,7 @@ void IoMessageManager::Report() HiSysEventParam params[] = { { "time", HISYSEVENT_INT32_ARRAY, { .array = ioTimes.data() }, static_cast(ioTimes.size()) }, - { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = IoBundleName.data() }, + { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = charIoBundleName.data() }, static_cast(charIoBundleName.size()) }, { "ReadCharDiff", HISYSEVENT_INT64_ARRAY, { .array = ioReadCharDiff.data() }, static_cast(ioReadCharDiff.size()) }, -- Gitee From 8e4ddc6d7f231e38dcaa02803924afbfc83a1f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 19:06:47 +0800 Subject: [PATCH 06/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/ipc/cloud_daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index ab7e8a4e3..4a4c2c61d 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -134,7 +134,7 @@ void CloudDaemon::OnStart() if (ShouldRegisterListener()) { auto bundleNameList = vector{}; std::thread listenThread([bundleNameList] { - if (!filesystem::create_directories(IO_MESSAGE_DIR)) { + if (!filesystem::exists(IO_MESSAGE_DIR)) { try { filesystem::create_directories(IO_MESSAGE_DIR); } catch (const filesystem::filesystem_error& e) { -- Gitee From 8a261af26ab1238c57447b330dc4910dedd8923b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 22:31:54 +0800 Subject: [PATCH 07/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 1 + .../src/cloud_disk/io_message_listener.cpp | 14 ++++++++++++++ .../cloudfiledaemon/src/ipc/cloud_daemon.cpp | 16 +++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 1e3f55bec..eda7f2d28 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -75,6 +75,7 @@ private: void RecordDataToFile(const std::string &path); void RecordIoData(); void ProcessIoData(const std::string &path); + void PushDataRollBack(); void PushData(const std::vector &fields); void ReadAndReportIoMessage(); void CheckMaxSizeAndReport(); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 7b7c36205..476ec2ab5 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -154,6 +154,18 @@ void IoMessageManager::Report() ioResult.clear(); } +void PushDataRollBack() { + size_t initialSize = ioResult.size(); + ioTimes.resize(initialSize); + ioBundleName.resize(initialSize); + ioReadCharDiff.resize(initialSize); + ioSyscReadDiff.resize(initialSize); + ioReadBytesDiff.resize(initialSize); + ioSyscOpenDiff.resize(initialSize); + ioSyscStatDiff.resize(initialSize); + ioResult.resize(initialSize); +} + void IoMessageManager::PushData(const vector &fields) { try{ @@ -177,9 +189,11 @@ void IoMessageManager::PushData(const vector &fields) } } catch (const invalid_argument& e) { LOGE("Invalid argument: %{public}s", e.what()); + PushDataRollBack(); return; } catch (const out_of_range& e) { LOGE("Out of range: %{public}s", e.what()); + PushDataRollBack(); return; } } diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 4a4c2c61d..6dd7174e2 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -134,13 +134,15 @@ void CloudDaemon::OnStart() if (ShouldRegisterListener()) { auto bundleNameList = vector{}; std::thread listenThread([bundleNameList] { - if (!filesystem::exists(IO_MESSAGE_DIR)) { - try { - filesystem::create_directories(IO_MESSAGE_DIR); - } catch (const filesystem::filesystem_error& e) { - LOGI("Mkdir for io failed"); - return; - } + if (filesystem::exists(IO_MESSAGE_DIR)) { + CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); + return; + } + try { + filesystem::create_directories(IO_MESSAGE_DIR); + } catch (const filesystem::filesystem_error& e) { + LOGI("Mkdir for io failed"); + return; } CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); }); -- Gitee From a1f43d13cd4b6d7974f74b08384938374a88970c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 4 Sep 2025 22:34:38 +0800 Subject: [PATCH 08/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloud_disk/io_message_listener_test.cpp | 114 +++++------------- 1 file changed, 32 insertions(+), 82 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 82f0cae65..da3178265 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -557,74 +557,6 @@ HWTEST_F(IoMessageListenerTest, ReadIoDataFromFileTest017, TestSize.Level1) GTEST_LOG_(INFO) << "ReadIoDataFromFileTest017 End"; } -/** - * @tc.name: IsFirstLineHeaderTest001 - * @tc.desc: Read IO data - * @tc.type: FUNC - * @tc.require: issuesI92WQP - */ -HWTEST_F(IoMessageListenerTest, IsFirstLineHeaderTest001, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest001 Start"; - string path = "/data/service/el1/public/cloudfile/rdb/1.txt"; - try { - bool ret = ioMessageManager_->IsFirstLineHeader(path); - EXPECT_FALSE(ret); - } catch (...) { - EXPECT_FALSE(true); - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest001 ERROR"; - } - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest001 End"; -} - -/** - * @tc.name: IsFirstLineHeaderTest002 - * @tc.desc: Read IO data - * @tc.type: FUNC - * @tc.require: issuesI92WQP - */ -HWTEST_F(IoMessageListenerTest, IsFirstLineHeaderTest002, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest002 Start"; - string path = "/data/service/el1/public/cloudfile/rdb/1.txt"; - try { - int fd = open(path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - close(fd); - bool ret = ioMessageManager_->IsFirstLineHeader(path); - EXPECT_FALSE(ret); - } catch (...) { - EXPECT_FALSE(true); - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest002 ERROR"; - } - unlink(path.c_str()); - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest002 End"; -} - -/** - * @tc.name: IsFirstLineHeaderTest003 - * @tc.desc: Read IO data - * @tc.type: FUNC - * @tc.require: issuesI92WQP - */ -HWTEST_F(IoMessageListenerTest, IsFirstLineHeaderTest003, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest003 Start"; - string path = "/data/service/el1/public/cloudfile/rdb/1.txt"; - try { - int fd = open(path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - string line1 = "time\n"; - write(fd, line1.c_str(), line1.size()); - close(fd); - bool ret = ioMessageManager_->IsFirstLineHeader(path); - EXPECT_TRUE(ret); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest003 ERROR"; - } - unlink(path.c_str()); - GTEST_LOG_(INFO) << "IsFirstLineHeaderTest003 End"; -} - /** * @tc.name: RecordDataToFileTest001 * @tc.desc: Read IO data @@ -1351,14 +1283,14 @@ HWTEST_F(IoMessageListenerTest, Report001, TestSize.Level1) { GTEST_LOG_(INFO) << "Report001 Start"; for (int i = 0; i <= 101; i++) { - ioMessageManager_->ioTimes.push_back("tdd"); + ioMessageManager_->ioTimes.push_back(1); ioMessageManager_->ioBundleName.push_back("tdd"); - ioMessageManager_->ioReadCharDiff.push_back("tdd"); - ioMessageManager_->ioSyscReadDiff.push_back("tdd"); - ioMessageManager_->ioReadBytesDiff.push_back("tdd"); - ioMessageManager_->ioSyscOpenDiff.push_back("tdd"); - ioMessageManager_->ioSyscStatDiff.push_back("tdd"); - ioMessageManager_->ioResult.push_back("tdd"); + ioMessageManager_->ioReadCharDiff.push_back(1); + ioMessageManager_->ioSyscReadDiff.push_back(1); + ioMessageManager_->ioReadBytesDiff.push_back(1); + ioMessageManager_->ioSyscOpenDiff.push_back(1); + ioMessageManager_->ioSyscStatDiff.push_back(1); + ioMessageManager_->ioResult.push_back(1.0); } try { ioMessageManager_->Report(); @@ -1379,14 +1311,14 @@ HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) { GTEST_LOG_(INFO) << "Report002 Start"; for (int i = 0; i <= 10; i++) { - ioMessageManager_->ioTimes.push_back("tdd"); + ioMessageManager_->ioTimes.push_back(1); ioMessageManager_->ioBundleName.push_back("tdd"); - ioMessageManager_->ioReadCharDiff.push_back("tdd"); - ioMessageManager_->ioSyscReadDiff.push_back("tdd"); - ioMessageManager_->ioReadBytesDiff.push_back("tdd"); - ioMessageManager_->ioSyscOpenDiff.push_back("tdd"); - ioMessageManager_->ioSyscStatDiff.push_back("tdd"); - ioMessageManager_->ioResult.push_back("tdd"); + ioMessageManager_->ioReadCharDiff.push_back(1); + ioMessageManager_->ioSyscReadDiff.push_back(1); + ioMessageManager_->ioReadBytesDiff.push_back(1); + ioMessageManager_->ioSyscOpenDiff.push_back(1); + ioMessageManager_->ioSyscStatDiff.push_back(1); + ioMessageManager_->ioResult.push_back(1.0); } try { ioMessageManager_->Report(); @@ -1398,6 +1330,24 @@ HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) GTEST_LOG_(INFO) << "Report002 End"; } +/** + * @tc.name: PushDataRollBack001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, PushDataRollBack001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PushDataRollBack001 Start"; + try { + ioMessageManager_->PushDataRollBack(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PushDataRollBack001 ERROR"; + } + GTEST_LOG_(INFO) << "PushDataRollBack001 End"; +} + /** * @tc.name: PushData001 * @tc.desc: Report IO data -- Gitee From af7b34ed84939015098b170f72d9d64efad16585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 09:15:41 +0800 Subject: [PATCH 09/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 476ec2ab5..246b59c3f 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -154,7 +154,7 @@ void IoMessageManager::Report() ioResult.clear(); } -void PushDataRollBack() { +void IoMessageManager::PushDataRollBack() { size_t initialSize = ioResult.size(); ioTimes.resize(initialSize); ioBundleName.resize(initialSize); -- Gitee From dfa3ab51df56de436dff01cc3bde4d8b7612bc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 09:27:30 +0800 Subject: [PATCH 10/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../src/cloud_disk/io_message_listener.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 246b59c3f..721ff650f 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -131,7 +131,6 @@ void IoMessageManager::Report() { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = ioResult.data() }, static_cast(ioResult.size()) }, }; - auto ret = OH_HiSysEvent_Write( "HM_FS", "ABNORMAL_IO_STATISTICS_DATA", @@ -139,11 +138,9 @@ void IoMessageManager::Report() params, sizeof(params) / sizeof(params[0]) ); - if (ret != 0) { LOGE("Report failed, err : %{public}d", ret); } - ioTimes.clear(); ioBundleName.clear(); ioReadCharDiff.clear(); @@ -154,11 +151,12 @@ void IoMessageManager::Report() ioResult.clear(); } -void IoMessageManager::PushDataRollBack() { +void IoMessageManager::PushDataRollBack() +{ size_t initialSize = ioResult.size(); ioTimes.resize(initialSize); ioBundleName.resize(initialSize); - ioReadCharDiff.resize(initialSize); + ioReadCharDiff.resize(inNORMAL_IO_STATISTICS_DATitialSize); ioSyscReadDiff.resize(initialSize); ioReadBytesDiff.resize(initialSize); ioSyscOpenDiff.resize(initialSize); @@ -168,7 +166,7 @@ void IoMessageManager::PushDataRollBack() { void IoMessageManager::PushData(const vector &fields) { - try{ + try { static const std::map> fieldMap = { { 0, [this](const std::string& value) { ioTimes.push_back(std::stoi(value)); }}, { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, -- Gitee From 1e002a32e1172da4fe80a74a48ba6eab12a11998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 09:46:30 +0800 Subject: [PATCH 11/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index da3178265..ea4de52b5 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1616,8 +1616,8 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport003, TestSize.Level1) close(fd); if (!filesystem::exists(IO_REPORT_FILE)) { - int fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - close(fd); + int fd2 = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + close(fd2); } ioMessageManager_->CheckMaxSizeAndReport(); EXPECT_TRUE(true); -- Gitee From 3511c42c4a786e67268832bb823ab29d7a9375d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 10:51:51 +0800 Subject: [PATCH 12/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 721ff650f..d4a9fb8eb 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -131,6 +131,7 @@ void IoMessageManager::Report() { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = ioResult.data() }, static_cast(ioResult.size()) }, }; + auto ret = OH_HiSysEvent_Write( "HM_FS", "ABNORMAL_IO_STATISTICS_DATA", @@ -156,7 +157,7 @@ void IoMessageManager::PushDataRollBack() size_t initialSize = ioResult.size(); ioTimes.resize(initialSize); ioBundleName.resize(initialSize); - ioReadCharDiff.resize(inNORMAL_IO_STATISTICS_DATitialSize); + ioReadCharDiff.resize(initialSize); ioSyscReadDiff.resize(initialSize); ioReadBytesDiff.resize(initialSize); ioSyscOpenDiff.resize(initialSize); -- Gitee From f3ff22cca03a0b46c72de9dbde44709a8fa75eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 10:53:44 +0800 Subject: [PATCH 13/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index d4a9fb8eb..7c1dc9396 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -144,6 +144,7 @@ void IoMessageManager::Report() } ioTimes.clear(); ioBundleName.clear(); + charIoBundleName.clear(); ioReadCharDiff.clear(); ioSyscReadDiff.clear(); ioReadBytesDiff.clear(); -- Gitee From 6f113e31f6cf230190e2ee39b58867ea00e1a8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 10:57:15 +0800 Subject: [PATCH 14/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/include/cloud_disk/io_message_listener.h | 1 + services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index eda7f2d28..67b59614c 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -55,6 +55,7 @@ private: std::thread ioThread; std::mutex sleepMutex; std::mutex cvMute; + std::mutex iothreadMute; std::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 7c1dc9396..dd0668041 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -317,6 +317,7 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa } if (appStateData.state == TYPE_FRONT) { lastestAppStateData = appStateData; + lock_guard lock(iothreadMute); if (!ioThread.joinable()) { try { isThreadRunning.store(true); @@ -332,6 +333,7 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa return; } if (appStateData.state == TYPE_BACKGROUND) { + lock_guard lock(iothreadMute); if (ioThread.joinable()) { lock_guard lock(cvMute); isThreadRunning.store(false); -- Gitee From 9430ee24a1946bb815868ff6bea85529bb01eef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 14:23:39 +0800 Subject: [PATCH 15/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/include/cloud_disk/io_message_listener.h | 1 - services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 67b59614c..eda7f2d28 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -55,7 +55,6 @@ private: std::thread ioThread; std::mutex sleepMutex; std::mutex cvMute; - std::mutex iothreadMute; std::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index dd0668041..7c1dc9396 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -317,7 +317,6 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa } if (appStateData.state == TYPE_FRONT) { lastestAppStateData = appStateData; - lock_guard lock(iothreadMute); if (!ioThread.joinable()) { try { isThreadRunning.store(true); @@ -333,7 +332,6 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa return; } if (appStateData.state == TYPE_BACKGROUND) { - lock_guard lock(iothreadMute); if (ioThread.joinable()) { lock_guard lock(cvMute); isThreadRunning.store(false); -- Gitee From e23205f372a13354b6086eda7c9c1058a42e0ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 5 Sep 2025 15:46:57 +0800 Subject: [PATCH 16/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/ipc/cloud_daemon.cpp | 2 +- .../cloud_disk/io_message_listener_test.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 6dd7174e2..daa72089f 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -141,7 +141,7 @@ void CloudDaemon::OnStart() try { filesystem::create_directories(IO_MESSAGE_DIR); } catch (const filesystem::filesystem_error& e) { - LOGI("Mkdir for io failed"); + LOGE("Mkdir for io failed"); return; } CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index ea4de52b5..63855f7da 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -39,6 +39,8 @@ const int32_t THREAD_SLEEP_TIME = 100; const int32_t FRONT_EVENT = 2; const int32_t BACKGROUND_EVENT = 4; const int32_t UNKNOWN_EVENT = 8; +const int32_t LOOP_COUNT = 20000; +const int32_t FEWER_LOOP_COUNT = 101; const string IO_REPORT_FILE = "/data/service/el1/public/cloudfile/io/wait_report_io_message.csv"; const string IO_FILE = "/data/service/el1/public/cloudfile/io/io_message.csv"; @@ -1310,7 +1312,7 @@ HWTEST_F(IoMessageListenerTest, Report001, TestSize.Level1) HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) { GTEST_LOG_(INFO) << "Report002 Start"; - for (int i = 0; i <= 10; i++) { + for (int i = 0; i <= FEWER_LOOP_COUNT; i++) { ioMessageManager_->ioTimes.push_back(1); ioMessageManager_->ioBundleName.push_back("tdd"); ioMessageManager_->ioReadCharDiff.push_back(1); @@ -1525,7 +1527,7 @@ HWTEST_F(IoMessageListenerTest, ReadAndReportIoMessage005, TestSize.Level1) if (!filesystem::exists(IO_REPORT_FILE)) { fd = open(IO_REPORT_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); } - for (int i = 0; i <= 101; i++) { + for (int i = 0; i <= FEWER_LOOP_COUNT; i++) { string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; write(fd, line.c_str(), line.size()); } @@ -1609,7 +1611,7 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport003, TestSize.Level1) unlink(IO_FILE.c_str()); } fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - for (int i = 0; i <= 20000; i++) { + for (int i = 0; i <= LOOP_COUNT; i++) { string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; write(fd, line.c_str(), line.size()); } @@ -1645,7 +1647,7 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport004, TestSize.Level1) unlink(IO_FILE.c_str()); } fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - for (int i = 0; i <= 20000; i++) { + for (int i = 0; i <= LOOP_COUNT; i++) { string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; write(fd, line.c_str(), line.size()); } @@ -1680,7 +1682,7 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport005, TestSize.Level1) unlink(IO_FILE.c_str()); } fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); - for (int i = 0; i <= 20000; i++) { + for (int i = 0; i <= LOOP_COUNT; i++) { string line = "tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd\n"; write(fd, line.c_str(), line.size()); } -- Gitee From 193cde90d15a883ccfe0ab73777560a66ea41751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 14:39:54 +0800 Subject: [PATCH 17/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 54 ++++- .../src/cloud_disk/io_message_listener.cpp | 229 +++++++++++------- 2 files changed, 181 insertions(+), 102 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index eda7f2d28..6158038ca 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -47,6 +47,27 @@ struct IoDataToWrite { double result = 0; }; +using Int32Vector = std::vector; +using Int64Vector = std::vector; +using StringVector = std::vector; +using DoubleVector = std::vector; + +enum class VectorIndex { + IO_TIMES, + IO_BUNDLE_NAME, + IO_READ_CHAR_DIFF, + IO_SYSC_READ_DIFF, + IO_READ_BYTES_DIFF, + IO_SYSC_OPEN_DIFF, + IO_SYSC_STAT_DIFF, + IO_RESULT +}; +using VectorVariant = std::variant< + Int32Vector, + StringVector, + Int64Vector, + DoubleVector +>; class IoMessageManager { private: std::string currentBundleName = ""; @@ -55,6 +76,7 @@ private: std::thread ioThread; std::mutex sleepMutex; std::mutex cvMute; + std::mutex iothreadMutex; std::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; @@ -62,20 +84,34 @@ private: IoDataToWrite dataToWrite; AppExecFwk::AppStateData lastestAppStateData; - std::vector ioTimes; - std::vector ioBundleName; - std::vector ioReadCharDiff; - std::vector ioSyscReadDiff; - std::vector ioReadBytesDiff; - std::vector ioSyscOpenDiff; - std::vector ioSyscStatDiff; - std::vector ioResult; + Int32Vector ioTimes; + StringVector ioBundleName; + Int64Vector ioReadCharDiff; + Int64Vector ioSyscReadDiff; + Int64Vector ioReadBytesDiff; + Int64Vector ioSyscOpenDiff; + Int64Vector ioSyscStatDiff; + DoubleVector ioResult; + + std::vector targetVecots = { + VectorVariant(std::in_place_type<>, std::move(ioTimes)); + VectorVariant(std::in_place_type<>, std::move(ioBundleName)); + VectorVariant(std::in_place_type<>, std::move(ioReadCharDiff)); + VectorVariant(std::in_place_type<>, std::move(ioSyscOpenDiff)); + VectorVariant(std::in_place_type<>, std::move(ioReadBytesDiff)); + VectorVariant(std::in_place_type<>, std::move(ioSyscOpenDiff)); + VectorVariant(std::in_place_type<>, std::move(ioSyscStatDiff)); + VectorVariant(std::in_place_type<>, std::move(ioResult)); + } + template + T& GetVector(std::vector& targetVectors) { + return std::get(targetVectors[static_cast(Index)]); + } bool ReadIoDataFromFile(const std::string &path); void RecordDataToFile(const std::string &path); void RecordIoData(); void ProcessIoData(const std::string &path); - void PushDataRollBack(); void PushData(const std::vector &fields); void ReadAndReportIoMessage(); void CheckMaxSizeAndReport(); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 7c1dc9396..8255d789a 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -15,7 +15,10 @@ #include "io_message_listener.h" #include "hisysevent.h" +#include "ffrt_inner.h" #include "utils_log.h" +#include +#include using namespace std; using namespace chrono; @@ -29,6 +32,7 @@ const int32_t GET_FREQUENCY = 5; const int32_t READ_THRESHOLD = 1000; const int32_t OPEN_THRESHOLD = 1000; const int32_t STAT_THRESHOLD = 1000; +const int32_t MAX_RECORD_IN_FILE = 2400; const string IO_DATA_FILE_PATH = "/data/service/el1/public/cloudfile/io/"; const string IO_FILE_NAME = "io_message.csv"; const string IO_NEED_REPORT_PREFIX = "wait_report_"; @@ -109,27 +113,95 @@ static vector ConvertToCStringArray(const vector& vec) return cstrVec; } +template +void PushField(const std::string &value, std::vector &vec) +{ + if constexpr (std::is_same_v) { + vec.push_back(std::stoi(value)); + } else if constexpr (std::is_same_v) { + vec.push_back(std::stoll(value)); + } else if constexpr (std::is_same_v) { + vec.push_back(std::stod(value)); + } else { + vec.push_back(value); + } +} + +bool CheckInt(const std::string &value) +{ + if (value.empty()) { + return false; + } + if (!all_of(value.begin(), value.end(), ::isdigit)) { + return false; + } + return true; +} + +bool CheckDouble(const std::string &value) +{ + if (value.empty()) { + return false; + } + + char *endptr; + std::strtod(value.c_str(), &emdptr); + return *endptr == '\0' || (std::isspace(*endptr) && endptr[1] == '\0'); +} + +struct PushBackVisitor { + const std::string &value; + + template + void operator()(std::vector &vec) { + PushField(value, vec); + } +} + +struct CheckVisitor { + const std::string &value; + bool &checkType; + + template + void operator()(std::vector &vec) { + if constexpr (std::is_same_v) { + checkType = CheckInt(value); + } else if constexpr (std::is_same_v) { + checkType = CheckInt(value); + } else if constexpr (std::is_same_v) { + checkType = CheckDouble(value); + } else if constexpr (std::is_same_v) { + checkType = true; + } + } +} + +template +HiSysEventParam CreateParam(const char *name, HiSysEventParamType type, std::vector &data) +{ + HiSysEventParam param; + size_t len = std::min(strlen(name), static_cast(MAX_LENGTH_OF_PARAM_NAME - 1)); + std::copy_n(name, len, param.name); + param.name[len] = '\0'; + param.t = type; + param.v.array = data.data(); + param.arraySize = static_cast(data.size()); + return param; +} + void IoMessageManager::Report() { - auto charIoBundleName = ConvertToCStringArray(ioBundleName); + auto charIoBundleName = ConvertToCStringArray(getVector(targetVectors)); HiSysEventParam params[] = { - { "time", HISYSEVENT_INT32_ARRAY, { .array = ioTimes.data() }, - static_cast(ioTimes.size()) }, - { "BundleName", HISYSEVENT_STRING_ARRAY, { .array = charIoBundleName.data() }, - static_cast(charIoBundleName.size()) }, - { "ReadCharDiff", HISYSEVENT_INT64_ARRAY, { .array = ioReadCharDiff.data() }, - static_cast(ioReadCharDiff.size()) }, - { "SyscReadDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscReadDiff.data() }, - static_cast(ioSyscReadDiff.size()) }, - { "ReadBytesDiff", HISYSEVENT_INT64_ARRAY, { .array = ioReadBytesDiff.data() }, - static_cast(ioReadBytesDiff.size()) }, - { "SyscOpenDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscOpenDiff.data() }, - static_cast(ioSyscOpenDiff.size()) }, - { "SyscStatDiff", HISYSEVENT_INT64_ARRAY, { .array = ioSyscStatDiff.data() }, - static_cast(ioSyscStatDiff.size()) }, - { "Result", HISYSEVENT_DOUBLE_ARRAY, { .array = ioResult.data() }, - static_cast(ioResult.size()) }, + createParam("time", HISYSEVENT_INT32_ARRAY, getVector(targetVectors)), + createParam("BundleName", HISYSEVENT_STRING_ARRAY, charIoBundleName), + createParam("ReadCharDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), + createParam("SyscReadDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), + createParam("ReadBytesDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), + createParam("SyscOpenDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), + createParam("SyscStatDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), + createParam("Result", HISYSEVENT_DOUBLE_ARRAY, getVector(targetVectors)), }; auto ret = OH_HiSysEvent_Write( @@ -142,60 +214,33 @@ void IoMessageManager::Report() if (ret != 0) { LOGE("Report failed, err : %{public}d", ret); } - ioTimes.clear(); - ioBundleName.clear(); - charIoBundleName.clear(); - ioReadCharDiff.clear(); - ioSyscReadDiff.clear(); - ioReadBytesDiff.clear(); - ioSyscOpenDiff.clear(); - ioSyscStatDiff.clear(); - ioResult.clear(); -} - -void IoMessageManager::PushDataRollBack() -{ - size_t initialSize = ioResult.size(); - ioTimes.resize(initialSize); - ioBundleName.resize(initialSize); - ioReadCharDiff.resize(initialSize); - ioSyscReadDiff.resize(initialSize); - ioReadBytesDiff.resize(initialSize); - ioSyscOpenDiff.resize(initialSize); - ioSyscStatDiff.resize(initialSize); - ioResult.resize(initialSize); + auto clearVector = [](auto &vec) { + vec.clear(); + }; + for (auto &variant : targetVectors) { + std::visit(clearVector, variant); + } } void IoMessageManager::PushData(const vector &fields) { - try { - static const std::map> fieldMap = { - { 0, [this](const std::string& value) { ioTimes.push_back(std::stoi(value)); }}, - { 1, [this](const std::string& value) { ioBundleName.push_back(value); }}, - { 2, [this](const std::string& value) { ioReadCharDiff.push_back(std::stoll(value)); }}, - { 3, [this](const std::string& value) { ioSyscReadDiff.push_back(std::stoll(value)); }}, - { 4, [this](const std::string& value) { ioReadBytesDiff.push_back(std::stoll(value)); }}, - { 5, [this](const std::string& value) { ioSyscOpenDiff.push_back(std::stoll(value)); }}, - { 6, [this](const std::string& value) { ioSyscStatDiff.push_back(std::stoll(value)); }}, - { 7, [this](const std::string& value) { ioResult.push_back(std::stod(value)); }}, - }; - for (int i = 0; i < fields.size(); ++i) { - auto it = fieldMap.find(i); - if (it == fieldMap.end()) { - LOGE("Unknow field index: %{public}d", i); - continue; - } - it->second(fields[i]); - } - } catch (const invalid_argument& e) { - LOGE("Invalid argument: %{public}s", e.what()); - PushDataRollBack(); - return; - } catch (const out_of_range& e) { - LOGE("Out of range: %{public}s", e.what()); - PushDataRollBack(); + if (fields.size() != targetVectors.size()) { return; } + for (unsigned i = 0; i < fields.size(); ++i) { + bool checkType = false; + CheckVisitor visitor(fields[i], checkType); + std::visit(visitor,targetVectors[i]); + if (!checkType) { + LOGI("checkType failed. value = %{public}s", fields[i].c_str()); + return; + } + } + for (unsigned i = 0; i < fields.size(); ++i) { + PushBackVisitor visitor(fileds[i]); + std::visit(visitor, targetVectors[i]); + } + return; } void IoMessageManager::ReadAndReportIoMessage() @@ -208,6 +253,7 @@ void IoMessageManager::ReadAndReportIoMessage() string line; int32_t reportCount = 0; + int32_t totalCount = 0; while (getline(localData, line)) { vector fields; istringstream iss(line); @@ -219,11 +265,14 @@ void IoMessageManager::ReadAndReportIoMessage() PushData(fields); reportCount++; - + totalCount++; if (reportCount >= MAX_IO_REPORT_NUMBER) { Report(); reportCount = 0; } + if (totalCount >= MAX_RECORD_IN_FILE) { + break; + } } if (reportCount > 0) { Report(); @@ -237,23 +286,24 @@ void IoMessageManager::ReadAndReportIoMessage() void IoMessageManager::CheckMaxSizeAndReport() { - try { - auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); - if (fileSize >= MAX_IO_FILE_SIZE) { - if (filesystem::exists(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME)) { - LOGI("Report file exist"); - } - filesystem::rename(IO_DATA_FILE_PATH + IO_FILE_NAME, - IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); - if (!reportThreadRunning.load()) { - reportThreadRunning.store(true); - LOGI("Start report io data"); - thread reportThread(&IoMessageManager::ReadAndReportIoMessage, this); - reportThread.detach(); - } - } - } catch (const filesystem::filesystem_error& e) { - LOGE("Rename or get file size failed, err: %{public}s", e.what()); + auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); + if (fileSize < MAX_IO_FILE_SIZE) { + return; + } + if (filesystem::exists(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME)) { + LOGI("Report file exist"); + } + std::error_code errcode; + filesystem::rename(IO_DATA_FILE_PATH + IO_FILE_NAME, + IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); + if (errcode.value() != 0) { + LOGE("Failed to rename file, error code: %{public}d", errcode.value()); + return; + } + if (!reportThreadRunning.load()) { + reportThreadRunning.store(true); + LOGI("Start report io data"); + ffrt::thread([this] {ReadAndReportIoMessage();}).detach(); } } @@ -318,16 +368,9 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa if (appStateData.state == TYPE_FRONT) { lastestAppStateData = appStateData; if (!ioThread.joinable()) { - try { - isThreadRunning.store(true); - ioThread = thread(&IoMessageManager::RecordIoData, this); - } catch (const std::system_error &e) { - LOGE("System error while creating thread: %{public}s", e.what()); - isThreadRunning.store(false); - } catch (const std::exception &e) { - LOGE("Exception while creating thread: %{public}s", e.what()); - isThreadRunning.store(false); - } + isThreadRunning.store(true); + ffrt::submit([this] {RecordIoData();}, {}, {}, + ffrt::task_attr().qos(ffrt::qos_background)); } return; } -- Gitee From d67d87f5a471cadad6026f9797e588445165c8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 14:54:00 +0800 Subject: [PATCH 18/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 19 +++++----- .../src/cloud_disk/io_message_listener.cpp | 38 +++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 6158038ca..983900429 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -76,7 +76,6 @@ private: std::thread ioThread; std::mutex sleepMutex; std::mutex cvMute; - std::mutex iothreadMutex; std::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; @@ -93,15 +92,15 @@ private: Int64Vector ioSyscStatDiff; DoubleVector ioResult; - std::vector targetVecots = { - VectorVariant(std::in_place_type<>, std::move(ioTimes)); - VectorVariant(std::in_place_type<>, std::move(ioBundleName)); - VectorVariant(std::in_place_type<>, std::move(ioReadCharDiff)); - VectorVariant(std::in_place_type<>, std::move(ioSyscOpenDiff)); - VectorVariant(std::in_place_type<>, std::move(ioReadBytesDiff)); - VectorVariant(std::in_place_type<>, std::move(ioSyscOpenDiff)); - VectorVariant(std::in_place_type<>, std::move(ioSyscStatDiff)); - VectorVariant(std::in_place_type<>, std::move(ioResult)); + std::vector targetVectors = { + VectorVariant(std::in_place_type, std::move(ioTimes)); + VectorVariant(std::in_place_type, std::move(ioBundleName)); + VectorVariant(std::in_place_type, std::move(ioReadCharDiff)); + VectorVariant(std::in_place_type, std::move(ioSyscReadDiff)); + VectorVariant(std::in_place_type, std::move(ioReadBytesDiff)); + VectorVariant(std::in_place_type, std::move(ioSyscOpenDiff)); + VectorVariant(std::in_place_type, std::move(ioSyscStatDiff)); + VectorVariant(std::in_place_type, std::move(ioResult)); } template diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 8255d789a..aece8975d 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -145,7 +145,7 @@ bool CheckDouble(const std::string &value) } char *endptr; - std::strtod(value.c_str(), &emdptr); + std::strtod(value.c_str(), &endptr); return *endptr == '\0' || (std::isspace(*endptr) && endptr[1] == '\0'); } @@ -156,7 +156,7 @@ struct PushBackVisitor { void operator()(std::vector &vec) { PushField(value, vec); } -} +}; struct CheckVisitor { const std::string &value; @@ -174,7 +174,7 @@ struct CheckVisitor { checkType = true; } } -} +}; template HiSysEventParam CreateParam(const char *name, HiSysEventParamType type, std::vector &data) @@ -191,17 +191,17 @@ HiSysEventParam CreateParam(const char *name, HiSysEventParamType type, std::vec void IoMessageManager::Report() { - auto charIoBundleName = ConvertToCStringArray(getVector(targetVectors)); + auto charIoBundleName = ConvertToCStringArray(GetVector(targetVectors)); HiSysEventParam params[] = { - createParam("time", HISYSEVENT_INT32_ARRAY, getVector(targetVectors)), - createParam("BundleName", HISYSEVENT_STRING_ARRAY, charIoBundleName), - createParam("ReadCharDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), - createParam("SyscReadDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), - createParam("ReadBytesDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), - createParam("SyscOpenDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), - createParam("SyscStatDiff", HISYSEVENT_INT64_ARRAY, getVector(targetVectors)), - createParam("Result", HISYSEVENT_DOUBLE_ARRAY, getVector(targetVectors)), + CreateParam("time", HISYSEVENT_INT32_ARRAY, GetVector(targetVectors)), + CreateParam("BundleName", HISYSEVENT_STRING_ARRAY, charIoBundleName), + CreateParam("ReadCharDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), + CreateParam("SyscReadDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), + CreateParam("ReadBytesDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), + CreateParam("SyscOpenDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), + CreateParam("SyscStatDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), + CreateParam("Result", HISYSEVENT_DOUBLE_ARRAY, GetVector(targetVectors)), }; auto ret = OH_HiSysEvent_Write( @@ -229,15 +229,15 @@ void IoMessageManager::PushData(const vector &fields) } for (unsigned i = 0; i < fields.size(); ++i) { bool checkType = false; - CheckVisitor visitor(fields[i], checkType); - std::visit(visitor,targetVectors[i]); + CheckVisitor visitor{fields[i], checkType}; + std::visit(visitor, targetVectors[i]); if (!checkType) { LOGI("checkType failed. value = %{public}s", fields[i].c_str()); return; } } for (unsigned i = 0; i < fields.size(); ++i) { - PushBackVisitor visitor(fileds[i]); + PushBackVisitor visitor{fields[i]}; std::visit(visitor, targetVectors[i]); } return; @@ -293,11 +293,11 @@ void IoMessageManager::CheckMaxSizeAndReport() if (filesystem::exists(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME)) { LOGI("Report file exist"); } - std::error_code errcode; + std::error_code errCode; filesystem::rename(IO_DATA_FILE_PATH + IO_FILE_NAME, - IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME); - if (errcode.value() != 0) { - LOGE("Failed to rename file, error code: %{public}d", errcode.value()); + IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME, errCode); + if (errCode.value() != 0) { + LOGE("Failed to rename file, error code: %{public}d", errCode.value()); return; } if (!reportThreadRunning.load()) { -- Gitee From 2aed2c878b0661497e9326396b5de8c8aaff017a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 14:58:09 +0800 Subject: [PATCH 19/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 983900429..80c2cb144 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -93,15 +93,15 @@ private: DoubleVector ioResult; std::vector targetVectors = { - VectorVariant(std::in_place_type, std::move(ioTimes)); - VectorVariant(std::in_place_type, std::move(ioBundleName)); - VectorVariant(std::in_place_type, std::move(ioReadCharDiff)); - VectorVariant(std::in_place_type, std::move(ioSyscReadDiff)); - VectorVariant(std::in_place_type, std::move(ioReadBytesDiff)); - VectorVariant(std::in_place_type, std::move(ioSyscOpenDiff)); - VectorVariant(std::in_place_type, std::move(ioSyscStatDiff)); - VectorVariant(std::in_place_type, std::move(ioResult)); - } + VectorVariant(std::in_place_type, std::move(ioTimes)), + VectorVariant(std::in_place_type, std::move(ioBundleName)), + VectorVariant(std::in_place_type, std::move(ioReadCharDiff)), + VectorVariant(std::in_place_type, std::move(ioSyscReadDiff)), + VectorVariant(std::in_place_type, std::move(ioReadBytesDiff)), + VectorVariant(std::in_place_type, std::move(ioSyscOpenDiff)), + VectorVariant(std::in_place_type, std::move(ioSyscStatDiff)), + VectorVariant(std::in_place_type, std::move(ioResult)) + }; template T& GetVector(std::vector& targetVectors) { -- Gitee From b654b4fa02564a407b2fc728dd3b85af5e348eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 16:45:11 +0800 Subject: [PATCH 20/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 7 +++---- .../src/cloud_disk/io_message_listener.cpp | 21 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 80c2cb144..48413a8e6 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -24,6 +24,7 @@ #include "application_state_observer_stub.h" #include "common_event_subscriber.h" +#include "ffrt_inner.h" namespace OHOS { namespace FileManagement { @@ -73,10 +74,8 @@ private: std::string currentBundleName = ""; std::atomic isThreadRunning{false}; std::atomic reportThreadRunning{false}; - std::thread ioThread; - std::mutex sleepMutex; - std::mutex cvMute; - std::condition_variable sleepCv; + ffrt::mutex sleepMutex; + ffrt::condition_variable sleepCv; std::map bundleTimeMap; IoData currentData; IoData preData; diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index aece8975d..9aca03173 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -353,7 +353,7 @@ void IoMessageManager::RecordIoData() string path = "/proc/" + to_string(lastestAppStateData.pid) + "/sys_count"; ProcessIoData(path); } - unique_lock lock(sleepMutex); + unique_lock lock(sleepMutex); sleepCv.wait_for(lock, chrono::seconds(GET_FREQUENCY), [&] { return !isThreadRunning.load(); }); @@ -367,23 +367,18 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa } if (appStateData.state == TYPE_FRONT) { lastestAppStateData = appStateData; - if (!ioThread.joinable()) { + if (!isThreadRunning.load()) { isThreadRunning.store(true); - ffrt::submit([this] {RecordIoData();}, {}, {}, - ffrt::task_attr().qos(ffrt::qos_background)); + ffrt::submit([this] {RecordIoData();}, {}, {},ffrt::task_attr().qos(ffrt::qos_background)); } return; } if (appStateData.state == TYPE_BACKGROUND) { - if (ioThread.joinable()) { - lock_guard lock(cvMute); - isThreadRunning.store(false); - sleepCv.notify_all(); - ioThread.join(); - ioThread = thread(); - currentData = {}; - preData = {}; - } + lock_guard lock(sleepMutex); + isThreadRunning.store(false); + sleepCv.notify_all(); + currentData = {}; + preData = {}; } } } // namespace CloudDisk -- Gitee From 219ef9bd00ef56fd8c49adca875d0daa29e5a611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 16:46:10 +0800 Subject: [PATCH 21/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 9aca03173..f532dcd4d 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -15,7 +15,6 @@ #include "io_message_listener.h" #include "hisysevent.h" -#include "ffrt_inner.h" #include "utils_log.h" #include #include -- Gitee From b478747908699a05f001c5213f48ba95f93ff29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 16:59:02 +0800 Subject: [PATCH 22/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloud_disk/io_message_listener_test.cpp | 94 +++++++++++++++---- 1 file changed, 76 insertions(+), 18 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 63855f7da..7fc13fcb4 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1332,24 +1332,6 @@ HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) GTEST_LOG_(INFO) << "Report002 End"; } -/** - * @tc.name: PushDataRollBack001 - * @tc.desc: Report IO data - * @tc.type: FUNC - */ -HWTEST_F(IoMessageListenerTest, PushDataRollBack001, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "PushDataRollBack001 Start"; - try { - ioMessageManager_->PushDataRollBack(); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "PushDataRollBack001 ERROR"; - } - GTEST_LOG_(INFO) << "PushDataRollBack001 End"; -} - /** * @tc.name: PushData001 * @tc.desc: Report IO data @@ -1703,4 +1685,80 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport005, TestSize.Level1) GTEST_LOG_(INFO) << "CheckMaxSizeAndReport005 End"; } +/** + * @tc.name: CheckInt001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckInt001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckInt001 Start"; + + try { + CheckInt("1234"); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckInt001 ERROR"; + } + GTEST_LOG_(INFO) << "CheckInt001 End"; +} + +/** + * @tc.name: CheckInt002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckInt002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckInt002 Start"; + + try { + CheckInt("str"); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckInt002 ERROR"; + } + GTEST_LOG_(INFO) << "CheckInt001 End"; +} + +/** + * @tc.name: CheckDouble001 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckDouble001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckDouble001 Start"; + + try { + CheckDouble("1.0"); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckDouble001 ERROR"; + } + GTEST_LOG_(INFO) << "CheckInt001 End"; +} + +/** + * @tc.name: CheckDouble002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckDouble002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckDouble002 Start"; + + try { + CheckDouble("str"); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckDouble002 ERROR"; + } + GTEST_LOG_(INFO) << "CheckDouble002 End"; +} + } // namespace OHOS::FileManagement::CloudDisk::Test \ No newline at end of file -- Gitee From 3e7f241456f3ee27752f14482fb56ccbaf116a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 17:14:51 +0800 Subject: [PATCH 23/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 7fc13fcb4..b072eb238 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1695,7 +1695,7 @@ HWTEST_F(IoMessageListenerTest, CheckInt001, TestSize.Level1) GTEST_LOG_(INFO) << "CheckInt001 Start"; try { - CheckInt("1234"); + OHOS::FileManagement::CloudDisk::CheckInt("1234"); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1714,7 +1714,7 @@ HWTEST_F(IoMessageListenerTest, CheckInt002, TestSize.Level1) GTEST_LOG_(INFO) << "CheckInt002 Start"; try { - CheckInt("str"); + OHOS::FileManagement::CloudDisk::CheckInt("str"); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1733,7 +1733,7 @@ HWTEST_F(IoMessageListenerTest, CheckDouble001, TestSize.Level1) GTEST_LOG_(INFO) << "CheckDouble001 Start"; try { - CheckDouble("1.0"); + OHOS::FileManagement::CloudDisk::CheckDouble("1.0"); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); @@ -1752,7 +1752,7 @@ HWTEST_F(IoMessageListenerTest, CheckDouble002, TestSize.Level1) GTEST_LOG_(INFO) << "CheckDouble002 Start"; try { - CheckDouble("str"); + OHOS::FileManagement::CloudDisk::CheckDouble("str"); EXPECT_TRUE(true); } catch (...) { EXPECT_TRUE(false); -- Gitee From 28e55eb257d22ae87d45b4708503d2fd0f7c75ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 17:27:53 +0800 Subject: [PATCH 24/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/include/cloud_disk/io_message_listener.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 48413a8e6..990f73357 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -52,6 +52,8 @@ using Int32Vector = std::vector; using Int64Vector = std::vector; using StringVector = std::vector; using DoubleVector = std::vector; +bool CheckInt(const std::string &value); +bool CheckDouble(const std::string &value); enum class VectorIndex { IO_TIMES, -- Gitee From eb60a2c1b6a01ada0afdfc81f4defbe709ea9c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 11 Sep 2025 23:59:25 +0800 Subject: [PATCH 25/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../src/cloud_disk/io_message_listener.cpp | 20 +++++++++---------- .../cloudfiledaemon/src/ipc/cloud_daemon.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index f532dcd4d..f4483f024 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -31,14 +31,14 @@ const int32_t GET_FREQUENCY = 5; const int32_t READ_THRESHOLD = 1000; const int32_t OPEN_THRESHOLD = 1000; const int32_t STAT_THRESHOLD = 1000; -const int32_t MAX_RECORD_IN_FILE = 2400; const string IO_DATA_FILE_PATH = "/data/service/el1/public/cloudfile/io/"; const string IO_FILE_NAME = "io_message.csv"; const string IO_NEED_REPORT_PREFIX = "wait_report_"; const int32_t TYPE_FRONT = 2; const int32_t TYPE_BACKGROUND = 4; const int32_t MAX_IO_FILE_SIZE = 128 * 1024; -int32_t MAX_IO_REPORT_NUMBER = 100; +const size_t MAX_RECORD_IN_FILE = 10000; +const size_t MAX_IO_REPORT_NUMBER = 100; IoMessageManager &IoMessageManager::GetInstance() { @@ -176,12 +176,10 @@ struct CheckVisitor { }; template -HiSysEventParam CreateParam(const char *name, HiSysEventParamType type, std::vector &data) +HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, std::vector &data) { HiSysEventParam param; - size_t len = std::min(strlen(name), static_cast(MAX_LENGTH_OF_PARAM_NAME - 1)); - std::copy_n(name, len, param.name); - param.name[len] = '\0'; + strncpy_s(param.name, sizeof(param.name), name.c_str(), sizeof(name.c_str())); param.t = type; param.v.array = data.data(); param.arraySize = static_cast(data.size()); @@ -226,7 +224,7 @@ void IoMessageManager::PushData(const vector &fields) if (fields.size() != targetVectors.size()) { return; } - for (unsigned i = 0; i < fields.size(); ++i) { + for (uint32_t i = 0; i < fields.size(); ++i) { bool checkType = false; CheckVisitor visitor{fields[i], checkType}; std::visit(visitor, targetVectors[i]); @@ -235,7 +233,7 @@ void IoMessageManager::PushData(const vector &fields) return; } } - for (unsigned i = 0; i < fields.size(); ++i) { + for (uint32_t i = 0; i < fields.size(); ++i) { PushBackVisitor visitor{fields[i]}; std::visit(visitor, targetVectors[i]); } @@ -251,8 +249,8 @@ void IoMessageManager::ReadAndReportIoMessage() } string line; - int32_t reportCount = 0; - int32_t totalCount = 0; + size_t reportCount = 0; + size_t totalCount = 0; while (getline(localData, line)) { vector fields; istringstream iss(line); @@ -302,7 +300,7 @@ void IoMessageManager::CheckMaxSizeAndReport() if (!reportThreadRunning.load()) { reportThreadRunning.store(true); LOGI("Start report io data"); - ffrt::thread([this] {ReadAndReportIoMessage();}).detach(); + ffrt::submit([this] { ReadAndReportIoMessage(); }, {}, {}, ffrt::task_attr().qos(ffrt::qos_background)); } } diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index daa72089f..7db44a3f2 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -138,11 +138,11 @@ void CloudDaemon::OnStart() CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); return; } - try { - filesystem::create_directories(IO_MESSAGE_DIR); - } catch (const filesystem::filesystem_error& e) { + std::error_code errCode; + filesystem::create_directories(IO_MESSAGE_DIR, errCode); + if (error_code.value() != 0) { LOGE("Mkdir for io failed"); - return; + return; } CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); }); -- Gitee From c104b326acde6a556c2fe62f750f5029736d02e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 00:04:42 +0800 Subject: [PATCH 26/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index f4483f024..78780f468 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -14,10 +14,11 @@ */ #include "io_message_listener.h" +#include +#include #include "hisysevent.h" #include "utils_log.h" -#include -#include + using namespace std; using namespace chrono; -- Gitee From 8b63307ab6ed4272196b61266acd9a63078da6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 00:08:52 +0800 Subject: [PATCH 27/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 78780f468..fad46bb60 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -15,7 +15,7 @@ #include "io_message_listener.h" #include -#include +#include #include "hisysevent.h" #include "utils_log.h" @@ -144,8 +144,12 @@ bool CheckDouble(const std::string &value) return false; } + errno = 0; char *endptr; std::strtod(value.c_str(), &endptr); + if (errno != 0) { + return false; + } return *endptr == '\0' || (std::isspace(*endptr) && endptr[1] == '\0'); } -- Gitee From 716d56dafe28c8d70c758a7d6eaab11796c9967a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 00:17:30 +0800 Subject: [PATCH 28/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../src/cloud_disk/io_message_listener.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index fad46bb60..c6c64fb72 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -193,17 +193,30 @@ HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, st void IoMessageManager::Report() { + auto sizeVector = [](auto &vec) { + if (vec.szie() == 0) { + return; + } + } + for (auto &variant : targetVectors) { + std::visit(sizeVector, variant); + } auto charIoBundleName = ConvertToCStringArray(GetVector(targetVectors)); - HiSysEventParam params[] = { CreateParam("time", HISYSEVENT_INT32_ARRAY, GetVector(targetVectors)), CreateParam("BundleName", HISYSEVENT_STRING_ARRAY, charIoBundleName), - CreateParam("ReadCharDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), - CreateParam("SyscReadDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), - CreateParam("ReadBytesDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), - CreateParam("SyscOpenDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), - CreateParam("SyscStatDiff", HISYSEVENT_INT64_ARRAY, GetVector(targetVectors)), - CreateParam("Result", HISYSEVENT_DOUBLE_ARRAY, GetVector(targetVectors)), + CreateParam("ReadCharDiff", HISYSEVENT_INT64_ARRAY, + GetVector(targetVectors)), + CreateParam("SyscReadDiff", HISYSEVENT_INT64_ARRAY, + GetVector(targetVectors)), + CreateParam("ReadBytesDiff", HISYSEVENT_INT64_ARRAY, + GetVector(targetVectors)), + CreateParam("SyscOpenDiff", HISYSEVENT_INT64_ARRAY, + GetVector(targetVectors)), + CreateParam("SyscStatDiff", HISYSEVENT_INT64_ARRAY, + GetVector(targetVectors)), + CreateParam("Result", HISYSEVENT_DOUBLE_ARRAY, + GetVector(targetVectors)), }; auto ret = OH_HiSysEvent_Write( -- Gitee From 33bc3d13cf9da2471fed445c51e0ef3f66eb2604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 11:06:26 +0800 Subject: [PATCH 29/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index c6c64fb72..52d5aba04 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -194,7 +194,7 @@ HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, st void IoMessageManager::Report() { auto sizeVector = [](auto &vec) { - if (vec.szie() == 0) { + if (vec.size() == 0) { return; } } -- Gitee From 9df4252e8355ccddce9a9678d482c2b8e5f5a274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 11:31:13 +0800 Subject: [PATCH 30/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 52d5aba04..39bc78887 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -301,6 +301,10 @@ void IoMessageManager::ReadAndReportIoMessage() void IoMessageManager::CheckMaxSizeAndReport() { + if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME)) { + LOGI("Source file not exist"); + return; + } auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); if (fileSize < MAX_IO_FILE_SIZE) { return; -- Gitee From 4452e06cd6fc602da4c39eae1d56df602eb6279e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 11:37:20 +0800 Subject: [PATCH 31/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../include/cloud_disk/io_message_listener.h | 3 ++- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 6 +++--- services/cloudfiledaemon/src/ipc/cloud_daemon.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h index 990f73357..33268b2bb 100644 --- a/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h +++ b/services/cloudfiledaemon/include/cloud_disk/io_message_listener.h @@ -105,7 +105,8 @@ private: }; template - T& GetVector(std::vector& targetVectors) { + T& GetVector(std::vector& targetVectors) + { return std::get(targetVectors[static_cast(Index)]); } bool ReadIoDataFromFile(const std::string &path); diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 39bc78887..ccb4ae864 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -15,7 +15,6 @@ #include "io_message_listener.h" #include -#include #include "hisysevent.h" #include "utils_log.h" @@ -167,7 +166,8 @@ struct CheckVisitor { bool &checkType; template - void operator()(std::vector &vec) { + void operator()(std::vector &vec) + { if constexpr (std::is_same_v) { checkType = CheckInt(value); } else if constexpr (std::is_same_v) { @@ -388,7 +388,7 @@ void IoMessageManager::OnReceiveEvent(const AppExecFwk::AppStateData &appStateDa lastestAppStateData = appStateData; if (!isThreadRunning.load()) { isThreadRunning.store(true); - ffrt::submit([this] {RecordIoData();}, {}, {},ffrt::task_attr().qos(ffrt::qos_background)); + ffrt::submit([this] {RecordIoData();}, {}, {}, ffrt::task_attr().qos(ffrt::qos_background)); } return; } diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 7db44a3f2..1f5d1580b 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -142,7 +142,7 @@ void CloudDaemon::OnStart() filesystem::create_directories(IO_MESSAGE_DIR, errCode); if (error_code.value() != 0) { LOGE("Mkdir for io failed"); - return; + return; } CloudDisk::AppStateObserverManager::GetInstance().SubscribeAppState(bundleNameList); }); -- Gitee From 6c15bc66726654cb9f17a2116cd991dce526ccb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 11:47:06 +0800 Subject: [PATCH 32/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index ccb4ae864..0c1e5f4ef 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -184,6 +184,7 @@ template HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, std::vector &data) { HiSysEventParam param; + size_t count = std::min(name.size(), sizeof(param.name) - 1); strncpy_s(param.name, sizeof(param.name), name.c_str(), sizeof(name.c_str())); param.t = type; param.v.array = data.data(); -- Gitee From 110f9a3ed7af441159de19b5861a8177dfc1088d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 11:48:58 +0800 Subject: [PATCH 33/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 0c1e5f4ef..ebd9f64c6 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -185,7 +185,7 @@ HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, st { HiSysEventParam param; size_t count = std::min(name.size(), sizeof(param.name) - 1); - strncpy_s(param.name, sizeof(param.name), name.c_str(), sizeof(name.c_str())); + strncpy_s(param.name, sizeof(param.name), name.c_str(), count); param.t = type; param.v.array = data.data(); param.arraySize = static_cast(data.size()); -- Gitee From 24236785fa9aaf5afc318471a9d049a40b5c5451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 14:10:26 +0800 Subject: [PATCH 34/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 4 ++++ test/unittests/cloud_disk/io_message_listener_test.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index ebd9f64c6..7565dc916 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -302,6 +302,10 @@ void IoMessageManager::ReadAndReportIoMessage() void IoMessageManager::CheckMaxSizeAndReport() { + if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME)) { + LOGE("source file not exist"); + return; + } if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME)) { LOGI("Source file not exist"); return; diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index b072eb238..a728b269f 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1539,6 +1539,10 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport001, TestSize.Level1) if (filesystem::exists(IO_FILE)) { unlink(IO_FILE.c_str()); } + fd = open(IO_FILE.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644); + string line = "test,test,test,test,test,test,test,test\n"; + write(fd, line.c_str(), line.size()); + close(fd); ioMessageManager_->CheckMaxSizeAndReport(); EXPECT_TRUE(true); -- Gitee From e924fd1c1a444e5a8411c17d6ca42623bbdacbac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 16:13:26 +0800 Subject: [PATCH 35/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 7565dc916..fb12045d0 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -306,10 +306,6 @@ void IoMessageManager::CheckMaxSizeAndReport() LOGE("source file not exist"); return; } - if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME)) { - LOGI("Source file not exist"); - return; - } auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); if (fileSize < MAX_IO_FILE_SIZE) { return; -- Gitee From 82b925ce835cbc498b89c3fbf634543bb4528915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 16:31:25 +0800 Subject: [PATCH 36/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../src/cloud_disk/io_message_listener.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index fb12045d0..4f178ec52 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -18,7 +18,6 @@ #include "hisysevent.h" #include "utils_log.h" - using namespace std; using namespace chrono; @@ -185,7 +184,11 @@ HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, st { HiSysEventParam param; size_t count = std::min(name.size(), sizeof(param.name) - 1); - strncpy_s(param.name, sizeof(param.name), name.c_str(), count); + auto ret = strncpy_s(param.name, sizeof(param.name), name.c_str(), count); + if (ret != EOK) { + LOGE(HisysEventParam set failed); + param.name[0] = '\0'; + } param.t = type; param.v.array = data.data(); param.arraySize = static_cast(data.size()); @@ -198,7 +201,7 @@ void IoMessageManager::Report() if (vec.size() == 0) { return; } - } + }; for (auto &variant : targetVectors) { std::visit(sizeVector, variant); } @@ -302,18 +305,18 @@ void IoMessageManager::ReadAndReportIoMessage() void IoMessageManager::CheckMaxSizeAndReport() { - if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME)) { + std::error_code errCode; + if (!filesystem::exists(IO_DATA_FILE_PATH + IO_FILE_NAME, errCode) || errCode.value() != 0) { LOGE("source file not exist"); return; } - auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME); - if (fileSize < MAX_IO_FILE_SIZE) { + auto fileSize = filesystem::file_size(IO_DATA_FILE_PATH + IO_FILE_NAME, errCode); + if (fileSize < MAX_IO_FILE_SIZE || errCode.value() != 0) { return; } if (filesystem::exists(IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME)) { LOGI("Report file exist"); } - std::error_code errCode; filesystem::rename(IO_DATA_FILE_PATH + IO_FILE_NAME, IO_DATA_FILE_PATH + IO_NEED_REPORT_PREFIX + IO_FILE_NAME, errCode); if (errCode.value() != 0) { -- Gitee From 7aa9bc3138f5652730ccc66d83589ae7bd328e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 12 Sep 2025 16:46:20 +0800 Subject: [PATCH 37/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 4f178ec52..6bfbb902a 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -186,7 +186,7 @@ HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, st size_t count = std::min(name.size(), sizeof(param.name) - 1); auto ret = strncpy_s(param.name, sizeof(param.name), name.c_str(), count); if (ret != EOK) { - LOGE(HisysEventParam set failed); + LOGE("HisysEventParam set failed"); param.name[0] = '\0'; } param.t = type; -- Gitee From 1750529671a76d5974da89399283eb5fa3e36337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 10:27:06 +0800 Subject: [PATCH 38/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloudfiledaemon/src/cloud_disk/io_message_listener.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index 6bfbb902a..e7aa420d0 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -148,14 +148,15 @@ bool CheckDouble(const std::string &value) if (errno != 0) { return false; } - return *endptr == '\0' || (std::isspace(*endptr) && endptr[1] == '\0'); + return *endptr == '\0'; } struct PushBackVisitor { const std::string &value; template - void operator()(std::vector &vec) { + void operator()(std::vector &vec) + { PushField(value, vec); } }; -- Gitee From 5007468f456c29868c85d19911739418bb74cce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 11:30:40 +0800 Subject: [PATCH 39/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../src/cloud_disk/io_message_listener.cpp | 8 ++------ services/cloudfiledaemon/src/ipc/cloud_daemon.cpp | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp index e7aa420d0..3a1f3ed48 100644 --- a/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp +++ b/services/cloudfiledaemon/src/cloud_disk/io_message_listener.cpp @@ -184,12 +184,8 @@ template HiSysEventParam CreateParam(const std::string name, HiSysEventParamType type, std::vector &data) { HiSysEventParam param; - size_t count = std::min(name.size(), sizeof(param.name) - 1); - auto ret = strncpy_s(param.name, sizeof(param.name), name.c_str(), count); - if (ret != EOK) { - LOGE("HisysEventParam set failed"); - param.name[0] = '\0'; - } + std::copy(name.begin(), name.begin() + std::min(name.length(), sizeof(param.name) - 1), param.name); + param.name[sizeof(param.name) - 1] = '\0'; param.t = type; param.v.array = data.data(); param.arraySize = static_cast(data.size()); diff --git a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp index 1f5d1580b..cf0e3729f 100644 --- a/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp +++ b/services/cloudfiledaemon/src/ipc/cloud_daemon.cpp @@ -140,7 +140,7 @@ void CloudDaemon::OnStart() } std::error_code errCode; filesystem::create_directories(IO_MESSAGE_DIR, errCode); - if (error_code.value() != 0) { + if (errCode.value() != 0) { LOGE("Mkdir for io failed"); return; } -- Gitee From 4a5ca81621247a44abce99437de3dbb953501459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 12:13:00 +0800 Subject: [PATCH 40/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index a728b269f..1ce9cc69c 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1222,7 +1222,6 @@ HWTEST_F(IoMessageListenerTest, OnReceiveEventTest002, TestSize.Level1) AppExecFwk::AppStateData appStateData; appStateData.bundleName = ""; appStateData.state = FRONT_EVENT; - ioMessageManager_->ioThread =std::thread(); ioMessageManager_->OnReceiveEvent(appStateData); EXPECT_TRUE(true); } catch (...) { -- Gitee From 063ad337c02a545792571d0340fbfaac5ceeaa63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 12:14:49 +0800 Subject: [PATCH 41/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 1ce9cc69c..97880b993 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1542,7 +1542,6 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport001, TestSize.Level1) string line = "test,test,test,test,test,test,test,test\n"; write(fd, line.c_str(), line.size()); close(fd); - ioMessageManager_->CheckMaxSizeAndReport(); EXPECT_TRUE(true); } catch (...) { -- Gitee From 688c8802b5dcdde64af4ea206512c135334d3f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 12:21:39 +0800 Subject: [PATCH 42/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 97880b993..1ce9cc69c 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -1542,6 +1542,7 @@ HWTEST_F(IoMessageListenerTest, CheckMaxSizeAndReport001, TestSize.Level1) string line = "test,test,test,test,test,test,test,test\n"; write(fd, line.c_str(), line.size()); close(fd); + ioMessageManager_->CheckMaxSizeAndReport(); EXPECT_TRUE(true); } catch (...) { -- Gitee From ba4402957226f393b31cf03c6fc609b0e8ddd9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:11:35 +0800 Subject: [PATCH 43/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloud_disk/io_message_listener_test.cpp | 136 +++++++++++++++++- 1 file changed, 132 insertions(+), 4 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 1ce9cc69c..9d50ada8b 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -629,6 +629,26 @@ HWTEST_F(IoMessageListenerTest, RecordDataToFileTest003, TestSize.Level1) GTEST_LOG_(INFO) << "RecordDataToFileTest003 End"; } +/** + * @tc.name: RecordDataToFileTest004 + * @tc.desc: Read IO data + * @tc.type: FUNC + * @tc.require: issuesI92WQP + */ +HWTEST_F(IoMessageListenerTest, RecordDataToFileTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RecordDataToFileTest004 Start"; + string path = ""; + try { + ioMessageManager_->RecordDataToFile(path); + EXPECT_FALSE(false); + } catch (...) { + EXPECT_FALSE(true); + GTEST_LOG_(INFO) << "RecordDataToFileTest004 ERROR"; + } + GTEST_LOG_(INFO) << "RecordDataToFileTest004 End"; +} + /** * @tc.name: ProcessIoDataTest001 * @tc.desc: Read IO data @@ -1283,7 +1303,7 @@ HWTEST_F(IoMessageListenerTest, OnReceiveEventTest005, TestSize.Level1) HWTEST_F(IoMessageListenerTest, Report001, TestSize.Level1) { GTEST_LOG_(INFO) << "Report001 Start"; - for (int i = 0; i <= 101; i++) { + for (int i = 0; i <= FEWER_LOOP_COUNT; i++) { ioMessageManager_->ioTimes.push_back(1); ioMessageManager_->ioBundleName.push_back("tdd"); ioMessageManager_->ioReadCharDiff.push_back(1); @@ -1311,7 +1331,7 @@ HWTEST_F(IoMessageListenerTest, Report001, TestSize.Level1) HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) { GTEST_LOG_(INFO) << "Report002 Start"; - for (int i = 0; i <= FEWER_LOOP_COUNT; i++) { + for (int i = 0; i <= 10; i++) { ioMessageManager_->ioTimes.push_back(1); ioMessageManager_->ioBundleName.push_back("tdd"); ioMessageManager_->ioReadCharDiff.push_back(1); @@ -1331,6 +1351,24 @@ HWTEST_F(IoMessageListenerTest, Report002, TestSize.Level1) GTEST_LOG_(INFO) << "Report002 End"; } +/** + * @tc.name: Report003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, Report003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "Report003 Start"; + try { + ioMessageManager_->Report(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "Report003 ERROR"; + } + GTEST_LOG_(INFO) << "Report003 End"; +} + /** * @tc.name: PushData001 * @tc.desc: Report IO data @@ -1379,7 +1417,14 @@ HWTEST_F(IoMessageListenerTest, PushData003, TestSize.Level1) { GTEST_LOG_(INFO) << "PushData003 Start"; vector fields; - fields.push_back("tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd,tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); + fields.push_back("tdd"); try { ioMessageManager_->PushData(fields); EXPECT_TRUE(true); @@ -1390,6 +1435,33 @@ HWTEST_F(IoMessageListenerTest, PushData003, TestSize.Level1) GTEST_LOG_(INFO) << "PushData003 End"; } +/** + * @tc.name: PushData004 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, PushData004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PushData004 Start"; + vector fields; + fields.push_back(TEST_INT32); + fields.push_back("tdd"); + fields.push_back(TEST_INT64); + fields.push_back(TEST_INT64); + fields.push_back(TEST_INT64); + fields.push_back(TEST_INT64); + fields.push_back(TEST_INT64); + fields.push_back(TEST_DOUBLE); + try { + ioMessageManager_->PushData(fields); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PushData004 ERROR"; + } + GTEST_LOG_(INFO) << "PushData004 End"; +} + /** * @tc.name: ReadAndReportIoMessage001 * @tc.desc: Report IO data @@ -1723,7 +1795,26 @@ HWTEST_F(IoMessageListenerTest, CheckInt002, TestSize.Level1) EXPECT_TRUE(false); GTEST_LOG_(INFO) << "CheckInt002 ERROR"; } - GTEST_LOG_(INFO) << "CheckInt001 End"; + GTEST_LOG_(INFO) << "CheckInt002 End"; +} + +/** + * @tc.name: CheckInt003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckInt003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckInt003 Start"; + + try { + OHOS::FileManagement::CloudDisk::CheckInt(""); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckInt003 ERROR"; + } + GTEST_LOG_(INFO) << "CheckInt003 End"; } /** @@ -1764,4 +1855,41 @@ HWTEST_F(IoMessageListenerTest, CheckDouble002, TestSize.Level1) GTEST_LOG_(INFO) << "CheckDouble002 End"; } +/** + * @tc.name: CheckDouble003 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckDouble003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckDouble003 Start"; + + try { + OHOS::FileManagement::CloudDisk::CheckDouble(""); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckDouble003 ERROR"; + } + GTEST_LOG_(INFO) << "CheckDouble003 End"; +} + +/** + * @tc.name: CheckDouble002 + * @tc.desc: Report IO data + * @tc.type: FUNC + */ +HWTEST_F(IoMessageListenerTest, CheckDouble002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckDouble002 Start"; + + try { + OHOS::FileManagement::CloudDisk::CheckDouble("str"); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckDouble002 ERROR"; + } + GTEST_LOG_(INFO) << "CheckDouble002 End"; +} } // namespace OHOS::FileManagement::CloudDisk::Test \ No newline at end of file -- Gitee From 192632fdc23553e49c47ce05c5b42653dc54ea4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:18:11 +0800 Subject: [PATCH 44/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../cloud_disk/io_message_listener_test.cpp | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 9d50ada8b..45c761552 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -39,6 +39,9 @@ const int32_t THREAD_SLEEP_TIME = 100; const int32_t FRONT_EVENT = 2; const int32_t BACKGROUND_EVENT = 4; const int32_t UNKNOWN_EVENT = 8; +const string TEST_INT32 = "10000"; +const string TEST_INT64 = "20000"; +const string TEST_DOUBLE = "888.123" const int32_t LOOP_COUNT = 20000; const int32_t FEWER_LOOP_COUNT = 101; const string IO_REPORT_FILE = "/data/service/el1/public/cloudfile/io/wait_report_io_message.csv"; @@ -1361,9 +1364,9 @@ HWTEST_F(IoMessageListenerTest, Report003, TestSize.Level1) GTEST_LOG_(INFO) << "Report003 Start"; try { ioMessageManager_->Report(); - EXPECT_TRUE(true); + EXPECT_FALSE(false); } catch (...) { - EXPECT_TRUE(false); + EXPECT_FALSE(true); GTEST_LOG_(INFO) << "Report003 ERROR"; } GTEST_LOG_(INFO) << "Report003 End"; @@ -1874,22 +1877,4 @@ HWTEST_F(IoMessageListenerTest, CheckDouble003, TestSize.Level1) GTEST_LOG_(INFO) << "CheckDouble003 End"; } -/** - * @tc.name: CheckDouble002 - * @tc.desc: Report IO data - * @tc.type: FUNC - */ -HWTEST_F(IoMessageListenerTest, CheckDouble002, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "CheckDouble002 Start"; - - try { - OHOS::FileManagement::CloudDisk::CheckDouble("str"); - EXPECT_TRUE(true); - } catch (...) { - EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "CheckDouble002 ERROR"; - } - GTEST_LOG_(INFO) << "CheckDouble002 End"; -} } // namespace OHOS::FileManagement::CloudDisk::Test \ No newline at end of file -- Gitee From 4c58c06164933f29949a04ab4b1c8fea3e445914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:19:26 +0800 Subject: [PATCH 45/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/cloud_disk/io_message_listener_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittests/cloud_disk/io_message_listener_test.cpp b/test/unittests/cloud_disk/io_message_listener_test.cpp index 45c761552..a6c14b6e9 100644 --- a/test/unittests/cloud_disk/io_message_listener_test.cpp +++ b/test/unittests/cloud_disk/io_message_listener_test.cpp @@ -39,9 +39,9 @@ const int32_t THREAD_SLEEP_TIME = 100; const int32_t FRONT_EVENT = 2; const int32_t BACKGROUND_EVENT = 4; const int32_t UNKNOWN_EVENT = 8; -const string TEST_INT32 = "10000"; -const string TEST_INT64 = "20000"; -const string TEST_DOUBLE = "888.123" +const string TEST_INT32 = "100000"; +const string TEST_INT64 = "200000"; +const string TEST_DOUBLE = "888.123"; const int32_t LOOP_COUNT = 20000; const int32_t FEWER_LOOP_COUNT = 101; const string IO_REPORT_FILE = "/data/service/el1/public/cloudfile/io/wait_report_io_message.csv"; -- Gitee From 8aed85b5b00adcc5124c2f2312b9ffa0c93cf7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:40:58 +0800 Subject: [PATCH 46/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../services_daemon/cloud_daemon_test.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/unittests/services_daemon/cloud_daemon_test.cpp b/test/unittests/services_daemon/cloud_daemon_test.cpp index 2bb192508..a1ff47fd8 100644 --- a/test/unittests/services_daemon/cloud_daemon_test.cpp +++ b/test/unittests/services_daemon/cloud_daemon_test.cpp @@ -30,7 +30,7 @@ using namespace testing; using namespace testing::ext; constexpr int32_t USER_ID = 100; constexpr int32_t DEV_FD = 10; - +const string IO_MESSAGE_DIR = "/data/service/el1/public/cloudfile/io/" class CloudDaemonTest : public testing::Test { public: static void SetUpTestCase(void); @@ -134,6 +134,30 @@ HWTEST_F(CloudDaemonTest, OnStartTest2, TestSize.Level1) GTEST_LOG_(INFO) << "OnStart2 End"; } +/** + * @tc.name: OnStartTest3 + * @tc.desc: Verify the OnStart function + * @tc.type: FUNC + * @tc.require: I6H5MH + */ +HWTEST_F(CloudDaemonTest, OnStartTest3, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnStart3 Start"; + try { + cloudDaemon_->state_ = ServiceRunningState::STATE_NOT_START; + cloudDaemon_->registerToService_ = true; + if (filesystem::exists(IO_MESSAGE_DIR)) { + filesystem::remove(IO_MESSAGE_DIR); + } + cloudDaemon_->OnStart(); + EXPECT_TRUE(true); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "OnStart3 ERROR"; + } + GTEST_LOG_(INFO) << "OnStart3 End"; +} + /** * @tc.name: StartFuseTest001 * @tc.desc: Verify the StartFuse function -- Gitee From f9faa5fbad9f21ed4332648ce30126771b951f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:41:56 +0800 Subject: [PATCH 47/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/services_daemon/cloud_daemon_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittests/services_daemon/cloud_daemon_test.cpp b/test/unittests/services_daemon/cloud_daemon_test.cpp index a1ff47fd8..bf9e41097 100644 --- a/test/unittests/services_daemon/cloud_daemon_test.cpp +++ b/test/unittests/services_daemon/cloud_daemon_test.cpp @@ -31,6 +31,7 @@ using namespace testing::ext; constexpr int32_t USER_ID = 100; constexpr int32_t DEV_FD = 10; const string IO_MESSAGE_DIR = "/data/service/el1/public/cloudfile/io/" + class CloudDaemonTest : public testing::Test { public: static void SetUpTestCase(void); -- Gitee From 74a8368ef83bbe0e3b5a77666e69a190bf9366ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 13 Sep 2025 18:42:46 +0800 Subject: [PATCH 48/48] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- test/unittests/services_daemon/cloud_daemon_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittests/services_daemon/cloud_daemon_test.cpp b/test/unittests/services_daemon/cloud_daemon_test.cpp index bf9e41097..f4baaa7cc 100644 --- a/test/unittests/services_daemon/cloud_daemon_test.cpp +++ b/test/unittests/services_daemon/cloud_daemon_test.cpp @@ -30,7 +30,7 @@ using namespace testing; using namespace testing::ext; constexpr int32_t USER_ID = 100; constexpr int32_t DEV_FD = 10; -const string IO_MESSAGE_DIR = "/data/service/el1/public/cloudfile/io/" +const string IO_MESSAGE_DIR = "/data/service/el1/public/cloudfile/io/"; class CloudDaemonTest : public testing::Test { public: -- Gitee