• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <log/log_event_list.h>
18 #include <stats_event_list.h>
19 #include <cstdint>
20 #include <string>
21 
22 namespace android {
23 namespace metricslogger {
24 
25 // Logs a Tron histogram metric named |event| containing |data| to the Tron log
26 // buffer.
27 void LogHistogram(const std::string& event, int32_t data);
28 
29 // Logs a Tron counter metric named |name| containing |val| count to the Tron
30 // log buffer.
31 void LogCounter(const std::string& name, int32_t val);
32 
33 // Logs a Tron multi_action with category|category| containing the string
34 // |value| in the field |field|.
35 void LogMultiAction(int32_t category, int32_t field, const std::string& value);
36 
37 // Logs a Tron complex event.
38 //
39 // A complex event can include data in a structure not suppored by the other
40 // log event types above.
41 //
42 // Note that instances of this class are single use. You must call Record()
43 // to write the event to the event log.
44 class ComplexEventLogger {
45   private:
46     android_log_event_list logger;
47     stats_event_list stats_logger;
48 
49   public:
50     // Create a complex event with category|category|.
51     explicit ComplexEventLogger(int category);
52     // Set the package name that this event originates from.
53     void SetPackageName(const std::string& package_name);
54     // Add tagged data to the event, with the given tag and integer value.
55     void AddTaggedData(int tag, int32_t value);
56     // Add tagged data to the event, with the given tag and string value.
57     void AddTaggedData(int tag, const std::string& value);
58     // Add tagged data to the event, with the given tag and integer value.
59     void AddTaggedData(int tag, int64_t value);
60     // Add tagged data to the event, with the given tag and float value.
61     void AddTaggedData(int tag, float value);
62     // Record this event. This method can only be used once per instance
63     // of ComplexEventLogger. Do not made any subsequent calls to AddTaggedData
64     // after recording an event.
65     void Record();
66 };
67 
68 // TODO: replace these with the metric_logger.proto definitions
69 enum {
70     LOGBUILDER_CATEGORY = 757,
71     LOGBUILDER_TYPE = 758,
72     LOGBUILDER_NAME = 799,
73     LOGBUILDER_BUCKET = 801,
74     LOGBUILDER_VALUE = 802,
75     LOGBUILDER_COUNTER = 803,
76     LOGBUILDER_HISTOGRAM = 804,
77     LOGBUILDER_PACKAGENAME = 806,
78 
79     ACTION_BOOT = 1098,
80     FIELD_PLATFORM_REASON = 1099,
81 
82     FIELD_DURATION_MILLIS = 1304,
83 
84     FIELD_END_BATTERY_PERCENT = 1308,
85 
86     ACTION_HIDDEN_API_ACCESSED = 1391,
87     FIELD_HIDDEN_API_ACCESS_METHOD = 1392,
88     FIELD_HIDDEN_API_ACCESS_DENIED = 1393,
89     FIELD_HIDDEN_API_SIGNATURE = 1394,
90 
91     ACTION_USB_CONNECTOR_CONNECTED = 1422,
92     ACTION_USB_CONNECTOR_DISCONNECTED = 1423,
93     ACTION_USB_AUDIO_CONNECTED = 1424,
94     FIELD_USB_AUDIO_VIDPID = 1425,
95     ACTION_USB_AUDIO_DISCONNECTED = 1426,
96     ACTION_HARDWARE_FAILED = 1427,
97     FIELD_HARDWARE_TYPE = 1428,
98     FIELD_HARDWARE_FAILURE_CODE = 1429,
99     ACTION_PHYSICAL_DROP = 1430,
100     FIELD_CONFIDENCE_PERCENT = 1431,
101     FIELD_ACCEL_MILLI_G = 1432,
102     ACTION_BATTERY_HEALTH = 1433,
103     FIELD_BATTERY_HEALTH_SNAPSHOT_TYPE = 1434,
104     FIELD_BATTERY_TEMPERATURE_DECI_C = 1435,
105     FIELD_BATTERY_VOLTAGE_UV = 1436,
106     FIELD_BATTERY_OPEN_CIRCUIT_VOLTAGE_UV = 1437,
107     ACTION_BATTERY_CHARGE_CYCLES = 1438,
108     FIELD_BATTERY_CHARGE_CYCLES = 1439,
109 
110     ACTION_SLOW_IO = 1442,
111     FIELD_IO_OPERATION_TYPE = 1443,
112     FIELD_IO_OPERATION_COUNT = 1444,
113     ACTION_SPEAKER_IMPEDANCE = 1445,
114     FIELD_SPEAKER_IMPEDANCE_MILLIOHMS = 1446,
115     FIELD_SPEAKER_LOCATION = 1447,
116     FIELD_BATTERY_RESISTANCE_UOHMS = 1448,
117     FIELD_BATTERY_CURRENT_UA = 1449,
118     FIELD_HARDWARE_LOCATION = 1450,
119     ACTION_BATTERY_CAUSED_SHUTDOWN = 1451,
120 };
121 
122 enum {
123     TYPE_ACTION = 4,
124 };
125 
126 enum {
127     ACCESS_METHOD_NONE = 0,
128     ACCESS_METHOD_REFLECTION = 1,
129     ACCESS_METHOD_JNI = 2,
130     ACCESS_METHOD_LINKING = 3,
131 };
132 
133 enum HardwareType {
134     HARDWARE_UNKNOWN = 0,
135     HARDWARE_MICROPHONE = 1,
136     HARDWARE_CODEC = 2,
137     HARDWARE_SPEAKER = 3,
138     HARDWARE_FINGERPRINT = 4,
139 };
140 
141 enum HardwareFailureCode {
142     HARDWARE_FAILURE_UNKNOWN = 0,
143     HARDWARE_FAILURE_COMPLETE = 1,
144     HARDWARE_FAILURE_SPEAKER_HIGH_Z = 2,
145     HARDWARE_FAILURE_SPEAKER_SHORT = 3,
146     HARDWARE_FAILURE_FINGERPRINT_SENSOR_BROKEN = 4,
147     HARDWARE_FAILURE_FINGERPRINT_TOO_MANY_DEAD_PIXELS = 5,
148 };
149 
150 enum IoOperation {
151     IOOP_UNKNOWN = 0,
152     IOOP_READ = 1,
153     IOOP_WRITE = 2,
154     IOOP_UNMAP = 3,
155     IOOP_SYNC = 4,
156 };
157 
158 }  // namespace metricslogger
159 }  // namespace android
160