• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef RELIABILITY_HANDLER_CHECKER_H
17 #define RELIABILITY_HANDLER_CHECKER_H
18 
19 #include <atomic>
20 #include <string>
21 
22 #include "dumper.h"
23 #include "event_handler.h"
24 #include "xcollie_define.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 enum CheckStatus {
29     COMPLETED = 0,
30     WAITING = 1,
31     WAITED_HALF = 2,
32 };
33 
34 class HandlerChecker : public std::enable_shared_from_this<HandlerChecker> {
35 public:
HandlerChecker(std::string name,std::shared_ptr<AppExecFwk::EventHandler> handler)36     HandlerChecker(std::string name, std::shared_ptr<AppExecFwk::EventHandler> handler)
37         : name_(name), handler_(handler)
38     {
39         if (name == IPC_FULL_TASK && handler == nullptr) {
40             auto runner = AppExecFwk::EventRunner::Create(name);
41             handler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
42         }
43     };
~HandlerChecker()44     ~HandlerChecker() {};
45 
46 public:
47     void ScheduleCheck();
48     int GetCheckState();
49     std::shared_ptr<AppExecFwk::EventHandler> GetHandler() const;
50     std::string GetDumpInfo();
51 
52 private:
53     std::string name_;
54     std::shared_ptr<AppExecFwk::EventHandler> handler_;
55     std::atomic<bool> isCompleted_ = true;
56     bool taskSlow_ = false;
57 };
58 
59 class HandlerDumper : public AppExecFwk::Dumper {
60 public:
61     void Dump(const std::string &message) override;
62     std::string GetTag() override;
63     std::string GetDumpInfo();
64 private:
65     std::string dumpInfo_;
66 };
67 } // end of namespace HiviewDFX
68 } // end of namespace OHOS
69 #endif
70