• 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 FREEZE_RESOLVER_H
17 #define FREEZE_RESOLVER_H
18 
19 #include <list>
20 #include <memory>
21 #include <set>
22 #include <vector>
23 
24 #include "db_helper.h"
25 #include "freeze_common.h"
26 #include "watch_point.h"
27 #include "vendor.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class FreezeResolver {
32 public:
FreezeResolver(std::shared_ptr<FreezeCommon> fc)33     explicit FreezeResolver(std::shared_ptr<FreezeCommon> fc)
34         : startTime_(time(nullptr) * MILLISECOND), freezeCommon_(fc) {};
~FreezeResolver()35     ~FreezeResolver() {};
36     FreezeResolver& operator=(const FreezeResolver&) = delete;
37     FreezeResolver(const FreezeResolver&) = delete;
38 
39     static const int MILLISECOND = 1000;
40 
41     bool Init();
42     std::string GetTimeZone() const;
43     int ProcessEvent(const WatchPoint &watchPoint) const;
44 
45 private:
46     static const inline std::string HEADER = "*******************************************";
47     static const int DEFAULT_TIME_WINDOW = 30;
48     static const int MINUTES_IN_HOUR = 60;
49 
50     bool ResolveEvent(const WatchPoint& watchPoint,
51     std::vector<WatchPoint>& list, std::vector<FreezeResult>& result) const;
52     bool JudgmentResult(const WatchPoint& watchPoint,
53         const std::vector<WatchPoint>& list, const std::vector<FreezeResult>& result) const;
54     unsigned long startTime_;
55     std::shared_ptr<FreezeCommon> freezeCommon_ = nullptr;
56     std::shared_ptr<FreezeRuleCluster> freezeRuleCluster_ = nullptr;
57     std::unique_ptr<DBHelper> dBHelper_ = nullptr;
58     std::unique_ptr<Vendor> vendor_ = nullptr;
59 };
60 }  // namespace HiviewDFX
61 }  // namespace OHOS
62 #endif // FREEZE_DETECTOR_RESOLVER_H
63