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_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 ReportVisitStatistic(int dfxCode, const VisitStat &stat, std::shared_ptr<ExecutorPool> executors); 44 static void ReportTrafficStatistic(int dfxCode, const TrafficStat &stat, std::shared_ptr<ExecutorPool> executors); 45 static void ReportDatabaseStatistic(int dfxCode, const DbStat &stat, std::shared_ptr<ExecutorPool> executors); 46 static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat, 47 std::shared_ptr<ExecutorPool> executors); 48 static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors); 49 static void ReportUdmfBehaviour(int dfxCode, const UdmfBehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors); 50 static void StartTimerThread(std::shared_ptr<ExecutorPool> executors); 51 52 private: 53 static std::mutex visitMutex_; 54 static std::map<std::string, StatisticWrap<VisitStat>> visitStat_; 55 static void InvokeVisit(); 56 57 static std::mutex trafficMutex_; 58 static std::map<std::string, StatisticWrap<TrafficStat>> trafficStat_; 59 static void InvokeTraffic(); 60 61 static std::mutex dbMutex_; 62 static std::map<std::string, StatisticWrap<DbStat>> dbStat_; 63 static void InvokeDbSize(); 64 static void ReportDbSize(const StatisticWrap<DbStat> &stat); 65 66 static std::mutex apiPerformanceMutex_; 67 static std::map<std::string, StatisticWrap<ApiPerformanceStat>> apiPerformanceStat_; 68 static void InvokeApiPerformance(); 69 70 static std::string CoverEventID(int dfxCode); 71 private: 72 static std::mutex runMutex_; 73 static bool running_; 74 static const inline int DAILY_REPORT_TIME = 23; 75 static const inline int WAIT_TIME = 1 * 60 * 60; // 1 hours 76 }; 77 } // namespace DistributedDataDfx 78 } // namespace OHOS 79 #endif // DISTRIBUTEDDATAMGR_HI_VIEW_ADAPTER_H