1/*
2 * Copyright (C) 2017 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.os.statsd;
20
21option java_package = "com.android.internal.os";
22option java_outer_classname = "StatsdConfigProto";
23
24enum Position {
25  POSITION_UNKNOWN = 0;
26
27  FIRST = 1;
28
29  LAST = 2;
30
31  ANY = 3;
32
33  ALL = 4;
34}
35
36enum TimeUnit {
37  TIME_UNIT_UNSPECIFIED = 0;
38  ONE_MINUTE = 1;  // WILL BE GUARDRAILED TO 5 MINS UNLESS UID = SHELL OR ROOT
39  FIVE_MINUTES = 2;
40  TEN_MINUTES = 3;
41  THIRTY_MINUTES = 4;
42  ONE_HOUR = 5;
43  THREE_HOURS = 6;
44  SIX_HOURS = 7;
45  TWELVE_HOURS = 8;
46  ONE_DAY = 9;
47  ONE_WEEK = 10;
48  CTS = 1000;
49}
50
51message FieldMatcher {
52  optional int32 field = 1;
53
54  optional Position position = 2;
55
56  repeated FieldMatcher child = 3;
57}
58
59message FieldValueMatcher {
60  optional int32 field = 1;
61
62  optional Position position = 2;
63
64  oneof value_matcher {
65    bool eq_bool = 3;
66    string eq_string = 4;
67    int64 eq_int = 5;
68
69    int64 lt_int = 6;
70    int64 gt_int = 7;
71    float lt_float = 8;
72    float gt_float = 9;
73
74    int64 lte_int = 10;
75    int64 gte_int = 11;
76
77    MessageMatcher matches_tuple = 12;
78
79    StringListMatcher eq_any_string = 13;
80    StringListMatcher neq_any_string = 14;
81  }
82}
83
84message MessageMatcher {
85  repeated FieldValueMatcher field_value_matcher = 1;
86}
87
88message StringListMatcher {
89    repeated string str_value = 1;
90}
91
92enum LogicalOperation {
93  LOGICAL_OPERATION_UNSPECIFIED = 0;
94  AND = 1;
95  OR = 2;
96  NOT = 3;
97  NAND = 4;
98  NOR = 5;
99}
100
101message SimpleAtomMatcher {
102  optional int32 atom_id = 1;
103
104  repeated FieldValueMatcher field_value_matcher = 2;
105}
106
107message AtomMatcher {
108  optional int64 id = 1;
109
110  message Combination {
111    optional LogicalOperation operation = 1;
112
113    repeated int64 matcher = 2;
114  }
115  oneof contents {
116    SimpleAtomMatcher simple_atom_matcher = 2;
117    Combination combination = 3;
118  }
119}
120
121message SimplePredicate {
122  optional int64 start = 1;
123
124  optional int64 stop = 2;
125
126  optional bool count_nesting = 3 [default = true];
127
128  optional int64 stop_all = 4;
129
130  enum InitialValue {
131    UNKNOWN = 0;
132    FALSE = 1;
133  }
134  optional InitialValue initial_value = 5 [default = UNKNOWN];
135
136  optional FieldMatcher dimensions = 6;
137}
138
139message Predicate {
140  optional int64 id = 1;
141
142  message Combination {
143    optional LogicalOperation operation = 1;
144
145    repeated int64 predicate = 2;
146  }
147
148  oneof contents {
149    SimplePredicate simple_predicate = 2;
150    Combination combination = 3;
151  }
152}
153
154message StateMap {
155  message StateGroup {
156    optional int64 group_id = 1;
157
158    repeated int32 value = 2;
159  }
160
161  repeated StateGroup group = 1;
162}
163
164message State {
165  optional int64 id = 1;
166
167  optional int32 atom_id = 2;
168
169  optional StateMap map = 3;
170}
171
172message MetricConditionLink {
173  optional int64 condition = 1;
174
175  optional FieldMatcher fields_in_what = 2;
176
177  optional FieldMatcher fields_in_condition = 3;
178}
179
180message MetricStateLink {
181  optional int32 state_atom_id = 1;
182
183  optional FieldMatcher fields_in_what = 2;
184
185  optional FieldMatcher fields_in_state = 3;
186}
187
188message FieldFilter {
189  optional bool include_all = 1 [default = false];
190  optional FieldMatcher fields = 2;
191}
192
193message EventMetric {
194  optional int64 id = 1;
195
196  optional int64 what = 2;
197
198  optional int64 condition = 3;
199
200  repeated MetricConditionLink links = 4;
201
202  reserved 100;
203  reserved 101;
204}
205
206message CountMetric {
207  optional int64 id = 1;
208
209  optional int64 what = 2;
210
211  optional int64 condition = 3;
212
213  optional FieldMatcher dimensions_in_what = 4;
214
215  repeated int64 slice_by_state = 8;
216
217  optional TimeUnit bucket = 5;
218
219  repeated MetricConditionLink links = 6;
220
221  repeated MetricStateLink state_link = 9;
222
223  optional FieldMatcher dimensions_in_condition = 7 [deprecated = true];
224
225  reserved 100;
226  reserved 101;
227}
228
229message DurationMetric {
230  optional int64 id = 1;
231
232  optional int64 what = 2;
233
234  optional int64 condition = 3;
235
236  repeated int64 slice_by_state = 9;
237
238  repeated MetricConditionLink links = 4;
239
240  repeated MetricStateLink state_link = 10;
241
242  enum AggregationType {
243    SUM = 1;
244
245    MAX_SPARSE = 2;
246  }
247  optional AggregationType aggregation_type = 5 [default = SUM];
248
249  optional FieldMatcher dimensions_in_what = 6;
250
251  optional TimeUnit bucket = 7;
252
253  optional FieldMatcher dimensions_in_condition = 8 [deprecated = true];
254
255  reserved 100;
256  reserved 101;
257}
258
259message GaugeMetric {
260  optional int64 id = 1;
261
262  optional int64 what = 2;
263
264  optional int64 trigger_event = 12;
265
266  optional FieldFilter gauge_fields_filter = 3;
267
268  optional int64 condition = 4;
269
270  optional FieldMatcher dimensions_in_what = 5;
271
272  optional FieldMatcher dimensions_in_condition = 8 [deprecated = true];
273
274  optional TimeUnit bucket = 6;
275
276  repeated MetricConditionLink links = 7;
277
278  enum SamplingType {
279    RANDOM_ONE_SAMPLE = 1;
280    ALL_CONDITION_CHANGES = 2 [deprecated = true];
281    CONDITION_CHANGE_TO_TRUE = 3;
282    FIRST_N_SAMPLES = 4;
283  }
284  optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ;
285
286  optional int64 min_bucket_size_nanos = 10;
287
288  optional int64 max_num_gauge_atoms_per_bucket = 11 [default = 10];
289
290  optional int32 max_pull_delay_sec = 13 [default = 30];
291
292  optional bool split_bucket_for_app_upgrade = 14 [default = true];
293
294  reserved 100;
295  reserved 101;
296}
297
298message ValueMetric {
299  optional int64 id = 1;
300
301  optional int64 what = 2;
302
303  optional FieldMatcher value_field = 3;
304
305  optional int64 condition = 4;
306
307  optional FieldMatcher dimensions_in_what = 5;
308
309  repeated int64 slice_by_state = 18;
310
311  optional TimeUnit bucket = 6;
312
313  repeated MetricConditionLink links = 7;
314
315  repeated MetricStateLink state_link = 19;
316
317  enum AggregationType {
318    SUM = 1;
319    MIN = 2;
320    MAX = 3;
321    AVG = 4;
322  }
323  optional AggregationType aggregation_type = 8 [default = SUM];
324
325  optional int64 min_bucket_size_nanos = 10;
326
327  optional bool use_absolute_value_on_reset = 11 [default = false];
328
329  optional bool use_diff = 12;
330
331  optional bool use_zero_default_base = 15 [default = false];
332
333  enum ValueDirection {
334      UNKNOWN = 0;
335      INCREASING = 1;
336      DECREASING = 2;
337      ANY = 3;
338  }
339  optional ValueDirection value_direction = 13 [default = INCREASING];
340
341  optional bool skip_zero_diff_output = 14 [default = true];
342
343  optional int32 max_pull_delay_sec = 16 [default = 30];
344
345  optional bool split_bucket_for_app_upgrade = 17 [default = true];
346
347  optional FieldMatcher dimensions_in_condition = 9 [deprecated = true];
348
349  reserved 100;
350  reserved 101;
351}
352
353message Alert {
354  optional int64 id = 1;
355
356  optional int64 metric_id = 2;
357
358  optional int32 num_buckets = 3;
359
360  optional int32 refractory_period_secs = 4;
361
362  optional double trigger_if_sum_gt = 5;
363}
364
365message Alarm {
366  optional int64 id = 1;
367
368  optional int64 offset_millis = 2;
369
370  optional int64 period_millis = 3;
371}
372
373message IncidentdDetails {
374  repeated int32 section = 1;
375
376  enum Destination {
377    AUTOMATIC = 0;
378    EXPLICIT = 1;
379  }
380  optional Destination dest = 2;
381
382  // Package name of the incident report receiver.
383  optional string receiver_pkg = 3;
384
385  // Class name of the incident report receiver.
386  optional string receiver_cls = 4;
387
388  optional string alert_description = 5;
389}
390
391message PerfettoDetails {
392  // The |trace_config| field is a proto-encoded message of type
393  // perfetto.protos.TraceConfig defined in
394  // //external/perfetto/protos/perfetto/config/. On device,
395  // statsd doesn't need to deserialize the message as it's just
396  // passed binary-encoded to the perfetto cmdline client.
397  optional bytes trace_config = 1;
398}
399
400message BroadcastSubscriberDetails {
401  optional int64 subscriber_id = 1;
402  repeated string cookie = 2;
403}
404
405message Subscription {
406  optional int64 id = 1;
407
408  enum RuleType {
409    RULE_TYPE_UNSPECIFIED = 0;
410    ALARM = 1;
411    ALERT = 2;
412  }
413  optional RuleType rule_type = 2;
414
415  optional int64 rule_id = 3;
416
417  oneof subscriber_information {
418    IncidentdDetails incidentd_details = 4;
419    PerfettoDetails perfetto_details = 5;
420    BroadcastSubscriberDetails broadcast_subscriber_details = 6;
421  }
422
423  optional float probability_of_informing = 7 [default = 1.1];
424
425  // This was used for perfprofd historically.
426  reserved 8;
427}
428
429enum ActivationType {
430  ACTIVATION_TYPE_UNKNOWN = 0;
431  ACTIVATE_IMMEDIATELY = 1;
432  ACTIVATE_ON_BOOT = 2;
433}
434
435message EventActivation {
436  optional int64 atom_matcher_id = 1;
437  optional int64 ttl_seconds = 2;
438  optional int64 deactivation_atom_matcher_id = 3;
439  optional ActivationType activation_type = 4;
440}
441
442message MetricActivation {
443  optional int64 metric_id = 1;
444
445  optional ActivationType activation_type = 3 [deprecated = true];
446
447  repeated EventActivation event_activation = 2;
448}
449
450message PullAtomPackages {
451    optional int32 atom_id = 1;
452
453    repeated string packages = 2;
454}
455
456message StatsdConfig {
457  optional int64 id = 1;
458
459  repeated EventMetric event_metric = 2;
460
461  repeated CountMetric count_metric = 3;
462
463  repeated ValueMetric value_metric = 4;
464
465  repeated GaugeMetric gauge_metric = 5;
466
467  repeated DurationMetric duration_metric = 6;
468
469  repeated AtomMatcher atom_matcher = 7;
470
471  repeated Predicate predicate = 8;
472
473  repeated Alert alert = 9;
474
475  repeated Alarm alarm = 10;
476
477  repeated Subscription subscription = 11;
478
479  repeated string allowed_log_source = 12;
480
481  repeated int64 no_report_metric = 13;
482
483  message Annotation {
484    optional int64 field_int64 = 1;
485    optional int32 field_int32 = 2;
486  }
487  repeated Annotation annotation = 14;
488
489  optional int64 ttl_in_seconds = 15;
490
491  optional bool hash_strings_in_metric_report = 16 [default = true];
492
493  repeated MetricActivation metric_activation = 17;
494
495  optional bool version_strings_in_metric_report = 18;
496
497  optional bool installer_in_metric_report = 19;
498
499  optional bool persist_locally = 20 [default = false];
500
501  repeated State state = 21;
502
503  repeated string default_pull_packages = 22;
504
505  repeated PullAtomPackages pull_atom_packages = 23;
506
507  repeated int32 whitelisted_atom_ids = 24;
508
509  // Field number 1000 is reserved for later use.
510  reserved 1000;
511}
512