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 #define LOG_TAG "HiViewAdapter"
17 
18 #include "hiview_adapter.h"
19 #include <thread>
20 #include <unistd.h>
21 #include "log_print.h"
22 
23 namespace OHOS {
24 namespace DistributedDataDfx {
25 using namespace DistributedKv;
26 namespace {
27 constexpr const char *DATAMGR_DOMAIN = "DISTDATAMGR";
28 // fault key
29 constexpr const char *FAULT_TYPE = "FAULT_TYPE";
30 constexpr const char *MODULE_NAME = "MODULE_NAME";
31 constexpr const char *INTERFACE_NAME = "INTERFACE_NAME";
32 constexpr const char *ERROR_TYPE = "ERROR_TYPE";
33 constexpr const char *SYNC_ERROR_INFO = "SYNC_ERROR_INFO";
34 // Database statistic
35 constexpr const char *USER_ID = "ANONYMOUS_UID";
36 constexpr const char *APP_ID = "APP_ID";
37 constexpr const char *STORE_ID = "STORE_ID";
38 constexpr const char *DB_SIZE = "DB_SIZE";
39 // interface visit statistic
40 constexpr const char *TIMES = "TIMES";
41 constexpr const char *DEVICE_ID = "ANONYMOUS_DID";
42 constexpr const char *SEND_SIZE = "SEND_SIZE";
43 constexpr const char *RECEIVED_SIZE = "RECEIVED_SIZE";
44 constexpr const char *AVERAGE_TIMES = "AVERAGE_TIME";
45 constexpr const char *WORST_TIMES = "WORST_TIME";
46 constexpr const char *INTERFACES = "INTERFACES";
47 constexpr const char *TAG = "TAG";
48 constexpr const char *POWERSTATS = "PowerStats";
49 // behaviour key
50 constexpr const char *BEHAVIOUR_INFO = "BEHAVIOUR_INFO";
51 constexpr const char *CHANNEL = "CHANNEL";
52 constexpr const char *DATA_SIZE = "DATA_SIZE";
53 constexpr const char *DATA_TYPE = "DATA_TYPE";
54 constexpr const char *OPERATION = "OPERATION";
55 constexpr const char *RESULT = "RESULT";
56 
57 const std::map<int, std::string> EVENT_COVERT_TABLE = {
58     { DfxCodeConstant::SERVICE_FAULT, "SERVICE_FAULT" },
59     { DfxCodeConstant::RUNTIME_FAULT, "RUNTIME_FAULT" },
60     { DfxCodeConstant::DATABASE_FAULT, "DATABASE_FAULT" },
61     { DfxCodeConstant::COMMUNICATION_FAULT, "COMMUNICATION_FAULT" },
62     { DfxCodeConstant::DATABASE_STATISTIC, "DATABASE_STATISTIC}" },
63     { DfxCodeConstant::VISIT_STATISTIC, "VISIT_STATISTIC" },
64     { DfxCodeConstant::TRAFFIC_STATISTIC, "VISIT_STATISTIC" },
65     { DfxCodeConstant::DATABASE_PERFORMANCE_STATISTIC, "DATABASE_PERFORMANCE_STATISTIC" },
66     { DfxCodeConstant::API_PERFORMANCE_STATISTIC, "API_PERFORMANCE_STATISTIC" },
67     { DfxCodeConstant::API_PERFORMANCE_INTERFACE, "API_PERFORMANCE_STATISTIC" },
68     { DfxCodeConstant::DATABASE_SYNC_FAILED, "DATABASE_SYNC_FAILED" },
69     { DfxCodeConstant::DATABASE_CORRUPTED_FAILED, "DATABASE_CORRUPTED_FAILED" },
70     { DfxCodeConstant::DATABASE_REKEY_FAILED, "DATABASE_REKEY_FAILED" },
71     { DfxCodeConstant::DATABASE_BEHAVIOUR, "DATABASE_BEHAVIOUR" },
72     { DfxCodeConstant::UDMF_DATA_BEHAVIOR, "UDMF_DATA_BEHAVIOR" },
73 };
74 }
75 std::mutex HiViewAdapter::visitMutex_;
76 std::map<std::string, StatisticWrap<VisitStat>> HiViewAdapter::visitStat_;
77 
78 std::mutex HiViewAdapter::trafficMutex_;
79 std::map<std::string, StatisticWrap<TrafficStat>> HiViewAdapter::trafficStat_;
80 
81 std::mutex HiViewAdapter::dbMutex_;
82 std::map<std::string, StatisticWrap<DbStat>> HiViewAdapter::dbStat_;
83 
84 std::mutex HiViewAdapter::apiPerformanceMutex_;
85 std::map<std::string, StatisticWrap<ApiPerformanceStat>> HiViewAdapter::apiPerformanceStat_;
86 
87 bool HiViewAdapter::running_ = false;
88 std::mutex HiViewAdapter::runMutex_;
89 
ReportFault(int dfxCode,const FaultMsg & msg,std::shared_ptr<ExecutorPool> executors)90 void HiViewAdapter::ReportFault(int dfxCode, const FaultMsg &msg, std::shared_ptr<ExecutorPool> executors)
91 {
92     ExecutorPool::Task task([dfxCode, msg]() {
93         struct HiSysEventParam params[] = {
94             { .name = { *FAULT_TYPE },
95                 .t = HISYSEVENT_INT32,
96                 .v = { .i32 = static_cast<int32_t>(msg.faultType) },
97                 .arraySize = 0 },
98             { .name = { *MODULE_NAME },
99                 .t = HISYSEVENT_STRING,
100                 .v = { .s = const_cast<char *>(msg.moduleName.c_str()) },
101                 .arraySize = 0 },
102             { .name = { *INTERFACE_NAME },
103                 .t = HISYSEVENT_STRING,
104                 .v = { .s = const_cast<char *>(msg.interfaceName.c_str()) },
105                 .arraySize = 0 },
106             { .name = { *ERROR_TYPE },
107                 .t = HISYSEVENT_INT32,
108                 .v = { .i32 = static_cast<int32_t>(msg.errorType) },
109                 .arraySize = 0 },
110         };
111         OH_HiSysEvent_Write(
112             DATAMGR_DOMAIN,
113             CoverEventID(dfxCode).c_str(),
114             HISYSEVENT_FAULT,
115             params,
116             sizeof(params) / sizeof(params[0])
117         );
118     });
119     executors->Execute(std::move(task));
120 }
121 
ReportDBFault(int dfxCode,const DBFaultMsg & msg,std::shared_ptr<ExecutorPool> executors)122 void HiViewAdapter::ReportDBFault(int dfxCode, const DBFaultMsg &msg, std::shared_ptr<ExecutorPool> executors)
123 {
124     ExecutorPool::Task task([dfxCode, msg]() {
125         struct HiSysEventParam params[] = {
126             { .name = { *APP_ID },
127                 .t = HISYSEVENT_STRING,
128                 .v = { .s = const_cast<char *>(msg.appId.c_str()) },
129                 .arraySize = 0 },
130             { .name = { *STORE_ID },
131                 .t = HISYSEVENT_STRING,
132                 .v = { .s = const_cast<char *>(msg.storeId.c_str()) },
133                 .arraySize = 0 },
134             { .name = { *MODULE_NAME },
135                 .t = HISYSEVENT_STRING,
136                 .v = { .s = const_cast<char *>(msg.moduleName.c_str()) },
137                 .arraySize = 0 },
138             { .name = { *ERROR_TYPE },
139                 .t = HISYSEVENT_INT32,
140                 .v = { .i32 = static_cast<int32_t>(msg.errorType) },
141                 .arraySize = 0 },
142         };
143         OH_HiSysEvent_Write(
144             DATAMGR_DOMAIN,
145             CoverEventID(dfxCode).c_str(),
146             HISYSEVENT_FAULT,
147             params,
148             sizeof(params) / sizeof(params[0])
149         );
150     });
151     executors->Execute(std::move(task));
152 }
153 
ReportCommFault(int dfxCode,const CommFaultMsg & msg,std::shared_ptr<ExecutorPool> executors)154 void HiViewAdapter::ReportCommFault(int dfxCode, const CommFaultMsg &msg, std::shared_ptr<ExecutorPool> executors)
155 {
156     ExecutorPool ::Task task([dfxCode, msg]() {
157         std::string message;
158         for (size_t i = 0; i < msg.deviceId.size(); i++) {
159             message.append("No: ").append(std::to_string(i))
160                 .append(" sync to device: ").append(msg.deviceId[i])
161                 .append(" has error, errCode:").append(std::to_string(msg.errorCode[i])).append(". ");
162         }
163         struct HiSysEventParam params[] = {
164             { .name = { *USER_ID },
165                 .t = HISYSEVENT_STRING,
166                 .v = { .s = const_cast<char *>(msg.userId.c_str()) },
167                 .arraySize = 0 },
168             { .name = { *APP_ID },
169                 .t = HISYSEVENT_STRING,
170                 .v = { .s = const_cast<char *>(msg.appId.c_str()) },
171                 .arraySize = 0 },
172             { .name = { *STORE_ID },
173                 .t = HISYSEVENT_STRING,
174                 .v = { .s = const_cast<char *>(msg.storeId.c_str()) },
175                 .arraySize = 0 },
176             { .name = { *SYNC_ERROR_INFO },
177                 .t = HISYSEVENT_STRING,
178                 .v = { .s = const_cast<char *>(message.c_str()) },
179                 .arraySize = 0 },
180         };
181         OH_HiSysEvent_Write(
182             DATAMGR_DOMAIN,
183             CoverEventID(dfxCode).c_str(),
184             HISYSEVENT_FAULT,
185             params,
186             sizeof(params) / sizeof(params[0])
187         );
188     });
189     executors->Execute(std::move(task));
190 }
191 
ReportBehaviour(int dfxCode,const BehaviourMsg & msg,std::shared_ptr<ExecutorPool> executors)192 void HiViewAdapter::ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors)
193 {
194     ExecutorPool::Task task([dfxCode, msg]() {
195         std::string message;
196         message.append("Behaviour type : ").append(std::to_string(static_cast<int>(msg.behaviourType)))
197             .append(" behaviour info : ").append(msg.extensionInfo);
198         struct HiSysEventParam params[] = {
199             { .name = { *USER_ID },
200                 .t = HISYSEVENT_STRING,
201                 .v = { .s = const_cast<char *>(msg.userId.c_str()) },
202                 .arraySize = 0 },
203             { .name = { *APP_ID },
204                 .t = HISYSEVENT_STRING,
205                 .v = { .s = const_cast<char *>(msg.appId.c_str()) },
206                 .arraySize = 0 },
207             { .name = { *STORE_ID },
208                 .t = HISYSEVENT_STRING,
209                 .v = { .s = const_cast<char *>(msg.storeId.c_str()) },
210                 .arraySize = 0 },
211             { .name = { *BEHAVIOUR_INFO },
212                 .t = HISYSEVENT_STRING,
213                 .v = { .s = const_cast<char *>(message.c_str()) },
214                 .arraySize = 0 },
215         };
216         OH_HiSysEvent_Write(
217             DATAMGR_DOMAIN,
218             CoverEventID(dfxCode).c_str(),
219             HISYSEVENT_BEHAVIOR,
220             params,
221             sizeof(params) / sizeof(params[0])
222         );
223     });
224     executors->Execute(std::move(task));
225 }
226 
ReportDatabaseStatistic(int dfxCode,const DbStat & stat,std::shared_ptr<ExecutorPool> executors)227 void HiViewAdapter::ReportDatabaseStatistic(int dfxCode, const DbStat &stat, std::shared_ptr<ExecutorPool> executors)
228 {
229     ExecutorPool::Task task([dfxCode, stat]() {
230         std::lock_guard<std::mutex> lock(dbMutex_);
231         if (!dbStat_.count(stat.GetKey())) {
232             dbStat_.insert({stat.GetKey(), {stat, 0, dfxCode}});
233         }
234     });
235     executors->Execute(std::move(task));
236     StartTimerThread(executors);
237 }
238 
ReportDbSize(const StatisticWrap<DbStat> & stat)239 void HiViewAdapter::ReportDbSize(const StatisticWrap<DbStat> &stat)
240 {
241     uint64_t dbSize;
242     if (!stat.val.delegate->GetKvStoreDiskSize(stat.val.storeId, dbSize)) {
243         return;
244     }
245 
246     ValueHash vh;
247     std::string userId;
248     if (!vh.CalcValueHash(stat.val.userId, userId)) {
249         return;
250     }
251 
252     struct HiSysEventParam params[] = {
253         { .name = { *USER_ID },
254             .t = HISYSEVENT_STRING,
255             .v = { .s = const_cast<char *>(userId.c_str()) },
256             .arraySize = 0 },
257         { .name = { *APP_ID },
258             .t = HISYSEVENT_STRING,
259             .v = { .s = const_cast<char *>(stat.val.appId.c_str()) },
260             .arraySize = 0 },
261         { .name = { *STORE_ID },
262             .t = HISYSEVENT_STRING,
263             .v = { .s = const_cast<char *>(stat.val.storeId.c_str()) },
264             .arraySize = 0 },
265         { .name = { *DB_SIZE }, .t = HISYSEVENT_UINT64, .v = { .ui64 = dbSize }, .arraySize = 0 },
266     };
267     OH_HiSysEvent_Write(
268         DATAMGR_DOMAIN,
269         CoverEventID(stat.code).c_str(),
270         HISYSEVENT_STATISTIC,
271         params,
272         sizeof(params) / sizeof(params[0])
273     );
274 }
275 
InvokeDbSize()276 void HiViewAdapter::InvokeDbSize()
277 {
278     std::lock_guard<std::mutex> lock(dbMutex_);
279     for (auto const &kv : dbStat_) {
280         if (kv.second.val.delegate == nullptr) {
281             continue;
282         }
283         // device coordinate for single version database
284         if (!kv.second.val.storeId.empty()) {
285             ReportDbSize(kv.second);
286             continue;
287         }
288         // below codes for multiple version database
289         std::vector<StoreInfo> storeInfos;
290         kv.second.val.delegate->GetKvStoreKeys(storeInfos);
291         if (storeInfos.empty()) {
292             continue;
293         }
294         for (auto const &storeInfo : storeInfos) {
295             ReportDbSize({{storeInfo.userId, storeInfo.appId, storeInfo.storeId, 0,
296                 kv.second.val.delegate}, 0, kv.second.code});
297         }
298     }
299     dbStat_.clear();
300 }
301 
ReportTrafficStatistic(int dfxCode,const TrafficStat & stat,std::shared_ptr<ExecutorPool> executors)302 void HiViewAdapter::ReportTrafficStatistic(int dfxCode, const TrafficStat &stat,
303     std::shared_ptr<ExecutorPool> executors)
304 {
305     ExecutorPool::Task task([dfxCode, stat]() {
306         std::lock_guard<std::mutex> lock(trafficMutex_);
307         auto it = trafficStat_.find(stat.GetKey());
308         if (it != trafficStat_.end()) {
309             it->second.val.receivedSize += stat.receivedSize;
310             it->second.val.sendSize += stat.sendSize;
311         } else {
312             trafficStat_.insert({stat.GetKey(), {stat, 0, dfxCode}});
313         }
314     });
315     executors->Execute(std::move(task));
316     StartTimerThread(executors);
317 }
318 
InvokeTraffic()319 void HiViewAdapter::InvokeTraffic()
320 {
321     std::lock_guard<std::mutex> lock(trafficMutex_);
322     ValueHash vh;
323     for (auto const &kv : trafficStat_) {
324         std::string deviceId;
325         if (!vh.CalcValueHash(kv.second.val.deviceId, deviceId)) {
326             continue;
327         }
328         struct HiSysEventParam params[] = {
329             { .name = { *TAG }, .t = HISYSEVENT_STRING, .v = { .s = const_cast<char *>(POWERSTATS) }, .arraySize = 0 },
330             { .name = { *APP_ID },
331                 .t = HISYSEVENT_STRING,
332                 .v = { .s = const_cast<char *>(kv.second.val.appId.c_str()) },
333                 .arraySize = 0 },
334             { .name = { *DEVICE_ID },
335                 .t = HISYSEVENT_STRING,
336                 .v = { .s = const_cast<char *>(deviceId.c_str()) },
337                 .arraySize = 0 },
338             { .name = { *SEND_SIZE },
339                 .t = HISYSEVENT_INT64,
340                 .v = { .i64 = static_cast<int64_t>(kv.second.val.sendSize) },
341                 .arraySize = 0 },
342             { .name = { *RECEIVED_SIZE },
343                 .t = HISYSEVENT_INT64,
344                 .v = { .i64 = static_cast<int64_t>(kv.second.val.receivedSize) },
345                 .arraySize = 0 },
346         };
347         OH_HiSysEvent_Write(
348             DATAMGR_DOMAIN,
349             CoverEventID(kv.second.code).c_str(),
350             HISYSEVENT_STATISTIC,
351             params,
352             sizeof(params) / sizeof(params[0])
353         );
354     }
355     trafficStat_.clear();
356 }
357 
ReportVisitStatistic(int dfxCode,const VisitStat & stat,std::shared_ptr<ExecutorPool> executors)358 void HiViewAdapter::ReportVisitStatistic(int dfxCode, const VisitStat &stat, std::shared_ptr<ExecutorPool> executors)
359 {
360     ExecutorPool::Task task([dfxCode, stat]() {
361         std::lock_guard<std::mutex> lock(visitMutex_);
362         auto it = visitStat_.find(stat.GetKey());
363         if (it == visitStat_.end()) {
364             visitStat_.insert({stat.GetKey(), {stat, 1, dfxCode}});
365         } else {
366             it->second.times++;
367         }
368     });
369     executors->Execute(std::move(task));
370     StartTimerThread(executors);
371 }
372 
InvokeVisit()373 void HiViewAdapter::InvokeVisit()
374 {
375     std::lock_guard<std::mutex> lock(visitMutex_);
376     for (auto const &kv : visitStat_) {
377         struct HiSysEventParam params[] = {
378             { .name = { *TAG },
379                 .t = HISYSEVENT_STRING,
380                 .v = { .s = const_cast<char *>(POWERSTATS) },
381                 .arraySize = 0 },
382             { .name = { *APP_ID },
383                 .t = HISYSEVENT_STRING,
384                 .v = { .s = const_cast<char *>(kv.second.val.appId.c_str()) },
385                 .arraySize = 0 },
386             { .name = { *INTERFACE_NAME },
387                 .t = HISYSEVENT_STRING,
388                 .v = { .s = const_cast<char *>(kv.second.val.interfaceName.c_str()) },
389                 .arraySize = 0 },
390             { .name = { *BEHAVIOUR_INFO },
391                 .t = HISYSEVENT_INT64,
392                 .v = { .i64 = static_cast<int64_t>(kv.second.times) },
393                 .arraySize = 0 },
394         };
395         OH_HiSysEvent_Write(
396             DATAMGR_DOMAIN,
397             CoverEventID(kv.second.code).c_str(),
398             HISYSEVENT_STATISTIC,
399             params,
400             sizeof(params) / sizeof(params[0])
401         );
402     }
403     visitStat_.clear();
404 }
405 
ReportApiPerformanceStatistic(int dfxCode,const ApiPerformanceStat & stat,std::shared_ptr<ExecutorPool> executors)406 void HiViewAdapter::ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat,
407     std::shared_ptr<ExecutorPool> executors)
408 {
409     ExecutorPool::Task task([dfxCode, stat]() {
410         std::lock_guard<std::mutex> lock(apiPerformanceMutex_);
411         auto it = apiPerformanceStat_.find(stat.GetKey());
412         if (it == apiPerformanceStat_.end()) {
413             apiPerformanceStat_.insert({stat.GetKey(), {stat, 1, dfxCode}}); // the init value of times is 1
414         } else {
415             it->second.times++;
416             it->second.val.costTime = stat.costTime;
417             if (it->second.times > 0) {
418                 it->second.val.averageTime =
419                     (it->second.val.averageTime * static_cast<uint64_t>(it->second.times - 1) + stat.costTime)
420                     / it->second.times;
421             }
422             if (stat.costTime > it->second.val.worstTime) {
423                 it->second.val.worstTime = stat.costTime;
424             }
425         }
426     });
427 
428     executors->Execute(std::move(task));
429     StartTimerThread(executors);
430 }
431 
ReportUdmfBehaviour(int dfxCode,const UdmfBehaviourMsg & msg,std::shared_ptr<ExecutorPool> executors)432 void HiViewAdapter::ReportUdmfBehaviour(
433     int dfxCode, const UdmfBehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors)
434 {
435     if (executors == nullptr) {
436         ZLOGI("report udmf behavior failed");
437         return;
438     }
439     ExecutorPool::Task task([dfxCode, msg]() {
440         struct HiSysEventParam params[] = {
441             { .name = { *APP_ID },
442                 .t = HISYSEVENT_STRING,
443                 .v = { .s = const_cast<char *>(msg.appId.c_str()) },
444                 .arraySize = 0 },
445             { .name = { *CHANNEL },
446                 .t = HISYSEVENT_STRING,
447                 .v = { .s = const_cast<char *>(msg.channel.c_str()) },
448                 .arraySize = 0 },
449             { .name = { *DATA_SIZE },
450                 .t = HISYSEVENT_INT64,
451                 .v = { .i64 = msg.dataSize },
452                 .arraySize = 0 },
453             { .name = { *DATA_TYPE },
454                 .t = HISYSEVENT_STRING,
455                 .v = { .s = const_cast<char *>(msg.dataType.c_str()) },
456                 .arraySize = 0 },
457             { .name = { *OPERATION },
458                 .t = HISYSEVENT_STRING,
459                 .v = { .s = const_cast<char *>(msg.operation.c_str()) },
460                 .arraySize = 0 },
461             { .name = { *RESULT },
462                 .t = HISYSEVENT_STRING,
463                 .v = { .s = const_cast<char *>(msg.result.c_str()) },
464                 .arraySize = 0 },
465         };
466         OH_HiSysEvent_Write(
467             DATAMGR_DOMAIN,
468             CoverEventID(dfxCode).c_str(),
469             HISYSEVENT_BEHAVIOR,
470             params,
471             sizeof(params) / sizeof(params[0])
472         );
473     });
474     executors->Execute(std::move(task));
475 }
476 
InvokeApiPerformance()477 void HiViewAdapter::InvokeApiPerformance()
478 {
479     std::string message;
480     message.append("[");
481     std::lock_guard<std::mutex> lock(apiPerformanceMutex_);
482     for (auto const &kv : apiPerformanceStat_) {
483         message.append("{\"CODE\":\"").append(std::to_string(kv.second.code)).append("\",")
484             .append("\"").append(INTERFACE_NAME).append("\":\"").append(kv.second.val.interfaceName).append("\",")
485             .append("\"").append(TIMES).append("\":").append(std::to_string(kv.second.times)).append(",")
486             .append("\"").append(AVERAGE_TIMES).append("\":").append(std::to_string(kv.second.val.averageTime))
487             .append(",").append("\"").append(WORST_TIMES).append("\":").append(std::to_string(kv.second.val.worstTime))
488             .append("}");
489     }
490     message.append("]");
491     struct HiSysEventParam params[] = {
492         { .name = { *INTERFACES },
493             .t = HISYSEVENT_STRING,
494             .v = { .s = const_cast<char *>(message.c_str()) },
495             .arraySize = 0 },
496     };
497     OH_HiSysEvent_Write(
498         DATAMGR_DOMAIN,
499         CoverEventID(DfxCodeConstant::API_PERFORMANCE_STATISTIC).c_str(),
500         HISYSEVENT_STATISTIC,
501         params,
502         sizeof(params) / sizeof(params[0])
503     );
504     apiPerformanceStat_.clear();
505     ZLOGI("DdsTrace interface: clean");
506 }
507 
StartTimerThread(std::shared_ptr<ExecutorPool> executors)508 void HiViewAdapter::StartTimerThread(std::shared_ptr<ExecutorPool> executors)
509 {
510     if (running_) {
511         return;
512     }
513     std::lock_guard<std::mutex> lock(runMutex_);
514     if (running_) {
515         return;
516     }
517     running_ = true;
518     auto interval = std::chrono::seconds(WAIT_TIME);
519     auto fun = []() {
520         time_t current = time(nullptr);
521         tm localTime = { 0 };
522         tm *result = localtime_r(&current, &localTime);
523         if ((result != nullptr) && (localTime.tm_hour == DAILY_REPORT_TIME)) {
524             InvokeDbSize();
525             InvokeApiPerformance();
526         }
527         InvokeTraffic();
528         InvokeVisit();
529     };
530     executors->Schedule(fun, interval);
531 }
532 
CoverEventID(int dfxCode)533 std::string HiViewAdapter::CoverEventID(int dfxCode)
534 {
535     std::string sysEventID;
536     auto operatorIter = EVENT_COVERT_TABLE.find(dfxCode);
537     if (operatorIter != EVENT_COVERT_TABLE.end()) {
538         sysEventID = operatorIter->second;
539     }
540     return sysEventID;
541 }
542 } // namespace DistributedDataDfx
543 } // namespace OHOS