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 "hilog/log.h"
18 #include "hiview_event_common.h"
19 #include "hiview_event_cacher.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 namespace {
27 const HiLogLabel LABEL = { LOG_CORE, LABEL_DOMAIN, "HiView-HiviewEventReport" };
28 }
29
ReportPluginLoad(const std::string & name,uint32_t result)30 void HiviewEventReport::ReportPluginLoad(const std::string &name, uint32_t result)
31 {
32 auto factory = std::make_unique<PluginLoadEventFactory>();
33 auto event = factory->Create();
34 event->Update(PluginEventSpace::KEY_OF_PLUGIN_NAME, name);
35 event->Update(PluginEventSpace::KEY_OF_RESULT, result);
36 event->Report();
37 HiLog::Info(LABEL, "report plugin load event=%{public}s", event->ToJsonString().c_str());
38 }
39
ReportPluginUnload(const std::string & name,uint32_t result)40 void HiviewEventReport::ReportPluginUnload(const std::string &name, uint32_t result)
41 {
42 auto factory = std::make_unique<PluginUnloadEventFactory>();
43 auto event = factory->Create();
44 event->Update(PluginEventSpace::KEY_OF_PLUGIN_NAME, name);
45 event->Update(PluginEventSpace::KEY_OF_RESULT, result);
46 event->Report();
47 HiLog::Info(LABEL, "report plugin unload event=%{public}s", event->ToJsonString().c_str());
48 }
49
ReportPluginFault(const std::string & name,const std::string & reason)50 void HiviewEventReport::ReportPluginFault(const std::string &name, const std::string &reason)
51 {
52 auto factory = std::make_unique<PluginFaultEventFactory>();
53 auto event = factory->Create();
54 event->Update(PluginFaultEventSpace::KEY_OF_PLUGIN_NAME, name);
55 event->Update(PluginFaultEventSpace::KEY_OF_REASON, reason);
56 event->Report();
57 HiLog::Info(LABEL, "report plugin fault event=%{public}s", event->ToJsonString().c_str());
58 }
59
ReportPluginStats()60 void HiviewEventReport::ReportPluginStats()
61 {
62 std::vector<std::shared_ptr<LoggerEvent>> events;
63 HiviewEventCacher::GetInstance().GetPluginStatsEvents(events);
64 for (auto event : events) {
65 event->Report();
66 HiLog::Info(LABEL, "report plugin stat event=%{public}s", event->ToJsonString().c_str());
67 }
68 HiviewEventCacher::GetInstance().ClearPluginStatsEvents();
69 }
70
UpdatePluginStats(const std::string & name,const std::string & procName,uint32_t procTime)71 void HiviewEventReport::UpdatePluginStats(const std::string &name, const std::string &procName, uint32_t procTime)
72 {
73 HiLog::Debug(LABEL, "UpdatePluginStats pluginName=%{public}s, procName=%{public}s, time=%{public}d",
74 name.c_str(), procName.c_str(), procTime);
75 HiviewEventCacher::GetInstance().UpdatePluginStatsEvent(name, procName, procTime);
76 }
77 } // namespace HiviewDFX
78 } // namespace OHOS
79