• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 package ohos.devtools.datasources.utils.monitorconfig.entity;
16 
17 /**
18  * NativeHook Config  Struct.
19  *
20  * @since 2021/11/17
21  */
22 public class NativeHookConfigInfo {
23     private final String DEFAULT_MEMORY_BUFFER = "4:MB";
24     private final String DEFAULT_FILTER_SIZE = "0:MB";
25     private final int UNWIND_SIZE = 10;
26 
27     private String sharedMemorySize = DEFAULT_MEMORY_BUFFER;
28     private String filterSize = DEFAULT_FILTER_SIZE;
29     private int unwind = UNWIND_SIZE;
30 
31 
32     /**
33      * getSharedMemorySize
34      *
35      * @return String
36      */
getSharedMemorySize()37     public String getSharedMemorySize() {
38         return sharedMemorySize;
39     }
40 
41     /**
42      * getSharedMemorySizeValue
43      *
44      * @return int
45      */
getSharedMemorySizeValue()46     public int getSharedMemorySizeValue() {
47         return convertToValue(sharedMemorySize);
48     }
49 
50     /**
51      * setSharedMemorySize
52      *
53      * @param sharedMemorySize sharedMemorySize
54      */
setSharedMemorySize(String sharedMemorySize)55     public void setSharedMemorySize(String sharedMemorySize) {
56         this.sharedMemorySize = sharedMemorySize;
57     }
58 
59     /**
60      * getFilterSize
61      *
62      * @return String
63      */
getFilterSize()64     public String getFilterSize() {
65         return filterSize;
66     }
67 
68 
69     /**
70      * getFilterSizeValue
71      *
72      * @return int
73      */
getFilterSizeValue()74     public int getFilterSizeValue() {
75         return convertToValue(filterSize);
76     }
77 
78     /**
79      * setFilterSize
80      *
81      * @param filterSize filterSize
82      */
setFilterSize(String filterSize)83     public void setFilterSize(String filterSize) {
84         this.filterSize = filterSize;
85     }
86 
87     /**
88      * getUnwind
89      *
90      * @return int
91      */
getUnwind()92     public int getUnwind() {
93         return unwind;
94     }
95 
96     /**
97      * setUnwind
98      *
99      * @param unwind unwind
100      */
setUnwind(int unwind)101     public void setUnwind(int unwind) {
102         this.unwind = unwind;
103     }
104 
convertToValue(String size)105     private int convertToValue(String size) {
106         String[] split = size.split(":");
107         int value;
108         String unit = split[1];
109         switch (unit) {
110             case "MB":
111                 value = Integer.parseInt(split[0]) * 1024 * 1024;
112                 break;
113             case "KB":
114                 value = Integer.parseInt(split[0]) * 1024;
115                 break;
116             default:
117                 value = 0;
118         }
119         return value / 4096;
120     }
121 }
122