• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "hiview_event_report.h"
16 
17 #include "hiview_event_common.h"
18 #include "hiview_event_cacher.h"
19 #include "logger.h"
20 #include "plugin_fault_event_factory.h"
21 #include "plugin_load_event_factory.h"
22 #include "plugin_unload_event_factory.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 DEFINE_LOG_LABEL(LABEL_DOMAIN, "HiView-HiviewEventReport");
ReportPluginLoad(const std::string & name,uint32_t result)27 void HiviewEventReport::ReportPluginLoad(const std::string &name, uint32_t result)
28 {
29     auto factory = std::make_unique<PluginLoadEventFactory>();
30     auto event = factory->Create();
31     event->Update(PluginEventSpace::KEY_OF_PLUGIN_NAME, name);
32     event->Update(PluginEventSpace::KEY_OF_RESULT, result);
33     event->Report();
34     HIVIEW_LOGI("report plugin load event=%{public}s", event->ToJsonString().c_str());
35 }
36 
ReportPluginUnload(const std::string & name,uint32_t result)37 void HiviewEventReport::ReportPluginUnload(const std::string &name, uint32_t result)
38 {
39     auto factory = std::make_unique<PluginUnloadEventFactory>();
40     auto event = factory->Create();
41     event->Update(PluginEventSpace::KEY_OF_PLUGIN_NAME, name);
42     event->Update(PluginEventSpace::KEY_OF_RESULT, result);
43     event->Report();
44     HIVIEW_LOGI("report plugin unload event=%{public}s", event->ToJsonString().c_str());
45 }
46 
ReportPluginFault(const std::string & name,const std::string & reason)47 void HiviewEventReport::ReportPluginFault(const std::string &name, const std::string &reason)
48 {
49     auto factory = std::make_unique<PluginFaultEventFactory>();
50     auto event = factory->Create();
51     event->Update(PluginFaultEventSpace::KEY_OF_PLUGIN_NAME, name);
52     event->Update(PluginFaultEventSpace::KEY_OF_REASON, reason);
53     event->Report();
54     HIVIEW_LOGI("report plugin fault event=%{public}s", event->ToJsonString().c_str());
55 }
56 
ReportPluginStats()57 void HiviewEventReport::ReportPluginStats()
58 {
59     std::vector<std::shared_ptr<LoggerEvent>> events;
60     HiviewEventCacher::GetInstance().GetPluginStatsEvents(events);
61     for (auto event : events) {
62         event->Report();
63         HIVIEW_LOGI("report plugin stat event=%{public}s", event->ToJsonString().c_str());
64     }
65     HiviewEventCacher::GetInstance().ClearPluginStatsEvents();
66 }
67 
UpdatePluginStats(const std::string & name,const std::string & procName,uint32_t procTime)68 void HiviewEventReport::UpdatePluginStats(const std::string &name, const std::string &procName, uint32_t procTime)
69 {
70     HIVIEW_LOGD("UpdatePluginStats pluginName=%{public}s, procName=%{public}s, time=%{public}d",
71         name.c_str(), procName.c_str(), procTime);
72     HiviewEventCacher::GetInstance().UpdatePluginStatsEvent(name, procName, procTime);
73 }
74 } // namespace HiviewDFX
75 } // namespace OHOS
76