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 #include "dump_event_handler.h"
16 #include "util/dump_cpu_info_util.h"
17 #include "dump_manager_cpu_service.h"
18 #include "hilog_wrapper.h"
19 namespace OHOS {
20 namespace HiviewDFX {
21 const int DumpEventHandler::MSG_GET_CPU_INFO_ID = 1;
22 const int DumpEventHandler::GET_CPU_INFO_DELAY_TIME_INIT = 5 * 1000;
23 const int DumpEventHandler::GET_CPU_INFO_DELAY_TIME = 60 * 1000;
24
DumpEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner,const wptr<DumpManagerCpuService> & service)25 DumpEventHandler::DumpEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner,
26 const wptr<DumpManagerCpuService>& service)
27 : AppExecFwk::EventHandler(runner), service_(service)
28 {
29 }
30
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)31 void DumpEventHandler::ProcessEvent([[maybe_unused]] const AppExecFwk::InnerEvent::Pointer& event)
32 {
33 auto dmsptr = service_.promote();
34 if (dmsptr == nullptr) {
35 DUMPER_HILOGE(MODULE_CPU_SERVICE, "service is nullptr!");
36 return;
37 }
38 if (event == nullptr) {
39 DUMPER_HILOGE(MODULE_CPU_SERVICE, "event is nullptr!");
40 return;
41 }
42 auto eventId = event->GetInnerEventId();
43 DUMPER_HILOGI(MODULE_CPU_SERVICE, "debug|eventId=%{public}d", eventId);
44 switch (eventId) {
45 case MSG_GET_CPU_INFO_ID: {
46 DumpCpuInfoUtil::GetInstance().UpdateCpuInfo();
47 (dmsptr->GetHandler())->RemoveAllEvents();
48 (dmsptr->GetHandler())->SendEvent(MSG_GET_CPU_INFO_ID, GET_CPU_INFO_DELAY_TIME);
49 break;
50 }
51 default:
52 break;
53 }
54 }
55 } // namespace HiviewDFX
56 } // namespace OHOS
57