1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DISTRIBUTEDDATAMGR_HI_VIEW_ADAPTER_H 17 #define DISTRIBUTEDDATAMGR_HI_VIEW_ADAPTER_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "dfx_code_constant.h" 23 #include "dfx/dfx_types.h" 24 #include "executor_pool.h" 25 #include "hisysevent_c.h" 26 #include "value_hash.h" 27 28 namespace OHOS { 29 namespace DistributedDataDfx { 30 template<typename T> 31 struct StatisticWrap { 32 T val; 33 int times; 34 int code; 35 }; 36 37 class HiViewAdapter { 38 public: 39 ~HiViewAdapter(); 40 static void ReportFault(int dfxCode, const FaultMsg &msg, std::shared_ptr<ExecutorPool> executors); 41 static void ReportDBFault(int dfxCode, const DBFaultMsg &msg, std::shared_ptr<ExecutorPool> executors); 42 static void ReportCommFault(int dfxCode, const CommFaultMsg &msg, std::shared_ptr<ExecutorPool> executors); 43 static void ReportArkDataFault(int dfxCode, const ArkDataFaultMsg &msg, std::shared_ptr<ExecutorPool> executors); 44 static void ReportVisitStatistic(int dfxCode, const VisitStat &stat, std::shared_ptr<ExecutorPool> executors); 45 static void ReportTrafficStatistic(int dfxCode, const TrafficStat &stat, std::shared_ptr<ExecutorPool> executors); 46 static void ReportDatabaseStatistic(int dfxCode, const DbStat &stat, std::shared_ptr<ExecutorPool> executors); 47 static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat, 48 std::shared_ptr<ExecutorPool> executors); 49 static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors); 50 static void ReportUdmfBehaviour(int dfxCode, const UdmfBehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors); 51 static void StartTimerThread(std::shared_ptr<ExecutorPool> executors); 52 53 private: 54 static std::mutex visitMutex_; 55 static std::map<std::string, StatisticWrap<VisitStat>> visitStat_; 56 static void InvokeVisit(); 57 58 static std::mutex trafficMutex_; 59 static std::map<std::string, StatisticWrap<TrafficStat>> trafficStat_; 60 static void InvokeTraffic(); 61 62 static std::mutex dbMutex_; 63 static std::map<std::string, StatisticWrap<DbStat>> dbStat_; 64 static void InvokeDbSize(); 65 static void ReportDbSize(const StatisticWrap<DbStat> &stat); 66 67 static std::mutex apiPerformanceMutex_; 68 static std::map<std::string, StatisticWrap<ApiPerformanceStat>> apiPerformanceStat_; 69 static void InvokeApiPerformance(); 70 71 static std::string CoverEventID(int dfxCode); 72 private: 73 static std::mutex runMutex_; 74 static bool running_; 75 static const inline int DAILY_REPORT_TIME = 23; 76 static const inline int WAIT_TIME = 1 * 60 * 60; // 1 hours 77 }; 78 } // namespace DistributedDataDfx 79 } // namespace OHOS 80 #endif // DISTRIBUTEDDATAMGR_HI_VIEW_ADAPTER_H