1 /*
2 * Copyright (c) 2023 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 "base/log/ace_checker.h"
17 #include "base/log/ace_performance_check.h"
18 #include "base/websocket/websocket_manager.h"
19
20 #ifdef HICHECKER_EXISTS
21 #include "caution.h"
22 #include "hichecker.h"
23 #include "parameter.h"
24 #include "parameters.h"
25 #endif
26
27 namespace OHOS::Ace {
28 namespace {
29 constexpr int32_t PAGE_NODES = 1000;
30 constexpr int32_t PAGE_DEPTH = 30;
31 constexpr int32_t NODE_CHILDREN = 100;
32 constexpr int32_t FUNCTION_TIMEOUT = 15;
33 constexpr int32_t VSYNC_TIMEOUT = 500;
34 constexpr int32_t NODE_TIMEOUT = 15;
35 constexpr int32_t FOREACH_ITEMS = 50;
36 constexpr int32_t FLEX_LAYOUTS = 8;
37 } // namespace
38
39 int32_t AceChecker::pageNodes_ = PAGE_NODES;
40 int32_t AceChecker::pageDepth_ = PAGE_DEPTH;
41 int32_t AceChecker::nodeChildren_ = NODE_CHILDREN;
42 int32_t AceChecker::functionTimeout_ = FUNCTION_TIMEOUT;
43 int32_t AceChecker::vsyncTimeout_ = VSYNC_TIMEOUT;
44 int32_t AceChecker::nodeTimeout_ = NODE_TIMEOUT;
45 int32_t AceChecker::foreachItems_ = FOREACH_ITEMS;
46 int32_t AceChecker::flexLayouts_ = FLEX_LAYOUTS;
47 std::string AceChecker::checkMessage_ = "";
48 bool AceChecker::isPerformanceCheckEnabled_ = false;
49 bool AceChecker::isWebSocketCheckEnabled_ = false;
50
51 #ifdef HICHECKER_EXISTS
IsPerformanceCheckEnabled()52 bool AceChecker::IsPerformanceCheckEnabled()
53 {
54 return HiviewDFX::HiChecker::Contains(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE) || isPerformanceCheckEnabled_;
55 }
56
NotifyCaution(const std::string & tag)57 void AceChecker::NotifyCaution(const std::string& tag)
58 {
59 HiviewDFX::Caution caution;
60 caution.SetTriggerRule(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
61 HiviewDFX::HiChecker::NotifyCaution(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE, tag, caution);
62 }
63
InitPerformanceParameters()64 void AceChecker::InitPerformanceParameters()
65 {
66 if (!IsPerformanceCheckEnabled()) {
67 return;
68 }
69 AceChecker::pageNodes_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagenodes", PAGE_NODES);
70 AceChecker::pageDepth_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagedepth", PAGE_DEPTH);
71 AceChecker::nodeChildren_ = system::GetIntParameter<int>("arkui.performancecheck.9901.nodechildren", NODE_CHILDREN);
72 AceChecker::functionTimeout_ =
73 system::GetIntParameter<int>("arkui.performancecheck.9902.functiontimeout", FUNCTION_TIMEOUT);
74 AceChecker::vsyncTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.vsynctimeout", VSYNC_TIMEOUT);
75 AceChecker::nodeTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.nodetimeout", NODE_TIMEOUT);
76 AceChecker::foreachItems_ = system::GetIntParameter<int>("arkui.performancecheck.9904.foreachitems", FOREACH_ITEMS);
77 AceChecker::flexLayouts_ = system::GetIntParameter<int>("arkui.performancecheck.9905.flexlayouts", FLEX_LAYOUTS);
78 }
79
SetPerformanceCheckStatus(bool status,const std::string & message)80 void AceChecker::SetPerformanceCheckStatus(bool status, const std::string& message)
81 {
82 AceChecker::checkMessage_ = message;
83 AceChecker::isPerformanceCheckEnabled_ = status;
84 AceChecker::isWebSocketCheckEnabled_ = true;
85 if (status) {
86 AceChecker::InitPerformanceParameters();
87 AcePerformanceCheck::Start();
88 } else {
89 AcePerformanceCheck::Stop();
90 }
91 }
92
93 #else
IsPerformanceCheckEnabled()94 bool AceChecker::IsPerformanceCheckEnabled()
95 {
96 return isPerformanceCheckEnabled_;
97 }
98
NotifyCaution(const std::string & tag)99 void AceChecker::NotifyCaution(const std::string& tag) {}
InitPerformanceParameters()100 void AceChecker::InitPerformanceParameters() {}
101
SetPerformanceCheckStatus(bool status,const std::string & message)102 void AceChecker::SetPerformanceCheckStatus(bool status, const std::string& message)
103 {
104 AceChecker::checkMessage_ = message;
105 AceChecker::isPerformanceCheckEnabled_ = status;
106 AceChecker::isWebSocketCheckEnabled_ = true;
107 if (status) {
108 AceChecker::InitPerformanceParameters();
109 AcePerformanceCheck::Start();
110 } else {
111 AcePerformanceCheck::Stop();
112 }
113 }
114
115 #endif
116
117 } // namespace OHOS::Ace
118