• 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 
16 package ohos.devtools.views.perftrace.bean;
17 
18 import ohos.devtools.views.perftrace.PerfData;
19 import ohos.devtools.views.trace.DField;
20 
21 import java.util.Objects;
22 
23 /**
24  * PrefSample from db file
25  *
26  * @since 2021/5/12 16:34
27  */
28 public class PrefSample {
29     /**
30      * KERNEL path name
31      */
32     public static final String KERNEL = "[kernel.kallsyms]";
33 
34     private static final String DATA_APP_DIR = "/data/app";
35 
36     @DField(name = "id")
37     private long id;
38     @DField(name = "callchain_id")
39     private long callChainId;
40     @DField(name = "sample_id")
41     private long sampleId;
42     @DField(name = "thread_id")
43     private long threadId;
44     @DField(name = "timestamp")
45     private long ts;
46     @DField(name = "file_id")
47     private long fileId;
48     @DField(name = "symbol_id")
49     private int symbolId;
50     @DField(name = "vaddr_in_file")
51     private long vaddrInFile;
52     private String name;
53     private boolean isUserWrite = false;
54 
55     /**
56      * get the isUserWrite
57      *
58      * @return boolean isUserWrite
59      */
isUserWrite()60     public boolean isUserWrite() {
61         return isUserWrite;
62     }
63 
64     /**
65      * set the isUserWrite
66      *
67      * @param userWrite isUserWrite
68      */
setUserWrite(boolean userWrite)69     public void setUserWrite(boolean userWrite) {
70         isUserWrite = userWrite;
71     }
72 
73     /**
74      * set the name
75      *
76      * @return String name
77      */
getName()78     public String getName() {
79         return name;
80     }
81 
82     /**
83      * set the name by the file
84      *
85      * @param file file
86      * @return PrefSample
87      */
setName(PrefFile file)88     public PrefSample setName(PrefFile file) {
89         if (Objects.isNull(file)) {
90             name = KERNEL + "+0x" + Long.toHexString(vaddrInFile);
91         } else {
92             if (file.getPath().startsWith(DATA_APP_DIR + PerfData.getThreadNames().get((int) threadId))) {
93                 isUserWrite = true;
94             }
95             if (symbolId == -1) {
96                 name = file.getFileName() + "+0x" + Long.toHexString(vaddrInFile);
97             } else {
98                 name = file.getSymbol();
99             }
100         }
101         return this;
102     }
103 
104     /**
105      * get the sample isSameStack form other sample
106      *
107      * @param sample sample
108      * @return isSameStack
109      */
isSameStack(PrefSample sample)110     public boolean isSameStack(PrefSample sample) {
111         if (!(sample.getFileId() == this.getFileId() && sample.getSymbolId() == this.getSymbolId())) {
112             return false;
113         }
114         if (this.getSymbolId() == -1) {
115             return this.getVaddrInFile() == sample.getVaddrInFile();
116         }
117         return true;
118     }
119 
120     /**
121      * get the callChainId
122      *
123      * @return long callChainId
124      */
getCallChainId()125     public long getCallChainId() {
126         return callChainId;
127     }
128 
129     /**
130      * set the callChainId
131      *
132      * @param callChainId callChainId
133      */
setCallChainId(long callChainId)134     public void setCallChainId(long callChainId) {
135         this.callChainId = callChainId;
136     }
137 
138     /**
139      * get the sampleId
140      *
141      * @return long sampleId
142      */
getSampleId()143     public long getSampleId() {
144         return sampleId;
145     }
146 
147     /**
148      * set the sampleId
149      *
150      * @param sampleId sampleId
151      */
setSampleId(long sampleId)152     public void setSampleId(long sampleId) {
153         this.sampleId = sampleId;
154     }
155 
156     /**
157      * get the sampleId
158      *
159      * @return long threadId
160      */
getThreadId()161     public long getThreadId() {
162         return threadId;
163     }
164 
165     /**
166      * set the sampleId
167      *
168      * @param threadId threadId
169      */
setThreadId(long threadId)170     public void setThreadId(long threadId) {
171         this.threadId = threadId;
172     }
173 
174     /**
175      * get the ts
176      *
177      * @return long ts
178      */
getTs()179     public long getTs() {
180         return ts;
181     }
182 
183     /**
184      * set the ts
185      *
186      * @param ts ts
187      */
setTs(long ts)188     public void setTs(long ts) {
189         this.ts = ts;
190     }
191 
192     /**
193      * get the fileId
194      *
195      * @return long fileId
196      */
getFileId()197     public long getFileId() {
198         return fileId;
199     }
200 
201     /**
202      * set the fileId
203      *
204      * @param fileId fileId
205      */
setFileId(long fileId)206     public void setFileId(long fileId) {
207         this.fileId = fileId;
208     }
209 
210     /**
211      * get the symbolId
212      *
213      * @return long symbolId
214      */
getSymbolId()215     public int getSymbolId() {
216         return symbolId;
217     }
218 
219     /**
220      * set the symbolId
221      *
222      * @param symbolId symbolId
223      */
setSymbolId(int symbolId)224     public void setSymbolId(int symbolId) {
225         this.symbolId = symbolId;
226     }
227 
228     /**
229      * get the vaddrInFile
230      *
231      * @return long vaddrInFile
232      */
getVaddrInFile()233     public long getVaddrInFile() {
234         return vaddrInFile;
235     }
236 
237     /**
238      * set the vaddrInFile
239      *
240      * @param vaddrInFile vaddrInFile
241      */
setVaddrInFile(long vaddrInFile)242     public void setVaddrInFile(long vaddrInFile) {
243         this.vaddrInFile = vaddrInFile;
244     }
245 
getId()246     public long getId() {
247         return id;
248     }
249 
setId(long id)250     public void setId(long id) {
251         this.id = id;
252     }
253 }
254