• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "dfx_types.h"
22 #include "dfx_code_constant.h"
23 #include "hisysevent.h"
24 #include "task_scheduler.h"
25 #include "kv_store_thread_pool.h"
26 #include "kv_store_task.h"
27 #include "value_hash.h"
28 
29 namespace OHOS {
30 namespace DistributedDataDfx {
31 template<typename T>
32 struct StatisticWrap {
33     T val;
34     int times;
35     int code;
36 };
37 
38 class HiViewAdapter {
39 public:
40     ~HiViewAdapter();
41     static void ReportFault(int dfxCode, const FaultMsg &msg);
42     static void ReportDBFault(int dfxCode, const DBFaultMsg &msg);
43     static void ReportCommFault(int dfxCode, const CommFaultMsg &msg);
44     static void ReportVisitStatistic(int dfxCode, const VisitStat &stat);
45     static void ReportTrafficStatistic(int dfxCode, const TrafficStat &stat);
46     static void ReportDatabaseStatistic(int dfxCode, const DbStat &stat);
47     static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat);
48     static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg);
49     static void StartTimerThread();
50 
51 private:
52     static constexpr int POOL_SIZE = 3;
53     static std::shared_ptr<DistributedKv::KvStoreThreadPool> pool_;
54 
55     static std::mutex visitMutex_;
56     static std::map<std::string, StatisticWrap<VisitStat>> visitStat_;
57     static void InvokeVisit();
58 
59     static std::mutex trafficMutex_;
60     static std::map<std::string, StatisticWrap<TrafficStat>> trafficStat_;
61     static void InvokeTraffic();
62 
63     static std::mutex dbMutex_;
64     static std::map<std::string, StatisticWrap<DbStat>> dbStat_;
65     static void InvokeDbSize();
66     static void ReportDbSize(const StatisticWrap<DbStat> &stat);
67 
68     static std::mutex apiPerformanceMutex_;
69     static std::map<std::string, StatisticWrap<ApiPerformanceStat>> apiPerformanceStat_;
70     static void InvokeApiPerformance();
71 
72     static std::string CoverEventID(int dfxCode);
73 private:
74     static std::mutex runMutex_;
75     static bool running_;
76     static TaskScheduler scheduler_;
77     static const inline int DAILY_REPORT_TIME = 23;
78     static const inline int WAIT_TIME = 1 * 60 * 60; // 1 hours
79 };
80 }  // namespace DistributedDataDfx
81 }  // namespace OHOS
82 #endif // DISTRIBUTEDDATAMGR_HI_VIEW_ADAPTER_H
83