1 /*
2 * Copyright (c) 2025 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 "mem_param_parse.h"
17 #include "memory/rs_memory_snapshot.h"
18
19 namespace OHOS::Rosen {
20
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)21 int32_t MEMParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
22 {
23 RS_LOGI("MEMParamParse start");
24 xmlNode *currNode = &node;
25 if (currNode == nullptr || currNode->xmlChildrenNode == nullptr) {
26 RS_LOGD("MEMParamParse stop parsing, no nodes");
27 return PARSE_GET_CHILD_FAIL;
28 }
29
30 currNode = currNode->xmlChildrenNode;
31 for (; currNode; currNode = currNode->next) {
32 if (currNode->type != XML_ELEMENT_NODE) {
33 continue;
34 }
35
36 if (ParseMemInternal(*currNode) != PARSE_EXEC_SUCCESS) {
37 RS_LOGD("MEMParamParse stop parsing, parse internal fail");
38 return PARSE_INTERNAL_FAIL;
39 }
40 }
41
42 return PARSE_EXEC_SUCCESS;
43 }
44
ParseMemInternal(xmlNode & node)45 int32_t MEMParamParse::ParseMemInternal(xmlNode &node)
46 {
47 // Start Parse Feature Params
48 int xmlParamType = GetXmlNodeAsInt(node);
49 auto name = ExtractPropertyValue("name", node);
50 auto val = ExtractPropertyValue("value", node);
51 if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
52 if (name == "RsWatchPoint") {
53 MEMParam::SetRSWatchPoint(val);
54 RS_LOGI("MEMParamParse parse RSWatchPoint %{public}s", MEMParam::GetRSWatchPoint().c_str());
55 } else if (name == "RSCacheLimitsResourceSize" && IsNumber(val)) {
56 MEMParam::SetRSCacheLimitsResourceSize(stoi(val));
57 RS_LOGI("RSCacheLimitsResourceSize %{public}d", MEMParam::GetRSCacheLimitsResourceSize());
58 } else if (name =="MemSnapshotPrintHilogLimit" && IsNumber(val)) {
59 MemorySnapshot::Instance().SetMemSnapshotPrintHilogLimit(stoi(val));
60 RS_LOGI("memSnapshotPrintHilogLimit %{public}d",
61 MemorySnapshot::Instance().GetMemSnapshotPrintHilogLimit());
62 }
63 } else if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
64 bool isEnabled = ParseFeatureSwitch(val);
65 if (name == "ReclaimEnabled") {
66 MEMParam::SetReclaimEnabled(isEnabled);
67 RS_LOGI("MEMParamParse parse ReclaimEnabled %{public}d", MEMParam::IsReclaimEnabled());
68 } else if (name == "DeeplyReleaseGpuResourceEnabled") {
69 MEMParam::SetDeeplyRelGpuResEnable(isEnabled);
70 RS_LOGI("MEMParamParse parse DeeplyReleaseGpuResourceEnabled %{public}d",
71 MEMParam::IsDeeplyRelGpuResEnable());
72 }
73 }
74
75 return PARSE_EXEC_SUCCESS;
76 }
77 } // namespace OHOS::Rosen