• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #include "handler_checker.h"
17 #include "ipc_skeleton.h"
18 #include "xcollie_utils.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
ScheduleCheck()22 void HandlerChecker::ScheduleCheck()
23 {
24     if (!isCompleted_ || handler_ == nullptr) {
25         return;
26     }
27     if (name_.compare(IPC_FULL) == 0) {
28         auto fb = [] {
29             IPCDfx::BlockUntilThreadAvailable();
30         };
31         if (!handler_->PostTask(fb, "IpcCheck Task", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) {
32             XCOLLIE_LOGE("XCollie IpcCheck Task PostTask failed.");
33         }
34     }
35 
36     isCompleted_.store(false);
37     auto f = [this] () {
38         this->isCompleted_.store(true);
39     };
40     if (!handler_->PostTask(f, "XCollie Watchdog Task", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) {
41         XCOLLIE_LOGE("XCollie Watchdog Task PostTask False.");
42     }
43 }
44 
GetCheckState()45 int HandlerChecker::GetCheckState()
46 {
47     if (isCompleted_) {
48         taskSlow = false;
49         return CheckStatus::COMPLETED;
50     } else {
51         if (!taskSlow) {
52             taskSlow = true;
53             return CheckStatus::WAITED_HALF;
54         } else {
55             return CheckStatus::WAITING;
56         }
57     }
58 }
59 
GetDumpInfo()60 std::string HandlerChecker::GetDumpInfo()
61 {
62     std::string ret;
63     if (handler_ != nullptr) {
64         HandlerDumper handlerDumper;
65         handler_->Dump(handlerDumper);
66         ret = handlerDumper.GetDumpInfo();
67     }
68     return ret;
69 }
70 
71 
GetHandler() const72 std::shared_ptr<AppExecFwk::EventHandler> HandlerChecker::GetHandler() const
73 {
74     return handler_;
75 }
76 
Dump(const std::string & message)77 void HandlerDumper::Dump(const std::string &message)
78 {
79     XCOLLIE_LOGD("message is %{public}s", message.c_str());
80     dumpInfo_ += message;
81 }
82 
GetTag()83 std::string HandlerDumper::GetTag()
84 {
85     return "";
86 }
87 
GetDumpInfo()88 std::string HandlerDumper::GetDumpInfo()
89 {
90     return dumpInfo_;
91 }
92 } // end of namespace HiviewDFX
93 } // end of namespace OHOS
94