1/*
2 * Copyright (C) 2021 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
17syntax = "proto2";
18
19package android.car.telemetry;
20
21option java_package = "android.car.telemetry";
22option java_outer_classname = "TelemetryProto";
23
24// A metrics configuration.
25//
26// The metrics configuration describes a metric that is collected from a device.
27// It includes a declarative part that configures the metric and the data publisher
28// and a data handler to process the data and create a statistic.
29// The latter is written in Lua language.
30message MetricsConfig {
31  // Required.
32  // The name of the configuration. Must be unique within a device.
33  //
34  // Changing the name of the config should be done carefully, by first removing the config
35  // with the old name, and creating a new config with a new name.
36  // The name is used to for persisting the configs and other internal state, not removing the
37  // configs with old name will result dangling data in the system.
38  //
39  // Only alphanumeric and _ characters are allowed. Minimum length is 3 chars.
40  optional string name = 1;
41
42  // Required.
43  // Version number of the configuration. Must be more than 0.
44  optional int32 version = 2;
45
46  // Required.
47  // A script that is executed at the device side. Must contain all the handler
48  // functions defined in the listeners below.
49  // The script functions must be `pure` functions.
50  optional string script = 3;
51
52  // Required.
53  repeated Subscriber subscribers = 4;
54}
55
56// Parameters for Vehicle Properties publisher.
57// See https://source.android.com/devices/automotive/vhal/properties
58message VehiclePropertyPublisher {
59  // Required.
60  // See packages/services/Car/car-lib/src/android/car/VehiclePropertyIds.java
61  optional int32 vehicle_property_id = 1;
62
63  // See
64  // packages/services/Car/car-lib/src/android/car/hardware/property/CarPropertyManager.java
65  // look for constants SENSOR_RATE_*;
66  optional float read_rate = 2;
67}
68
69// Parameters for cartelemetryd publisher.
70// See packages/services/Car/cpp/telemetry for CarData proto and docs.
71message CarTelemetrydPublisher {
72  // Required.
73  // CarData id to subscribe to.
74  // See packages/services/Car/cpp/telemetry/proto/CarData.proto for all the
75  // messages and IDs.
76  optional int32 id = 1;
77}
78
79// Publisher for various system metrics and stats.
80// It pushes metrics to the subscribers periodically or when garage mode starts.
81message StatsPublisher {
82  enum SystemMetric {
83    UNDEFINED = 0;  // default value, not used
84    // Collects all the app start events with the initial used RSS/CACHE/SWAP memory.
85    APP_START_MEMORY_STATE_CAPTURED = 1;
86    // Collects memory state of processes in 5-minute buckets (1 memory measurement per bucket).
87    // Consider using PROCESS_MEMORY_SNAPSHOT instead for smaller data size.
88    PROCESS_MEMORY_STATE = 2;
89    // Collects activity foreground/background transition events.
90    ACTIVITY_FOREGROUND_STATE_CHANGED = 3;
91    // Collects process CPU usage time.
92    PROCESS_CPU_TIME = 4;
93    // Collects app crash events.
94    APP_CRASH_OCCURRED = 5;
95    // Collects App Not Responding events.
96    ANR_OCCURRED = 6;
97    // Collects "wtf"-level log events.
98    WTF_OCCURRED = 7;
99    // Collects memory snapshot of processes in 5-minute buckets (1 memory measurement per bucket).
100    // It differs from PROCESS_MEMORY_STATE in that the snapshot can be used for leaked memory
101    // detection by tracking anon RSS + swap usage.
102    PROCESS_MEMORY_SNAPSHOT = 8;
103    // Logs number of milliseconds it takes to start a process.
104    // The definition of app process start time is from the app launch time to
105    // the time that Zygote finished forking the app process and loaded the
106    // application package's java classes.
107    PROCESS_START_TIME = 9;
108  }
109
110  // Required.
111  // System metric for the publisher.
112  optional SystemMetric system_metric = 1;
113}
114
115// Publisher for connectivity stats.
116// It pulls connectivity metrics when driving session changes.
117message ConnectivityPublisher {
118  // Transports are from android.net.NetworkCapabilities.
119  enum Transport {
120    TRANSPORT_UNDEFINED = 0;  // default value, not used
121    TRANSPORT_CELLULAR = 1;
122    TRANSPORT_WIFI = 2;
123    TRANSPORT_BLUETOOTH = 3;
124    TRANSPORT_ETHERNET = 4;
125  }
126
127  enum OemType {
128    OEM_UNDEFINED = 0;  // default value, not used
129    OEM_NONE = 1;       // non-OEM networks only
130    OEM_MANAGED = 2;    // OEM managed networks only
131  }
132
133  // Required. Network transport.
134  optional Transport transport = 1;
135
136  // Required. OEM network type.
137  optional OemType oem_type = 2;
138}
139
140// Publisher for device-wide memory statistics as well as process memory statistics.
141// It pulls data every N seconds, where N is the read_interval_sec.
142// Only one declaration of MemoryPublisher is allowed across all MetricsConfigs.
143// Performance on a device with 8GB RAM:
144// Collecting device meminfo takes 1-3ms.
145// Collecting process meminfo takes 70ms and up, depending on how many package names are specified.
146// For reference, collecting process memory on 1 process takes ~70ms, and for 10 processes it takes
147// ~200ms.
148message MemoryPublisher {
149  // Required.
150  // The number of seconds in between each memory snapshot.
151  // The smallest acceptable read interval is 1, which means one snapshot per second.
152  // If only device meminfo is collected, i.e., leaving the package_names field as empty, then
153  // one snapshot per second is lightweight enough to be supported.
154  // However, collecting additional process meminfo is an expensive operation and has adverse
155  // system health impact. Client should consider increasing read_interval_sec to reduce the
156  // data collection frequency if package_names field is non-empty.
157  optional int32 read_interval_sec = 1;
158
159  // Optional.
160  // The maximum number of memory snapshots to collect before terminating the MetricsConfig.
161  // If unspecified, data will be collected until Lua script marks the MetricsConfig as finished
162  // or MetricsConfig is removed.
163  optional int32 max_snapshots = 2;
164
165  // Required.
166  // The maximum number of pending script execution tasks that the MemoryPublisher can produce
167  // before the publisher is throttled (rate-limited).
168  optional int32 max_pending_tasks = 3;
169
170  // Optional.
171  // The package names to get process memory statistics on. If specified, it will be published
172  // along with device memory.
173  // Important: Specifying package_names will increase the cost of data collection in
174  // MemoryPublisher. So it should be done carefully and only when necessary. Some remedies
175  // include increasing the read_interval_sec to reduce data collection frequency, and to use a
176  // small number for max_pending_tasks to throttle the publisher. Client should remove the
177  // MetricsConfig once enough process memory data has been collected. It is not intended to be
178  // used as continuous monitoring on process memory because it is an expensive call.
179  repeated string package_names = 4;
180}
181
182// Specifies data publisher and its parameters.
183message Publisher {
184  oneof publisher {
185    VehiclePropertyPublisher vehicle_property = 1;
186    CarTelemetrydPublisher cartelemetryd = 2;
187    StatsPublisher stats = 3;
188    ConnectivityPublisher connectivity = 4;
189    MemoryPublisher memory = 5;
190  }
191}
192
193// Specifies publisher with its parameters and the handler function that's invoked
194// when data is received. The format of the data depends on the Publisher.
195message Subscriber {
196  // Optional.
197  // Name of the function that handles the published data. Must be defined
198  // in the script.
199  // Leaving the field unset signals that the data from the specified publisher
200  // should bypass ScriptExecutor and be uploaded directly in its original form.
201  optional string handler = 1;
202
203  // Required.
204  // Publisher definition.
205  optional Publisher publisher = 2;
206
207  // Required.
208  // Priority of the subscriber, which affects the order of when it receives data.
209  // Ranges from 0 to 100. 0 being highest priority and 100 being lowest.
210  optional int32 priority = 3;
211}
212
213// A message that encapsulates an error that's produced when collecting metrics.
214// Any changes here should also be reflected on
215// p/s/C/service/src/com/android/car/telemetry/scriptexecutorinterface/IScriptExecutorListener.aidl
216// p/s/C/packages/ScriptExecutor/src/ScriptExecutorListener.h
217message TelemetryError {
218  enum ErrorType {
219    // Not used.
220    UNSPECIFIED = 0;
221
222    // Used when an error occurs in the ScriptExecutor code.
223    SCRIPT_EXECUTOR_ERROR = 1;
224
225    // Used when an error occurs while executing the Lua script (such as errors returned by
226    // lua_pcall)
227    LUA_RUNTIME_ERROR = 2;
228
229    // Used to log errors by a script itself, for instance, when a script received inputs outside
230    // of expected range.
231    LUA_SCRIPT_ERROR = 3;
232
233    // Used to log errors that occur due publisher failures.
234    PUBLISHER_FAILED = 4;
235  }
236
237  // Required.
238  // A type that indicates the category of the error.
239  optional ErrorType error_type = 1;
240
241  // Required.
242  // Human readable message explaining the error or how to fix it.
243  optional string message = 2;
244
245  // Optional.
246  // If there is an exception, there will be stack trace. However this information is not always
247  // available.
248  optional string stack_trace = 3;
249}
250