Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 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 | |
| 17 | syntax = "proto2"; |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 18 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 19 | // TODO: Not the right package and class name |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 20 | package android.os.statsd; |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 21 | option java_package = "com.android.os"; |
| 22 | option java_outer_classname = "StatsEventProto"; |
| 23 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 24 | /** |
| 25 | * The master event class. This message defines all of the available |
| 26 | * raw stats log events from the Android system, also known as "atoms." |
| 27 | * |
| 28 | * This field contains a single oneof with all of the available messages. |
| 29 | * The stats-log-api-gen tool runs as part of the Android build and |
| 30 | * generates the android.util.StatsLog class, which contains the constants |
| 31 | * and methods that Android uses to log. |
| 32 | * |
| 33 | * This StatsEvent class is not actually built into the Android system. |
| 34 | * Instead, statsd on Android constructs these messages synthetically, |
| 35 | * in the format defined here and in stats_log.proto. |
| 36 | */ |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 37 | message StatsEvent { |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 38 | oneof event { |
| 39 | ScreenStateChanged screen_state_changed = 1; |
| 40 | ProcessStateChanged process_state_changed = 2; |
| 41 | WakeLockChanged wakelock_changed = 3; |
| 42 | } |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 45 | /** |
| 46 | * A WorkSource represents the chained attribution of applications that |
| 47 | * resulted in a particular bit of work being done. |
| 48 | */ |
| 49 | message WorkSource { |
| 50 | // TODO |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 53 | /* |
| 54 | * ***************************************************************************** |
| 55 | * Below are all of the individual atoms that are logged by Android via statsd |
| 56 | * and Westworld. |
| 57 | * |
| 58 | * RULES: |
| 59 | * - The field ids for each atom must start at 1, and count upwards by 1. |
| 60 | * Skipping field ids is not allowed. |
| 61 | * - These form an API, so renaming, renumbering or removing fields is |
| 62 | * not allowed between android releases. (This is not currently enforced, |
| 63 | * but there will be a tool to enforce this restriction). |
| 64 | * - The types must be built-in protocol buffer types, namely, no sub-messages |
| 65 | * are allowed (yet). The bytes type is also not allowed. |
| 66 | * - The CamelCase name of the message type should match the |
| 67 | * underscore_separated name as defined in StatsEvent. |
| 68 | * - If an atom represents work that can be attributed to an app, there can |
| 69 | * be exactly one WorkSource field. It must be field number 1. |
| 70 | * - A field that is a uid should be a string field, tagged with the [xxx] |
| 71 | * annotation. The generated code on android will be represented by UIDs, |
| 72 | * and those UIDs will be translated in xxx to those strings. |
| 73 | * |
| 74 | * CONVENTIONS: |
| 75 | * - Events are past tense. e.g. ScreenStateChanged, not ScreenStateChange |
| 76 | * - If there is a UID, it goes first. Think in an object-oriented fashion. |
| 77 | * ***************************************************************************** |
| 78 | */ |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 79 | |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 80 | /** |
| 81 | * Logs when the screen state changes. |
| 82 | * |
| 83 | * Logged from: |
| 84 | * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java |
| 85 | */ |
| 86 | message ScreenStateChanged { |
| 87 | // TODO: Use the real screen state. |
| 88 | enum State { |
| 89 | STATE_UNKNOWN = 0; |
| 90 | STATE_OFF = 1; |
| 91 | STATE_ON = 2; |
| 92 | STATE_DOZE = 3; |
| 93 | STATE_DOZE_SUSPEND = 4; |
| 94 | STATE_VR = 5; |
| 95 | } |
| 96 | // New screen state. |
| 97 | optional State display_state = 1; |
Stefan Lafon | cdb1a0e | 2017-09-27 20:24:15 -0700 | [diff] [blame] | 98 | } |
Yao Chen | d54f9dd | 2017-10-17 17:37:48 +0000 | [diff] [blame^] | 99 | |
| 100 | /** |
| 101 | * Logs that the state of a process state, as per the activity manager has changed. |
| 102 | * |
| 103 | * Logged from: |
| 104 | * frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java |
| 105 | */ |
| 106 | message ProcessStateChanged { |
| 107 | // TODO: Use the real (mapped) process states. |
| 108 | optional int32 uid = 1; // TODO: should be a string tagged w/ uid annotation |
| 109 | |
| 110 | // The state. |
| 111 | optional int32 state = 2; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Logs that the state of a wakelock has changed. |
| 116 | * |
| 117 | * Logged from: |
| 118 | * TODO |
| 119 | */ |
| 120 | message WakeLockChanged { |
| 121 | // TODO: Add attribution instead of uid. |
| 122 | optional int32 uid = 1; |
| 123 | |
| 124 | // The wakelock tag (Called tag in the Java API, sometimes name elsewhere). |
| 125 | optional string tag = 2; |
| 126 | |
| 127 | // TODO: Use a constant instead of boolean? |
| 128 | optional bool state = 3; |
| 129 | } |
| 130 | |