• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "reporter_impl.h"
17 
18 #include "behaviour/behaviour_reporter_impl.h"
19 #include "fault/cloud_sync_fault_impl.h"
20 #include "fault/communication_fault_impl.h"
21 #include "fault/database_fault_impl.h"
22 #include "fault/runtime_fault_impl.h"
23 #include "fault/service_fault_impl.h"
24 #include "statistic/api_performance_statistic_impl.h"
25 #include "statistic/database_statistic_impl.h"
26 #include "statistic/traffic_statistic_impl.h"
27 #include "statistic/visit_statistic_impl.h"
28 
29 namespace OHOS {
30 namespace DistributedDataDfx {
31 __attribute__((used)) static bool g_isInit = ReporterImpl::Init();
Init()32 bool ReporterImpl::Init()
33 {
34     static ReporterImpl reporterImpl;
35     static std::once_flag onceFlag;
36     std::call_once(onceFlag, [&]() {
37         Reporter::RegisterReporterInstance(&reporterImpl);
38     });
39     return true;
40 }
41 
CommunicationFault()42 FaultReporter* ReporterImpl::CommunicationFault()
43 {
44     static CommunicationFaultImpl communicationFault;
45     communicationFault.SetThreadPool(executors_);
46     return &communicationFault;
47 }
48 
DatabaseFault()49 FaultReporter* ReporterImpl::DatabaseFault()
50 {
51     static DatabaseFaultImpl databaseFault;
52     databaseFault.SetThreadPool(executors_);
53     return &databaseFault;
54 }
55 
RuntimeFault()56 FaultReporter* ReporterImpl::RuntimeFault()
57 {
58     static RuntimeFaultImpl runtimeFault;
59     runtimeFault.SetThreadPool(executors_);
60     return &runtimeFault;
61 }
62 
CloudSyncFault()63 FaultReporter* ReporterImpl::CloudSyncFault()
64 {
65     static CloudSyncFaultImpl cloudSyncFault;
66     cloudSyncFault.SetThreadPool(executors_);
67     return &cloudSyncFault;
68 }
69 
ServiceFault()70 FaultReporter* ReporterImpl::ServiceFault()
71 {
72     static ServiceFaultImpl serviceFault;
73     serviceFault.SetThreadPool(executors_);
74     return &serviceFault;
75 }
76 
TrafficStatistic()77 StatisticReporter<TrafficStat>* ReporterImpl::TrafficStatistic()
78 {
79     static TrafficStatisticImpl trafficStatistic;
80     trafficStatistic.SetThreadPool(executors_);
81     return &trafficStatistic;
82 }
83 
VisitStatistic()84 StatisticReporter<struct VisitStat>* ReporterImpl::VisitStatistic()
85 {
86     static VisitStatisticImpl visitStatistic;
87     visitStatistic.SetThreadPool(executors_);
88     return &visitStatistic;
89 }
90 
DatabaseStatistic()91 StatisticReporter<struct DbStat>* ReporterImpl::DatabaseStatistic()
92 {
93     static DatabaseStatisticImpl databaseStatistic;
94     databaseStatistic.SetThreadPool(executors_);
95     return &databaseStatistic;
96 }
97 
ApiPerformanceStatistic()98 StatisticReporter<ApiPerformanceStat>* ReporterImpl::ApiPerformanceStatistic()
99 {
100     static ApiPerformanceStatisticImpl apiPerformanceStat;
101     apiPerformanceStat.SetThreadPool(executors_);
102     return &apiPerformanceStat;
103 }
104 
GetBehaviourReporter()105 BehaviourReporter* ReporterImpl::GetBehaviourReporter()
106 {
107     static BehaviourReporterImpl behaviourReporterImpl;
108     behaviourReporterImpl.SetThreadPool(executors_);
109     return &behaviourReporterImpl;
110 }
111 
SetThreadPool(std::shared_ptr<ExecutorPool> executors)112 void ReporterImpl::SetThreadPool(std::shared_ptr<ExecutorPool> executors)
113 {
114     executors_ = executors;
115     if (executors != nullptr) {
116         ServiceFault();
117         RuntimeFault();
118         DatabaseFault();
119         CloudSyncFault();
120         CommunicationFault();
121         DatabaseStatistic();
122         VisitStatistic();
123         TrafficStatistic();
124         ApiPerformanceStatistic();
125         GetBehaviourReporter();
126     }
127 }
128 } // namespace DistributedDataDfx
129 } // namespace OHOS
130