• 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;
17  
18  import com.intellij.ui.JBColor;
19  import ohos.devtools.views.applicationtrace.bean.TreeTableBean;
20  import ohos.devtools.views.perftrace.bean.PrefFunc;
21  
22  import java.awt.Color;
23  
24  /**
25   * The PerfColorUtil
26   *
27   * @since 2021/04/22 12:25
28   */
29  public class PerfColorUtil {
30      /**
31       * PERF_VENDOR color
32       */
33      public static final Color PERF_VENDOR = new JBColor(0xA2DEFF, 0xA2DEFF);
34  
35      /**
36       * PERF_PLATFORM color
37       */
38      public static final Color PERF_PLATFORM = new JBColor(0xFECC82, 0xFECC82);
39  
40      /**
41       * PERF_APP color
42       */
43      public static final Color PERF_APP = new JBColor(0x9FEAAD, 0x9FEAAD);
44  
45      /**
46       * PERF_FLAME_VENDOR color
47       */
48      public static final Color PERF_FLAME_VENDOR = new JBColor(0xFFC56F, 0xFFC56F);
49  
50      /**
51       * PERF_FLAME_PLATFORM color
52       */
53      public static final Color PERF_FLAME_PLATFORM = new JBColor(0xFF855E, 0xFF855E);
54  
55      /**
56       * PERF_FLAME_APP color
57       */
58      public static final Color PERF_FLAME_APP = new JBColor(0xFFE0B2, 0xFFE0B2);
59  
60      /**
61       * get the func color by type
62       *
63       * @param func func
64       * @return Color Color
65       */
getJavaMethod(PrefFunc func)66      public static Color getJavaMethod(PrefFunc func) {
67          String funcName = func.getFuncName();
68          boolean result = funcName.startsWith("java.") || funcName.startsWith("sun.") || funcName.startsWith("javax.");
69          if (result || funcName.startsWith("apple.") || funcName.startsWith("com.apple.")) {
70              return PERF_VENDOR;
71          } else {
72              return PERF_APP;
73          }
74      }
75  
76      /**
77       * get the TreeTableBean color by type
78       *
79       * @param func func
80       * @return Color Color
81       */
getJavaMethod(TreeTableBean func)82      public static Color getJavaMethod(TreeTableBean func) {
83          String funcName = func.getName();
84          boolean nameResult =
85              funcName.startsWith("java.") || funcName.startsWith("sun.") || funcName.startsWith("javax.");
86          if (nameResult || funcName.startsWith("apple.") || funcName.startsWith("com.apple.")) {
87              return PERF_FLAME_VENDOR;
88          } else {
89              return PERF_FLAME_APP;
90          }
91      }
92  
93      /**
94       * get the PrefFunc color by type
95       *
96       * @param func func
97       * @return Color Color
98       */
getPerfMethod(PrefFunc func)99      public static Color getPerfMethod(PrefFunc func) {
100          String funcName = func.getFuncName();
101          if (func.isUserWrite() && funcName.contains("(")) {
102              return PERF_APP;
103          } else {
104              return PERF_VENDOR;
105          }
106      }
107  
108      /**
109       * get the TreeTableBean color by type
110       *
111       * @param func func
112       * @return Color Color
113       */
getPerfMethod(TreeTableBean func)114      public static Color getPerfMethod(TreeTableBean func) {
115          if (func.isUserWrite()) {
116              return PERF_FLAME_APP;
117          } else {
118              return PERF_FLAME_VENDOR;
119          }
120      }
121  }
122