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
18 #ifdef HICHECKER_EXISTS
19 #include "caution.h"
20 #include "hichecker.h"
21 #include "parameter.h"
22 #include "parameters.h"
23 #endif
24
25 #include "base/log/log.h"
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
48 #ifdef HICHECKER_EXISTS
IsPerformanceCheckEnabled()49 bool AceChecker::IsPerformanceCheckEnabled()
50 {
51 return HiviewDFX::HiChecker::Contains(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
52 }
53
NotifyCaution(const std::string & tag)54 void AceChecker::NotifyCaution(const std::string& tag)
55 {
56 HiviewDFX::Caution caution;
57 caution.SetTriggerRule(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
58 HiviewDFX::HiChecker::NotifyCaution(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE, tag, caution);
59 }
60
InitPerformanceParameters()61 void AceChecker::InitPerformanceParameters()
62 {
63 if (!IsPerformanceCheckEnabled()) {
64 return;
65 }
66 AceChecker::pageNodes_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagenodes", PAGE_NODES);
67 AceChecker::pageDepth_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagedepth", PAGE_DEPTH);
68 AceChecker::nodeChildren_ = system::GetIntParameter<int>("arkui.performancecheck.9901.nodechildren", NODE_CHILDREN);
69 AceChecker::functionTimeout_ =
70 system::GetIntParameter<int>("arkui.performancecheck.9902.functiontimeout", FUNCTION_TIMEOUT);
71 AceChecker::vsyncTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.vsynctimeout", VSYNC_TIMEOUT);
72 AceChecker::nodeTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.nodetimeout", NODE_TIMEOUT);
73 AceChecker::foreachItems_ = system::GetIntParameter<int>("arkui.performancecheck.9904.foreachitems", FOREACH_ITEMS);
74 AceChecker::flexLayouts_ = system::GetIntParameter<int>("arkui.performancecheck.9905.flexlayouts", FLEX_LAYOUTS);
75 }
76 #else
IsPerformanceCheckEnabled()77 bool AceChecker::IsPerformanceCheckEnabled()
78 {
79 return false;
80 }
81
NotifyCaution(const std::string & tag)82 void AceChecker::NotifyCaution(const std::string& tag) {}
InitPerformanceParameters()83 void AceChecker::InitPerformanceParameters() {}
84 #endif
85
86 } // namespace OHOS::Ace
87