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 namespace OHOS::Ace {
26 namespace {
27 constexpr int32_t PAGE_NODES = 1000;
28 constexpr int32_t PAGE_DEPTH = 30;
29 constexpr int32_t NODE_CHILDREN = 100;
30 constexpr int32_t FUNCTION_TIMEOUT = 15;
31 constexpr int32_t VSYNC_TIMEOUT = 500;
32 constexpr int32_t NODE_TIMEOUT = 15;
33 constexpr int32_t FOREACH_ITEMS = 50;
34 constexpr int32_t FLEX_LAYOUTS = 8;
35 } // namespace
36
37 int32_t AceChecker::pageNodes_ = PAGE_NODES;
38 int32_t AceChecker::pageDepth_ = PAGE_DEPTH;
39 int32_t AceChecker::nodeChildren_ = NODE_CHILDREN;
40 int32_t AceChecker::functionTimeout_ = FUNCTION_TIMEOUT;
41 int32_t AceChecker::vsyncTimeout_ = VSYNC_TIMEOUT;
42 int32_t AceChecker::nodeTimeout_ = NODE_TIMEOUT;
43 int32_t AceChecker::foreachItems_ = FOREACH_ITEMS;
44 int32_t AceChecker::flexLayouts_ = FLEX_LAYOUTS;
45
46 #ifdef HICHECKER_EXISTS
IsPerformanceCheckEnabled()47 bool AceChecker::IsPerformanceCheckEnabled()
48 {
49 return HiviewDFX::HiChecker::Contains(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
50 }
51
NotifyCaution(const std::string& tag)52 void AceChecker::NotifyCaution(const std::string& tag)
53 {
54 HiviewDFX::Caution caution;
55 caution.SetTriggerRule(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
56 HiviewDFX::HiChecker::NotifyCaution(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE, tag, caution);
57 }
58
InitPerformanceParameters()59 void AceChecker::InitPerformanceParameters()
60 {
61 if (!IsPerformanceCheckEnabled()) {
62 return;
63 }
64 AceChecker::pageNodes_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagenodes", PAGE_NODES);
65 AceChecker::pageDepth_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagedepth", PAGE_DEPTH);
66 AceChecker::nodeChildren_ = system::GetIntParameter<int>("arkui.performancecheck.9901.nodechildren", NODE_CHILDREN);
67 AceChecker::functionTimeout_ =
68 system::GetIntParameter<int>("arkui.performancecheck.9902.functiontimeout", FUNCTION_TIMEOUT);
69 AceChecker::vsyncTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.vsynctimeout", VSYNC_TIMEOUT);
70 AceChecker::nodeTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.nodetimeout", NODE_TIMEOUT);
71 AceChecker::foreachItems_ = system::GetIntParameter<int>("arkui.performancecheck.9904.foreachitems", FOREACH_ITEMS);
72 AceChecker::flexLayouts_ = system::GetIntParameter<int>("arkui.performancecheck.9905.flexlayouts", FLEX_LAYOUTS);
73 }
74 #else
IsPerformanceCheckEnabled()75 bool AceChecker::IsPerformanceCheckEnabled()
76 {
77 return false;
78 }
79
NotifyCaution(const std::string& tag)80 void AceChecker::NotifyCaution(const std::string& tag) {}
InitPerformanceParameters()81 void AceChecker::InitPerformanceParameters() {}
82 #endif
83
84 } // namespace OHOS::Ace
85