diff --git a/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp b/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d2eed066fdf9fdf406dbd75279026440d3d1181 --- /dev/null +++ b/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cloud_file_log.h" +#include "cloud_file_fault_event.h" +#include "dfs_error.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudFile { + +int32_t CloudFileFaultEvent::CloudSyncFaultReport(const std::string &funcName, + const int lineNum, + const CloudSyncFaultInfo &event) +{ + int32_t ret = CLOUD_SYNC_SYS_EVENT("CLOUD_FILE_SYNC_FAULT", + HiviewDFX::HiSysEvent::EventType::FAULT, + "bundle_name", event.bundleName_, + "fault_scenario", static_cast(event.faultScenario_), + "fault_type", static_cast(event.faultType_), + "fault_error_code", event.faultErrorCode_, + "function_name", funcName + ":" + std::to_string(lineNum), + "message", event.message_); + if (ret != E_OK) { + LOGE("report CLOUD_FILE_SYNC_FAULT error %{public}d", ret); + } + LOGE("%{public}s", event.message_.c_str()); + return event.faultErrorCode_; +} + +int32_t CloudFileFaultEvent::CloudFileFaultReport(const std::string &funcName, + const int lineNum, + const CloudFileFaultInfo &event) +{ + int32_t ret = CLOUD_SYNC_SYS_EVENT("CLOUD_FILE_ACCESS_FAULT", + HiviewDFX::HiSysEvent::EventType::FAULT, + "bundle_name", event.bundleName_, + "fault_operation", static_cast(event.faultOperation_), + "fault_type", static_cast(event.faultType_), + "fault_error_code", event.faultErrorCode_, + "function_name", funcName + ":" + std::to_string(lineNum), + "message", event.message_); + if (ret != E_OK) { + LOGE("report CLOUD_FILE_ACCESS_FAULT error %{public}d", ret); + } + LOGE("%{public}s", event.message_.c_str()); + return event.faultErrorCode_; +} +} // namespace CloudFile +} // namespace FileManagement +} // namespace OHOS diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/BUILD.gn b/interfaces/inner_api/native/cloud_file_kit_inner/BUILD.gn index 241ed5b50785d71eeb2e9118ddb58b8eb06ce4fb..4a2c632a6ec21ef0a48309b53259a9bb67ffa5d8 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/cloud_file_kit_inner/BUILD.gn @@ -49,7 +49,10 @@ ohos_shared_library("cloudfile_kit") { debug = false } - big_data_statistics = [ "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/gallery_download_file_stat.cpp" ] + big_data_statistics = [ + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/gallery_download_file_stat.cpp", + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp", + ] data_sync = [ "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/data_sync/data_syncer_rdb_store.cpp", diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics/cloud_file_fault_event.h b/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics/cloud_file_fault_event.h index 56477d04f26b86a3e0dfda7528e05c33bc30216a..d8db11d4d9c1b2f1870f49f1ca39f88862646b9e 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics/cloud_file_fault_event.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics/cloud_file_fault_event.h @@ -15,34 +15,22 @@ #ifndef OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H #define OHOS_CLOUD_SYNC_SERVICE_CLOUD_FILE_FAULT_EVENT_H -#include "cloud_file_log.h" #include "hisysevent.h" -#define CLOUD_SYNC_FAULT_REPORT(...) CloudFile::CloudSyncFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__) -#define CLOUD_FILE_FAULT_REPORT(...) CloudFile::CloudFileFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__) +#define CLOUD_SYNC_FAULT_REPORT(...) \ + CloudFile::CloudFileFaultEvent::CloudSyncFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__) +#define CLOUD_FILE_FAULT_REPORT(...) \ + CloudFile::CloudFileFaultEvent::CloudFileFaultReport(__FUNCTION__, __LINE__, ##__VA_ARGS__) namespace OHOS { namespace FileManagement { namespace CloudFile { + +#ifndef CLOUD_SYNC_SYS_EVENT #define CLOUD_SYNC_SYS_EVENT(eventName, type, ...) \ HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, eventName, type, \ ##__VA_ARGS__) - -struct CloudSyncFaultEvent { - std::string bundleName_; - uint32_t faultScenario_; - uint32_t faultType_; - int32_t faultErrorCode_; - std::string message_; -}; - -struct CloudFileFaultEvent { - std::string bundleName_; - uint32_t faultOperation_; - uint32_t faultType_; - int32_t faultErrorCode_; - std::string message_; -}; +#endif enum class FaultScenarioCode { CLOUD_FULL_SYNC = 100, @@ -109,44 +97,32 @@ enum class FaultType { PROCESS = 70000000 }; -int32_t CloudSyncFaultReport(const std::string &funcName, - const int lineNum, - const CloudSyncFaultEvent &event) -{ - int32_t ret = CLOUD_SYNC_SYS_EVENT("CLOUD_FILE_SYNC_FAULT", - HiviewDFX::HiSysEvent::EventType::FAULT, - "bundle_name", event.bundleName_, - "fault_scenario", event.faultScenario_, - "fault_type", event.faultType_, - "fault_error_code", event.faultErrorCode_, - "function_name", funcName + ":" + std::to_string(lineNum), - "message", event.message_); - if (ret != E_OK) { - LOGE("report CLOUD_FILE_SYNC_FAULT error %{public}d", ret); - } - LOGE("%{public}s", event.message_.c_str()); - return event.faultErrorCode_; -} - -int32_t CloudFileFaultReport(const std::string &funcName, - const int lineNum, - const CloudFileFaultEvent &event) -{ - int32_t ret = CLOUD_SYNC_SYS_EVENT("CLOUD_FILE_ACCESS_FAULT", - HiviewDFX::HiSysEvent::EventType::FAULT, - "bundle_name", event.bundleName_, - "fault_operation", event.faultOperation_, - "fault_type", event.faultType_, - "fault_error_code", event.faultErrorCode_, - "function_name", funcName + ":" + std::to_string(lineNum), - "message", event.message_); - if (ret != E_OK) { - LOGE("report CLOUD_FILE_ACCESS_FAULT error %{public}d", ret); - } - LOGE("%{public}s", event.message_.c_str()); - return event.faultErrorCode_; -} +struct CloudSyncFaultInfo { + std::string bundleName_; + FaultScenarioCode faultScenario_; + FaultType faultType_; + int32_t faultErrorCode_; + std::string message_; +}; +struct CloudFileFaultInfo { + std::string bundleName_; + FaultOperation faultOperation_; + FaultType faultType_; + int32_t faultErrorCode_; + std::string message_; +}; + +class CloudFileFaultEvent { +public: + static int32_t CloudSyncFaultReport(const std::string &funcName, + const int lineNum, + const CloudSyncFaultInfo &event); + + static int32_t CloudFileFaultReport(const std::string &funcName, + const int lineNum, + const CloudFileFaultInfo &event); +}; } // namespace CloudFile } // namespace FileManagement } // namespace OHOS