• 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.applicationtrace.bean;
17 
18 import ohos.devtools.views.applicationtrace.util.TimeUtils;
19 import ohos.devtools.views.trace.Common;
20 import ohos.devtools.views.trace.DField;
21 import ohos.devtools.views.trace.EventDispatcher;
22 import ohos.devtools.views.trace.util.ColorUtils;
23 import ohos.devtools.views.trace.util.Utils;
24 
25 import java.awt.Color;
26 import java.awt.Graphics2D;
27 import java.awt.Rectangle;
28 import java.awt.event.MouseEvent;
29 import java.util.Arrays;
30 import java.util.List;
31 
32 /**
33  * Func
34  *
35  * @since 2021/5/20 15:24
36  */
37 public class Func extends AppFunc {
38     /**
39      * parent blood id
40      */
41     protected String parentBloodId = "";
42     @DField(name = "stack_id")
43     private long stackId;
44     @DField(name = "parent_stack_id")
45     private long parentStackId;
46     @DField(name = "id")
47     private Integer id;
48     @DField(name = "parent_id")
49     private Integer parentId;
50     @DField(name = "is_main_thread")
51     private Integer isMainThread;
52     @DField(name = "track_id")
53     private Integer trackId;
54     @DField(name = "funName")
55     private String funcName = "";
56     @DField(name = "tid")
57     private Integer tid;
58     @DField(name = "depth")
59     private Integer depth = 0;
60     @DField(name = "threadName")
61     private String threadName = "";
62     @DField(name = "startTs")
63     private long startTs;
64     @DField(name = "dur")
65     private long dur;
66     private String category;
67     private long running;
68     private long idle;
69     private boolean isSelected; // Whether to be selected
70 
71     /**
72      * Gets the value of parentStackId .
73      *
74      * @return the value of int
75      */
getParentStackId()76     public long getParentStackId() {
77         return parentStackId;
78     }
79 
80     /**
81      * Sets the parentStackId .
82      * <p>You can use getParentStackId() to get the value of parentStackId</p>
83      *
84      * @param parentStackId parentStackId
85      */
setParentStackId(long parentStackId)86     public void setParentStackId(long parentStackId) {
87         this.parentStackId = parentStackId;
88     }
89 
90     /**
91      * Gets the value of stackId .
92      *
93      * @return the value of int
94      */
getStackId()95     public long getStackId() {
96         return stackId;
97     }
98 
99     /**
100      * Sets the stackId .
101      * <p>You can use getStackId() to get the value of stackId</p>
102      *
103      * @param stackId stackId
104      */
setStackId(Integer stackId)105     public void setStackId(Integer stackId) {
106         this.stackId = stackId;
107     }
108 
109     /**
110      * Gets the value of id .
111      *
112      * @return the value of int
113      */
getId()114     public Integer getId() {
115         return id;
116     }
117 
118     /**
119      * Sets the id .
120      * <p>You can use getId() to get the value of id</p>
121      *
122      * @param id id
123      */
setId(Integer id)124     public void setId(Integer id) {
125         this.id = id;
126     }
127 
128     /**
129      * Gets the value of parentId .
130      *
131      * @return the value of int
132      */
getParentId()133     public Integer getParentId() {
134         return parentId;
135     }
136 
137     /**
138      * Sets the parentId .
139      * <p>You can use getParentId() to get the value of parentId</p>
140      *
141      * @param parentId parentId
142      */
setParentId(Integer parentId)143     public void setParentId(Integer parentId) {
144         this.parentId = parentId;
145     }
146 
147     /**
148      * Gets the value of isMainThread .
149      *
150      * @return the value of int
151      */
getIsMainThread()152     public Integer getIsMainThread() {
153         return isMainThread;
154     }
155 
156     /**
157      * Sets the isMainThread .
158      * <p>You can use getIsMainThread() to get the value of isMainThread</p>
159      *
160      * @param mainThread mainThread
161      */
setIsMainThread(final Integer mainThread)162     public void setIsMainThread(final Integer mainThread) {
163         this.isMainThread = mainThread;
164     }
165 
166     /**
167      * Gets the value of trackId .
168      *
169      * @return the value of int
170      */
getTrackId()171     public Integer getTrackId() {
172         return trackId;
173     }
174 
175     /**
176      * Sets the trackId .
177      * <p>You can use getTrackId() to get the value of trackId</p>
178      *
179      * @param id id
180      */
setTrackId(final Integer id)181     public void setTrackId(final Integer id) {
182         this.trackId = id;
183     }
184 
185     /**
186      * Gets the value of category .
187      *
188      * @return the value of java.lang.String
189      */
getCategory()190     public String getCategory() {
191         return category;
192     }
193 
194     /**
195      * Sets the category .
196      * <p>You can use getCategory() to get the value of category</p>
197      *
198      * @param cate cate
199      */
setCategory(final String cate)200     public void setCategory(final String cate) {
201         this.category = cate;
202     }
203 
204     /**
205      * Gets the value of isSelected .
206      *
207      * @return the value of boolean
208      */
isSelected()209     public boolean isSelected() {
210         return isSelected;
211     }
212 
213     /**
214      * Sets the isSelected .
215      * <p>You can use getSelected() to get the value of isSelected</p>
216      *
217      * @param selected selected
218      */
setSelected(final boolean selected)219     public void setSelected(final boolean selected) {
220         this.isSelected = selected;
221     }
222 
223     /**
224      * get depth
225      *
226      * @return depth
227      */
getDepth()228     public Integer getDepth() {
229         return depth;
230     }
231 
232     /**
233      * Set the depth .
234      *
235      * @param depth depth
236      */
setDepth(final Integer depth)237     public void setDepth(final Integer depth) {
238         this.depth = depth;
239     }
240 
241     /**
242      * get the thread name
243      *
244      * @return thread name
245      */
getThreadName()246     public String getThreadName() {
247         return threadName;
248     }
249 
250     /**
251      * set the thread name
252      *
253      * @param threadName thread name
254      */
setThreadName(final String threadName)255     public void setThreadName(final String threadName) {
256         this.threadName = threadName;
257     }
258 
259     /**
260      * get start time
261      *
262      * @return start time
263      */
getStartTs()264     public long getStartTs() {
265         return startTs;
266     }
267 
268     /**
269      * set start ts
270      *
271      * @param startTs start ts
272      */
setStartTs(final long startTs)273     public void setStartTs(final long startTs) {
274         this.startTs = startTs;
275     }
276 
277     /**
278      * get parent blood id
279      *
280      * @return parent blood id
281      */
getParentBloodId()282     public String getParentBloodId() {
283         return parentBloodId;
284     }
285 
286     /**
287      * set the parent blood id
288      *
289      * @param parentBloodId parent blood id
290      */
setParentBloodId(final String parentBloodId)291     public void setParentBloodId(final String parentBloodId) {
292         this.parentBloodId = parentBloodId;
293     }
294 
295     /**
296      * get the endTs
297      *
298      * @return endTs endTs
299      */
getEndTs()300     public long getEndTs() {
301         return endTs;
302     }
303 
304     /**
305      * set the endTs
306      *
307      * @param endTs endTs
308      */
setEndTs(final long endTs)309     public void setEndTs(final long endTs) {
310         this.endTs = endTs;
311         dur = endTs - startTs;
312     }
313 
314     /**
315      * get the funcName
316      *
317      * @return funcName funcName
318      */
getFuncName()319     public String getFuncName() {
320         return funcName;
321     }
322 
323     /**
324      * set the funcName
325      *
326      * @param funcName funcName
327      */
setFuncName(final String funcName)328     public void setFuncName(final String funcName) {
329         this.funcName = funcName;
330     }
331 
332     /**
333      * get duration
334      *
335      * @return duration
336      */
getDur()337     public long getDur() {
338         return dur;
339     }
340 
341     /**
342      * set duration
343      *
344      * @param dur duration
345      */
setDur(final long dur)346     public void setDur(final long dur) {
347         this.dur = dur;
348     }
349 
350     /**
351      * get thread id
352      *
353      * @return thread id
354      */
getTid()355     public Integer getTid() {
356         return tid;
357     }
358 
359     /**
360      * set thread id
361      *
362      * @param tid thread id
363      */
setTid(final Integer tid)364     public void setTid(final Integer tid) {
365         this.tid = tid;
366     }
367 
368     /**
369      * Draw the corresponding shape according to the brush
370      *
371      * @param graphics graphics
372      */
373     @Override
draw(final Graphics2D graphics)374     public void draw(final Graphics2D graphics) {
375         if (depth == -1) {
376             return;
377         }
378         if (isMouseIn) {
379             Common.setAlpha(graphics, 0.7F);
380         } else {
381             Common.setAlpha(graphics, 1.0F);
382         }
383         if (isSelected) {
384             graphics.setColor(Color.black);
385             graphics.fillRect(Utils.getX(rect), Utils.getY(rect), rect.width, rect.height);
386             graphics.setColor(ColorUtils.FUNC_COLOR[depth % ColorUtils.FUNC_COLOR.length]);
387             graphics.fillRect(Utils.getX(rect) + 1, Utils.getY(rect) + 1, rect.width - 2, rect.height - 2);
388             graphics.setColor(Color.white);
389             Rectangle rectangle = new Rectangle();
390             rectangle.setRect(rect.getX() + 1, rect.getY() + 1, rect.getWidth() - 2, rect.getHeight() - 2);
391             Common.drawStringCenter(graphics, funcName, rectangle);
392         } else {
393             graphics.setColor(ColorUtils.FUNC_COLOR[depth % ColorUtils.FUNC_COLOR.length]);
394             graphics.fillRect(Utils.getX(rect), Utils.getY(rect), rect.width, rect.height);
395             graphics.setColor(Color.white);
396             Common.drawStringCenter(graphics, funcName, rect);
397         }
398         Common.setAlpha(graphics, 1.0F);
399     }
400 
401     @Override
getStringList(final String time)402     public List<String> getStringList(final String time) {
403         return Arrays.asList(time, "" + getFuncName(), "Thread:" + threadName, "Tid:" + tid,
404             "Running: " + TimeUtils.getTimeWithUnit(running), "Idle: " + TimeUtils.getTimeWithUnit(idle),
405             "Total: " + TimeUtils.getTimeWithUnit(dur));
406     }
407 
408     /**
409      * create StackId by parentStackId、funcName and depth
410      */
411     @Override
createBloodId()412     public void createBloodId() {
413         if (depth == 0) {
414             bloodId = Utils.md5String(threadName + funcName + depth);
415             parentBloodId = Utils.md5String(threadName);
416         } else {
417             bloodId = Utils.md5String(parentBloodId + funcName + depth);
418         }
419     }
420 
421     /**
422      * Gets the value of idle .
423      *
424      * @return the value of long
425      */
getIdle()426     public long getIdle() {
427         return idle;
428     }
429 
430     /**
431      * Sets the setIdle .
432      * <p>You can use setIdle() to get the value of setIdle</p>
433      *
434      * @param idle idle
435      */
setIdle(final long idle)436     public void setIdle(final long idle) {
437         this.idle = idle;
438         running = dur - idle;
439     }
440 
441     /**
442      * get running time
443      *
444      * @return running time
445      */
getRunning()446     public long getRunning() {
447         return running;
448     }
449 
450     /**
451      * set running time
452      *
453      * @param running running time
454      */
setRunning(final long running)455     public void setRunning(final long running) {
456         this.running = running;
457     }
458 
459     @Override
onClick(MouseEvent event)460     public void onClick(MouseEvent event) {
461         super.onClick(event);
462         if (depth != -1) {
463             EventDispatcher.dispatcherClickListener(this);
464         }
465     }
466 }
467