• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 android.os.profiling;
18 
19 import android.provider.DeviceConfig;
20 
21 /**
22  * Wrapper class for retrieving device configuration values.
23  */
24 public final class DeviceConfigHelper {
25 
26     // Begin section: Testing specific constants
27     // Values here can only be accessed with {@link #getTestBoolean}.
28 
29     // Namespace for testing only that is not registered on the server side
30     public static final String NAMESPACE_TESTING = "profiling_testing";
31 
32     // Configs for testing only.
33     public static final String RATE_LIMITER_DISABLE_PROPERTY = "rate_limiter.disabled";
34 
35     public static final String DISABLE_DELETE_TEMPORARY_RESULTS =
36             "delete_temporary_results.disabled";
37 
38     public static final String SYSTEM_TRIGGERED_TEST_PACKAGE_NAME =
39             "system_triggered_profiling.testing_package_name";
40 
41     // End section: Testing specific constants
42 
43     // Begin section: Server registered constants
44     // Values here can be accessed with all getters except {@link #getTestBoolean}.
45 
46     // Namespace for server configureable values
47     public static final String NAMESPACE = "profiling";
48     // System trace
49     public static final String KILLSWITCH_SYSTEM_TRACE = "killswitch_system_trace";
50     public static final String COST_SYSTEM_TRACE = "cost_system_trace";
51     public static final String SYSTEM_TRACE_DURATION_MS_DEFAULT =
52             "system_trace_duration_ms_default";
53     public static final String SYSTEM_TRACE_DURATION_MS_MIN = "system_trace_duration_ms_min";
54     public static final String SYSTEM_TRACE_DURATION_MS_MAX = "system_trace_duration_ms_max";
55     public static final String SYSTEM_TRACE_SIZE_KB_DEFAULT = "system_trace_size_kb_default";
56     public static final String SYSTEM_TRACE_SIZE_KB_MIN = "system_trace_size_kb_min";
57     public static final String SYSTEM_TRACE_SIZE_KB_MAX = "system_trace_size_kb_max";
58 
59     // Heap Profile
60     public static final String KILLSWITCH_HEAP_PROFILE = "killswitch_heap_profile";
61     public static final String COST_HEAP_PROFILE = "cost_heap_profile";
62     public static final String HEAP_PROFILE_TRACK_JAVA_ALLOCATIONS_DEFAULT =
63             "heap_profile_track_java_allocations_default";
64     public static final String HEAP_PROFILE_FLUSH_TIMEOUT_MS_DEFAULT =
65             "heap_profile_flush_timeout_ms_default";
66     public static final String HEAP_PROFILE_DURATION_MS_DEFAULT =
67             "heap_profile_duration_ms_default";
68     public static final String HEAP_PROFILE_DURATION_MS_MIN = "heap_profile_duration_ms_min";
69     public static final String HEAP_PROFILE_DURATION_MS_MAX = "heap_profile_duration_ms_max";
70     public static final String HEAP_PROFILE_SIZE_KB_DEFAULT = "heap_profile_size_kb_default";
71     public static final String HEAP_PROFILE_SIZE_KB_MIN = "heap_profile_size_kb_min";
72     public static final String HEAP_PROFILE_SIZE_KB_MAX = "heap_profile_size_kb_max";
73     public static final String HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_DEFAULT =
74             "heap_profile_sampling_interval_bytes_default";
75     public static final String HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_MIN =
76             "heap_profile_sampling_interval_bytes_min";
77     public static final String HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_MAX =
78             "heap_profile_sampling_interval_bytes_max";
79 
80     // Java Heap Dump
81     public static final String KILLSWITCH_JAVA_HEAP_DUMP = "killswitch_java_heap_dump";
82     public static final String COST_JAVA_HEAP_DUMP = "cost_java_heap_dump";
83     public static final String JAVA_HEAP_DUMP_DURATION_MS_DEFAULT =
84             "java_heap_dump_duration_ms_default";
85     public static final String JAVA_HEAP_DUMP_DATA_SOURCE_STOP_TIMEOUT_MS_DEFAULT =
86             "java_heap_dump_data_source_stop_timeout_ms_default";
87     public static final String JAVA_HEAP_DUMP_SIZE_KB_DEFAULT = "java_heap_dump_size_kb_default";
88     public static final String JAVA_HEAP_DUMP_SIZE_KB_MIN = "java_heap_dump_size_kb_min";
89     public static final String JAVA_HEAP_DUMP_SIZE_KB_MAX = "java_heap_dump_size_kb_max";
90 
91     // Stack Sampling
92     public static final String KILLSWITCH_STACK_SAMPLING = "killswitch_stack_sampling";
93     public static final String COST_STACK_SAMPLING = "cost_stack_sampling";
94     public static final String STACK_SAMPLING_FLUSH_TIMEOUT_MS_DEFAULT =
95             "stack_sampling_flush_timeout_ms_default";
96     public static final String STACK_SAMPLING_DURATION_MS_DEFAULT =
97             "stack_sampling_duration_ms_default";
98     public static final String STACK_SAMPLING_DURATION_MS_MIN = "stack_sampling_duration_ms_min";
99     public static final String STACK_SAMPLING_DURATION_MS_MAX = "stack_sampling_duration_ms_max";
100     public static final String STACK_SAMPLING_SAMPLING_SIZE_KB_DEFAULT =
101             "stack_sampling_size_kb_default";
102     public static final String STACK_SAMPLING_SAMPLING_SIZE_KB_MIN = "stack_sampling_size_kb_min";
103     public static final String STACK_SAMPLING_SAMPLING_SIZE_KB_MAX = "stack_sampling_size_kb_max";
104     public static final String STACK_SAMPLING_FREQUENCY_DEFAULT =
105             "stack_sampling_frequency_default";
106     public static final String STACK_SAMPLING_FREQUENCY_MIN = "stack_sampling_frequency_min";
107     public static final String STACK_SAMPLING_FREQUENCY_MAX = "stack_sampling_frequency_max";
108 
109     // System Triggered System Trace
110     public static final String COST_SYSTEM_TRIGGERED_SYSTEM_TRACE =
111             "cost_system_triggered_system_trace";
112     public static final String SYSTEM_TRIGGERED_SYSTEM_TRACE_DURATION_MS =
113             "system_triggered_system_trace_duration_ms";
114     public static final String SYSTEM_TRIGGERED_SYSTEM_TRACE_DISCARD_BUFFER_SIZE_KB =
115             "system_triggered_system_trace_discard_buffer_size_kb";
116     public static final String SYSTEM_TRIGGERED_SYSTEM_TRACE_RING_BUFFER_SIZE_KB =
117             "system_triggered_system_trace_ring_buffer_size_kb";
118 
119     // Rate limiter configs
120     public static final String PERSIST_TO_DISK_FREQUENCY_MS = "persist_to_disk_frequency_ms";
121     public static final String MAX_COST_SYSTEM_1_HOUR = "max_cost_system_1_hour";
122     public static final String MAX_COST_PROCESS_1_HOUR = "max_cost_process_1_hour";
123     public static final String MAX_COST_SYSTEM_24_HOUR = "max_cost_system_24_hour";
124     public static final String MAX_COST_PROCESS_24_HOUR = "max_cost_process_24_hour";
125     public static final String MAX_COST_SYSTEM_7_DAY = "max_cost_system_7_day";
126     public static final String MAX_COST_PROCESS_7_DAY = "max_cost_process_7_day";
127 
128     // Perfetto configs
129     public static final String PERFETTO_DESTROY_TIMEOUT_MS = "perfetto_destroy_timeout_ms";
130 
131     // General configs
132     public static final String MAX_RESULT_REDELIVERY_COUNT = "max_result_redelivery_count";
133     public static final String CLEAR_TEMPORARY_DIRECTORY_FREQUENCY_MS =
134             "clear_temporary_directory_frequency_ms";
135     public static final String CLEAR_TEMPORARY_DIRECTORY_BOOT_DELAY_MS =
136             "clear_temporary_directory_boot_delay_ms";
137 
138     // System triggered run configs
139     public static final String SYSTEM_TRIGGERED_TRACE_MIN_PERIOD_SECONDS =
140             "system_triggered_trace_min_period_seconds";
141     public static final String SYSTEM_TRIGGERED_TRACE_MAX_PERIOD_SECONDS =
142             "system_triggered_trace_max_period_seconds";
143 
144     // Post Processing Configs
145     public static final String PROFILING_RECHECK_DELAY_MS = "profiling_recheck_delay_ms";
146 
147     // Redaction configs
148     public static final String REDACTION_CHECK_FREQUENCY_MS = "redaction_check_frequency_ms";
149     public static final String REDACTION_MAX_RUNTIME_ALLOTTED_MS =
150             "redaction_max_runtime_allotted_ms";
151 
152     // End section: Server registered constants
153 
154     /**
155      * Get int param for provided device config name from server side device config namespace
156      * or return default if unavailable for any reason.
157      */
getInt(String name, int defaultValue)158     public static int getInt(String name, int defaultValue) {
159         return DeviceConfig.getInt(NAMESPACE, name, defaultValue);
160     }
161 
162     /**
163      * Get boolean param for provided device config name from test only device config namespace
164      * or return default if unavailable for any reason.
165      */
getTestBoolean(String name, boolean defaultValue)166     public static boolean getTestBoolean(String name, boolean defaultValue) {
167         return DeviceConfig.getBoolean(NAMESPACE_TESTING, name, defaultValue);
168     }
169 
170     /** Get all properties related to Java Heap Dump configuration. */
getAllJavaHeapDumpProperties()171     public static DeviceConfig.Properties getAllJavaHeapDumpProperties() {
172         return DeviceConfig.getProperties(NAMESPACE,
173                 KILLSWITCH_JAVA_HEAP_DUMP,
174                 JAVA_HEAP_DUMP_DURATION_MS_DEFAULT,
175                 JAVA_HEAP_DUMP_DATA_SOURCE_STOP_TIMEOUT_MS_DEFAULT,
176                 JAVA_HEAP_DUMP_SIZE_KB_DEFAULT,
177                 JAVA_HEAP_DUMP_SIZE_KB_MIN,
178                 JAVA_HEAP_DUMP_SIZE_KB_MAX);
179     }
180 
181     /** Get all properties related to Heap Profile configuration. */
getAllHeapProfileProperties()182     public static DeviceConfig.Properties getAllHeapProfileProperties() {
183         return DeviceConfig.getProperties(NAMESPACE,
184                 KILLSWITCH_HEAP_PROFILE,
185                 HEAP_PROFILE_TRACK_JAVA_ALLOCATIONS_DEFAULT,
186                 HEAP_PROFILE_FLUSH_TIMEOUT_MS_DEFAULT,
187                 HEAP_PROFILE_DURATION_MS_DEFAULT,
188                 HEAP_PROFILE_DURATION_MS_MIN,
189                 HEAP_PROFILE_DURATION_MS_MAX,
190                 HEAP_PROFILE_SIZE_KB_DEFAULT,
191                 HEAP_PROFILE_SIZE_KB_MIN,
192                 HEAP_PROFILE_SIZE_KB_MAX,
193                 HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_DEFAULT,
194                 HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_MIN,
195                 HEAP_PROFILE_SAMPLING_INTERVAL_BYTES_MAX);
196     }
197 
198     /** Get all properties related to Stack Sampling configuration. */
getAllStackSamplingProperties()199     public static DeviceConfig.Properties getAllStackSamplingProperties() {
200         return DeviceConfig.getProperties(NAMESPACE,
201                 KILLSWITCH_STACK_SAMPLING,
202                 STACK_SAMPLING_FLUSH_TIMEOUT_MS_DEFAULT,
203                 STACK_SAMPLING_DURATION_MS_DEFAULT,
204                 STACK_SAMPLING_DURATION_MS_MIN,
205                 STACK_SAMPLING_DURATION_MS_MAX,
206                 STACK_SAMPLING_SAMPLING_SIZE_KB_DEFAULT,
207                 STACK_SAMPLING_SAMPLING_SIZE_KB_MIN,
208                 STACK_SAMPLING_SAMPLING_SIZE_KB_MAX,
209                 STACK_SAMPLING_FREQUENCY_DEFAULT,
210                 STACK_SAMPLING_FREQUENCY_MIN,
211                 STACK_SAMPLING_FREQUENCY_MAX);
212     }
213 
214     /** Get all properties related to System Trace configuration. */
getAllSystemTraceProperties()215     public static DeviceConfig.Properties getAllSystemTraceProperties() {
216         return DeviceConfig.getProperties(NAMESPACE,
217                 KILLSWITCH_SYSTEM_TRACE,
218                 SYSTEM_TRACE_DURATION_MS_DEFAULT,
219                 SYSTEM_TRACE_DURATION_MS_MIN,
220                 SYSTEM_TRACE_DURATION_MS_MAX,
221                 SYSTEM_TRACE_SIZE_KB_DEFAULT,
222                 SYSTEM_TRACE_SIZE_KB_MIN,
223                 SYSTEM_TRACE_SIZE_KB_MAX);
224     }
225 
226     /** Get all properties related to System Triggered System Trace configuration. */
getAllSystemTriggeredSystemTraceProperties()227     public static DeviceConfig.Properties getAllSystemTriggeredSystemTraceProperties() {
228         return DeviceConfig.getProperties(NAMESPACE,
229                 SYSTEM_TRIGGERED_SYSTEM_TRACE_DURATION_MS,
230                 SYSTEM_TRIGGERED_SYSTEM_TRACE_DISCARD_BUFFER_SIZE_KB,
231                 SYSTEM_TRIGGERED_SYSTEM_TRACE_RING_BUFFER_SIZE_KB);
232     }
233 
234     /** Get all properties related to rate limiter. */
getAllRateLimiterProperties()235     public static DeviceConfig.Properties getAllRateLimiterProperties() {
236         return DeviceConfig.getProperties(NAMESPACE,
237                 MAX_COST_PROCESS_1_HOUR,
238                 MAX_COST_SYSTEM_1_HOUR,
239                 MAX_COST_PROCESS_24_HOUR,
240                 MAX_COST_SYSTEM_24_HOUR,
241                 MAX_COST_PROCESS_7_DAY,
242                 MAX_COST_SYSTEM_7_DAY,
243                 COST_JAVA_HEAP_DUMP,
244                 COST_HEAP_PROFILE,
245                 COST_STACK_SAMPLING,
246                 COST_SYSTEM_TRACE,
247                 COST_SYSTEM_TRIGGERED_SYSTEM_TRACE,
248                 PERSIST_TO_DISK_FREQUENCY_MS);
249     }
250 
251 }
252