• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.traceur;
18 
19 import android.os.Build;
20 import android.util.ArraySet;
21 
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Set;
26 
27 public class PresetTraceConfigs {
28 
29     private static final List<String> DEFAULT_TRACE_TAGS = Arrays.asList(
30             "aidl", "am", "binder_driver", "camera", "cpm", "dalvik", "disk", "freq",
31             "gfx", "hal", "idle", "input", "memory", "memreclaim", "network", "power",
32             "res", "sched", "ss", "sync", "thermal", "view", "webview", "wm", "workq");
33 
34     private static final List<String> PERFORMANCE_TRACE_TAGS = DEFAULT_TRACE_TAGS;
35     private static final List<String> UI_TRACE_TAGS = DEFAULT_TRACE_TAGS;
36 
37     private static final List<String> THERMAL_TRACE_TAGS = Arrays.asList(
38             "aidl", "am", "binder_driver", "camera", "dalvik", "disk", "freq",
39             "gfx", "hal", "idle", "input", "memory", "memreclaim", "network", "power",
40             "res", "sched", "ss", "sync", "thermal", "thermal_tj", "view", "webview",
41             "wm", "workq");
42 
43     private static final List<String> BATTERY_TRACE_TAGS = Arrays.asList(
44             "aidl", "am", "binder_driver", "network", "nnapi",
45             "pm", "power", "ss", "thermal", "wm");
46 
47     private static final List<String> USER_BUILD_DISABLED_TRACE_TAGS = Arrays.asList(
48             "workq", "sync");
49 
50     private static Set<String> mDefaultTagList = null;
51     private static Set<String> mPerformanceTagList = null;
52     private static Set<String> mBatteryTagList = null;
53     private static Set<String> mThermalTagList = null;
54     private static Set<String> mUiTagList = null;
55 
getDefaultConfig()56     public static TraceConfig getDefaultConfig() {
57         if (mDefaultTagList == null) {
58             mDefaultTagList = new ArraySet<>(DEFAULT_TRACE_TAGS);
59             updateTagsIfUserBuild(mDefaultTagList);
60         }
61         return new TraceConfig(DEFAULT_TRACE_OPTIONS, mDefaultTagList);
62     }
63 
getPerformanceConfig()64     public static TraceConfig getPerformanceConfig() {
65         if (mPerformanceTagList == null) {
66             mPerformanceTagList = new ArraySet<>(PERFORMANCE_TRACE_TAGS);
67             updateTagsIfUserBuild(mPerformanceTagList);
68         }
69         return new TraceConfig(PERFORMANCE_TRACE_OPTIONS, mPerformanceTagList);
70     }
71 
getBatteryConfig()72     public static TraceConfig getBatteryConfig() {
73         if (mBatteryTagList == null) {
74             mBatteryTagList = new ArraySet<>(BATTERY_TRACE_TAGS);
75             updateTagsIfUserBuild(mBatteryTagList);
76         }
77         return new TraceConfig(BATTERY_TRACE_OPTIONS, mBatteryTagList);
78     }
79 
getThermalConfig()80     public static TraceConfig getThermalConfig() {
81         if (mThermalTagList == null) {
82             mThermalTagList = new ArraySet<>(THERMAL_TRACE_TAGS);
83             updateTagsIfUserBuild(mThermalTagList);
84         }
85         return new TraceConfig(THERMAL_TRACE_OPTIONS, mThermalTagList);
86     }
87 
getUiConfig()88     public static TraceConfig getUiConfig() {
89         if (mUiTagList == null) {
90             mUiTagList = new ArraySet<>(UI_TRACE_TAGS);
91             updateTagsIfUserBuild(mUiTagList);
92         }
93         return new TraceConfig(UI_TRACE_OPTIONS, mUiTagList);
94     }
95 
updateTagsIfUserBuild(Collection<String> tags)96     private static void updateTagsIfUserBuild(Collection<String> tags) {
97         if (Build.TYPE.equals("user")) {
98             tags.removeAll(USER_BUILD_DISABLED_TRACE_TAGS);
99         }
100     }
101 
102     public static class TraceOptions {
103         public final int bufferSizeKb;
104         public final boolean winscope;
105         public final boolean apps;
106         public final boolean longTrace;
107         public final boolean attachToBugreport;
108         public final int maxLongTraceSizeMb;
109         public final int maxLongTraceDurationMinutes;
110 
TraceOptions(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace, boolean attachToBugreport, int maxLongTraceSizeMb, int maxLongTraceDurationMinutes)111         public TraceOptions(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace,
112                 boolean attachToBugreport, int maxLongTraceSizeMb,
113                 int maxLongTraceDurationMinutes) {
114             this.bufferSizeKb = bufferSizeKb;
115             this.winscope = winscope;
116             this.apps = apps;
117             this.longTrace = longTrace;
118             this.attachToBugreport = attachToBugreport;
119             this.maxLongTraceSizeMb = maxLongTraceSizeMb;
120             this.maxLongTraceDurationMinutes = maxLongTraceDurationMinutes;
121         }
122     }
123 
124     // Keep in sync with default sizes and durations in buffer_sizes.xml.
125     private static final int DEFAULT_BUFFER_SIZE_KB = 16384;
126     private static final int DEFAULT_MAX_LONG_TRACE_SIZE_MB = 10240;
127     private static final int DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES = 30;
128 
129     private static final TraceOptions DEFAULT_TRACE_OPTIONS =
130             new TraceOptions(DEFAULT_BUFFER_SIZE_KB,
131                     /* winscope */ false,
132                     /* apps */ true,
133                     /* longTrace */ false,
134                     /* attachToBugreport */ true,
135                     DEFAULT_MAX_LONG_TRACE_SIZE_MB,
136                     DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES);
137 
138     private static final TraceOptions PERFORMANCE_TRACE_OPTIONS =
139             new TraceOptions(DEFAULT_BUFFER_SIZE_KB,
140                     /* winscope */ false,
141                     /* apps */ true,
142                     /* longTrace */ false,
143                     /* attachToBugreport */ true,
144                     DEFAULT_MAX_LONG_TRACE_SIZE_MB,
145                     DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES);
146 
147     private static final TraceOptions BATTERY_TRACE_OPTIONS =
148             new TraceOptions(DEFAULT_BUFFER_SIZE_KB,
149                     /* winscope */ false,
150                     /* apps */ false,
151                     /* longTrace */ true,
152                     /* attachToBugreport */ true,
153                     DEFAULT_MAX_LONG_TRACE_SIZE_MB,
154                     DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES);
155 
156     private static final TraceOptions THERMAL_TRACE_OPTIONS =
157             new TraceOptions(DEFAULT_BUFFER_SIZE_KB,
158                     /* winscope */ false,
159                     /* apps */ true,
160                     /* longTrace */ true,
161                     /* attachToBugreport */ true,
162                     DEFAULT_MAX_LONG_TRACE_SIZE_MB,
163                     DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES);
164 
165     private static final TraceOptions UI_TRACE_OPTIONS =
166             new TraceOptions(DEFAULT_BUFFER_SIZE_KB,
167                     /* winscope */ true,
168                     /* apps */ true,
169                     /* longTrace */ true,
170                     /* attachToBugreport */ true,
171                     DEFAULT_MAX_LONG_TRACE_SIZE_MB,
172                     DEFAULT_MAX_LONG_TRACE_DURATION_MINUTES);
173 }
174