• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "caution.h"
19 #include "hichecker.h"
20 #include "parameter.h"
21 #include "parameters.h"
22 
23 #include "base/log/log.h"
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 
IsPerformanceCheckEnabled()46 bool AceChecker::IsPerformanceCheckEnabled()
47 {
48     return HiviewDFX::HiChecker::Contains(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
49 }
50 
NotifyCaution(const std::string & tag)51 void AceChecker::NotifyCaution(const std::string& tag)
52 {
53     HiviewDFX::Caution caution;
54     caution.SetTriggerRule(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE);
55     HiviewDFX::HiChecker::NotifyCaution(HiviewDFX::Rule::RULE_CHECK_ARKUI_PERFORMANCE, tag, caution);
56 }
57 
InitPerformanceParameters()58 void AceChecker::InitPerformanceParameters()
59 {
60     if (!IsPerformanceCheckEnabled()) {
61         return;
62     }
63     AceChecker::pageNodes_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagenodes", PAGE_NODES);
64     AceChecker::pageDepth_ = system::GetIntParameter<int>("arkui.performancecheck.9901.pagedepth", PAGE_DEPTH);
65     AceChecker::nodeChildren_ = system::GetIntParameter<int>("arkui.performancecheck.9901.nodechildren", NODE_CHILDREN);
66     AceChecker::functionTimeout_ =
67         system::GetIntParameter<int>("arkui.performancecheck.9902.functiontimeout", FUNCTION_TIMEOUT);
68     AceChecker::vsyncTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.vsynctimeout", VSYNC_TIMEOUT);
69     AceChecker::nodeTimeout_ = system::GetIntParameter<int>("arkui.performancecheck.9903.nodetimeout", NODE_TIMEOUT);
70     AceChecker::foreachItems_ = system::GetIntParameter<int>("arkui.performancecheck.9904.foreachitems", FOREACH_ITEMS);
71     AceChecker::flexLayouts_ = system::GetIntParameter<int>("arkui.performancecheck.9905.flexlayouts", FLEX_LAYOUTS);
72 }
73 } // namespace OHOS::Ace
74