Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -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 | |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 17 | #define DEBUG false // STOPSHIP if true |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 18 | #include "logd/LogEvent.h" |
| 19 | |
| 20 | #include <sstream> |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 21 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 22 | #include "stats_log_util.h" |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace os { |
| 26 | namespace statsd { |
| 27 | |
yro | 24809bd | 2017-10-31 23:06:53 -0700 | [diff] [blame] | 28 | using namespace android::util; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 29 | using std::ostringstream; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 30 | using std::string; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 31 | using android::util::ProtoOutputStream; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 32 | |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 33 | LogEvent::LogEvent(log_msg& msg) { |
Chenjie Yu | 3ca3683 | 2018-01-22 15:10:54 -0800 | [diff] [blame] | 34 | mContext = |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 35 | create_android_log_parser(msg.msg() + sizeof(uint32_t), msg.len() - sizeof(uint32_t)); |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 36 | mLogdTimestampNs = msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec; |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 37 | mLogUid = msg.entry_v4.uid; |
Chenjie Yu | 3ca3683 | 2018-01-22 15:10:54 -0800 | [diff] [blame] | 38 | init(mContext); |
| 39 | if (mContext) { |
Yao Chen | 48d7518 | 2018-01-23 09:40:48 -0800 | [diff] [blame] | 40 | // android_log_destroy will set mContext to NULL |
Chenjie Yu | 3ca3683 | 2018-01-22 15:10:54 -0800 | [diff] [blame] | 41 | android_log_destroy(&mContext); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 42 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 45 | LogEvent::LogEvent(int32_t tagId, int64_t wallClockTimestampNs, int64_t elapsedTimestampNs) { |
| 46 | mLogdTimestampNs = wallClockTimestampNs; |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 47 | mTagId = tagId; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 48 | mLogUid = 0; |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 49 | mContext = create_android_logger(1937006964); // the event tag shared by all stats logs |
| 50 | if (mContext) { |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 51 | android_log_write_int64(mContext, elapsedTimestampNs); |
| 52 | android_log_write_int32(mContext, tagId); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | LogEvent::LogEvent(int32_t tagId, int64_t timestampNs) { |
| 57 | mLogdTimestampNs = timestampNs; |
| 58 | mTagId = tagId; |
| 59 | mLogUid = 0; |
| 60 | mContext = create_android_logger(1937006964); // the event tag shared by all stats logs |
| 61 | if (mContext) { |
| 62 | android_log_write_int64(mContext, timestampNs); |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 63 | android_log_write_int32(mContext, tagId); |
| 64 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 65 | } |
| 66 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 67 | void LogEvent::init() { |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 68 | if (mContext) { |
| 69 | const char* buffer; |
| 70 | size_t len = android_log_write_list_buffer(mContext, &buffer); |
| 71 | // turns to reader mode |
Chenjie Yu | c1fe6f4 | 2018-02-01 23:14:18 -0800 | [diff] [blame] | 72 | android_log_context contextForRead = create_android_log_parser(buffer, len); |
| 73 | if (contextForRead) { |
| 74 | init(contextForRead); |
| 75 | // destroy the context to save memory. |
Yao Chen | 48d7518 | 2018-01-23 09:40:48 -0800 | [diff] [blame] | 76 | // android_log_destroy will set mContext to NULL |
Chenjie Yu | c1fe6f4 | 2018-02-01 23:14:18 -0800 | [diff] [blame] | 77 | android_log_destroy(&contextForRead); |
Yao Chen | 48d7518 | 2018-01-23 09:40:48 -0800 | [diff] [blame] | 78 | } |
Chenjie Yu | c1fe6f4 | 2018-02-01 23:14:18 -0800 | [diff] [blame] | 79 | android_log_destroy(&mContext); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | LogEvent::~LogEvent() { |
| 84 | if (mContext) { |
Yao Chen | 48d7518 | 2018-01-23 09:40:48 -0800 | [diff] [blame] | 85 | // This is for the case when LogEvent is created using the test interface |
| 86 | // but init() isn't called. |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 87 | android_log_destroy(&mContext); |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | bool LogEvent::write(int32_t value) { |
| 92 | if (mContext) { |
| 93 | return android_log_write_int32(mContext, value) >= 0; |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool LogEvent::write(uint32_t value) { |
| 99 | if (mContext) { |
| 100 | return android_log_write_int32(mContext, value) >= 0; |
| 101 | } |
| 102 | return false; |
| 103 | } |
| 104 | |
Chenjie Yu | d9dfda7 | 2017-12-11 17:41:20 -0800 | [diff] [blame] | 105 | bool LogEvent::write(int64_t value) { |
| 106 | if (mContext) { |
| 107 | return android_log_write_int64(mContext, value) >= 0; |
| 108 | } |
| 109 | return false; |
| 110 | } |
| 111 | |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 112 | bool LogEvent::write(uint64_t value) { |
| 113 | if (mContext) { |
| 114 | return android_log_write_int64(mContext, value) >= 0; |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | bool LogEvent::write(const string& value) { |
| 120 | if (mContext) { |
| 121 | return android_log_write_string8_len(mContext, value.c_str(), value.length()) >= 0; |
| 122 | } |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool LogEvent::write(float value) { |
| 127 | if (mContext) { |
| 128 | return android_log_write_float32(mContext, value) >= 0; |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 133 | bool LogEvent::write(const std::vector<AttributionNode>& nodes) { |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 134 | if (mContext) { |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 135 | if (android_log_write_list_begin(mContext) < 0) { |
| 136 | return false; |
| 137 | } |
| 138 | for (size_t i = 0; i < nodes.size(); ++i) { |
| 139 | if (!write(nodes[i])) { |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | if (android_log_write_list_end(mContext) < 0) { |
| 144 | return false; |
| 145 | } |
| 146 | return true; |
| 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool LogEvent::write(const AttributionNode& node) { |
| 152 | if (mContext) { |
| 153 | if (android_log_write_list_begin(mContext) < 0) { |
| 154 | return false; |
| 155 | } |
| 156 | if (android_log_write_int32(mContext, node.uid()) < 0) { |
| 157 | return false; |
| 158 | } |
| 159 | if (android_log_write_string8(mContext, node.tag().c_str()) < 0) { |
| 160 | return false; |
| 161 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 162 | if (android_log_write_list_end(mContext) < 0) { |
| 163 | return false; |
| 164 | } |
| 165 | return true; |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 170 | /** |
| 171 | * The elements of each log event are stored as a vector of android_log_list_elements. |
| 172 | * The goal is to do as little preprocessing as possible, because we read a tiny fraction |
| 173 | * of the elements that are written to the log. |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 174 | * |
| 175 | * The idea here is to read through the log items once, we get as much information we need for |
| 176 | * matching as possible. Because this log will be matched against lots of matchers. |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 177 | */ |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 178 | void LogEvent::init(android_log_context context) { |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 179 | android_log_list_element elem; |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 180 | int i = 0; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 181 | int depth = -1; |
| 182 | int pos[] = {1, 1, 1}; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 183 | do { |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 184 | elem = android_log_read_next(context); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 185 | switch ((int)elem.type) { |
| 186 | case EVENT_TYPE_INT: |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 187 | // elem at [0] is EVENT_TYPE_LIST, [1] is the timestamp, [2] is tag id. |
| 188 | if (i == 2) { |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 189 | mTagId = elem.data.int32; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 190 | } else { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 191 | if (depth < 0 || depth > 2) { |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 192 | return; |
| 193 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 194 | |
| 195 | mValues.push_back( |
| 196 | FieldValue(Field(mTagId, pos, depth), Value((int32_t)elem.data.int32))); |
| 197 | |
| 198 | pos[depth]++; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 199 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 200 | break; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 201 | case EVENT_TYPE_FLOAT: { |
| 202 | if (depth < 0 || depth > 2) { |
| 203 | ALOGE("Depth > 2. Not supported!"); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | mValues.push_back(FieldValue(Field(mTagId, pos, depth), Value(elem.data.float32))); |
| 208 | |
| 209 | pos[depth]++; |
| 210 | |
| 211 | } break; |
| 212 | case EVENT_TYPE_STRING: { |
| 213 | if (depth < 0 || depth > 2) { |
| 214 | ALOGE("Depth > 2. Not supported!"); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | mValues.push_back(FieldValue(Field(mTagId, pos, depth), |
| 219 | Value(string(elem.data.string, elem.len)))); |
| 220 | |
| 221 | pos[depth]++; |
| 222 | |
| 223 | } break; |
| 224 | case EVENT_TYPE_LONG: { |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 225 | if (i == 1) { |
| 226 | mElapsedTimestampNs = elem.data.int64; |
| 227 | } else { |
| 228 | if (depth < 0 || depth > 2) { |
| 229 | ALOGE("Depth > 2. Not supported!"); |
| 230 | return; |
| 231 | } |
| 232 | mValues.push_back( |
| 233 | FieldValue(Field(mTagId, pos, depth), Value((int64_t)elem.data.int64))); |
| 234 | |
| 235 | pos[depth]++; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 236 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 237 | } break; |
| 238 | case EVENT_TYPE_LIST: |
| 239 | depth++; |
| 240 | if (depth > 2) { |
| 241 | ALOGE("Depth > 2. Not supported!"); |
| 242 | return; |
| 243 | } |
| 244 | pos[depth] = 1; |
| 245 | |
| 246 | break; |
| 247 | case EVENT_TYPE_LIST_STOP: { |
| 248 | int prevDepth = depth; |
| 249 | depth--; |
| 250 | if (depth >= 0 && depth < 2) { |
| 251 | // Now go back to decorate the previous items that are last at prevDepth. |
| 252 | // So that we can later easily match them with Position=Last matchers. |
| 253 | pos[prevDepth]--; |
| 254 | int path = getEncodedField(pos, prevDepth, false); |
Yao Chen | db43afc | 2018-02-13 09:37:27 -0800 | [diff] [blame] | 255 | for (auto it = mValues.rbegin(); it != mValues.rend(); ++it) { |
| 256 | if (it->mField.getDepth() >= prevDepth && |
| 257 | it->mField.getPath(prevDepth) == path) { |
| 258 | it->mField.decorateLastPos(prevDepth); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 259 | } else { |
| 260 | // Safe to break, because the items are in DFS order. |
| 261 | break; |
| 262 | } |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 263 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 264 | pos[depth]++; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 265 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 266 | break; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 267 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 268 | case EVENT_TYPE_UNKNOWN: |
| 269 | break; |
| 270 | default: |
| 271 | break; |
| 272 | } |
Yao Chen | 8023540 | 2017-11-13 20:42:25 -0800 | [diff] [blame] | 273 | i++; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 274 | } while ((elem.type != EVENT_TYPE_UNKNOWN) && !elem.complete); |
| 275 | } |
| 276 | |
| 277 | int64_t LogEvent::GetLong(size_t key, status_t* err) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 278 | // TODO: encapsulate the magical operations all in Field struct as a static function. |
| 279 | int field = getSimpleField(key); |
| 280 | for (const auto& value : mValues) { |
| 281 | if (value.mField.getField() == field) { |
Yao Chen | ab92a1f | 2018-02-13 15:17:55 -0800 | [diff] [blame] | 282 | if (value.mValue.getType() == LONG) { |
| 283 | return value.mValue.long_value; |
| 284 | } else if (value.mValue.getType() == INT) { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 285 | return value.mValue.int_value; |
| 286 | } else { |
| 287 | *err = BAD_TYPE; |
| 288 | return 0; |
| 289 | } |
| 290 | } |
| 291 | if ((size_t)value.mField.getPosAtDepth(0) > key) { |
| 292 | break; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 293 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 294 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 295 | |
| 296 | *err = BAD_INDEX; |
| 297 | return 0; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 300 | int LogEvent::GetInt(size_t key, status_t* err) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 301 | int field = getSimpleField(key); |
| 302 | for (const auto& value : mValues) { |
| 303 | if (value.mField.getField() == field) { |
| 304 | if (value.mValue.getType() == INT) { |
| 305 | return value.mValue.int_value; |
| 306 | } else { |
| 307 | *err = BAD_TYPE; |
| 308 | return 0; |
| 309 | } |
| 310 | } |
| 311 | if ((size_t)value.mField.getPosAtDepth(0) > key) { |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 316 | *err = BAD_INDEX; |
| 317 | return 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 320 | const char* LogEvent::GetString(size_t key, status_t* err) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 321 | int field = getSimpleField(key); |
| 322 | for (const auto& value : mValues) { |
| 323 | if (value.mField.getField() == field) { |
| 324 | if (value.mValue.getType() == STRING) { |
| 325 | return value.mValue.str_value.c_str(); |
| 326 | } else { |
| 327 | *err = BAD_TYPE; |
| 328 | return 0; |
| 329 | } |
| 330 | } |
| 331 | if ((size_t)value.mField.getPosAtDepth(0) > key) { |
| 332 | break; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 333 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 334 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 335 | |
| 336 | *err = BAD_INDEX; |
| 337 | return NULL; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | bool LogEvent::GetBool(size_t key, status_t* err) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 341 | int field = getSimpleField(key); |
| 342 | for (const auto& value : mValues) { |
| 343 | if (value.mField.getField() == field) { |
| 344 | if (value.mValue.getType() == INT) { |
| 345 | return value.mValue.int_value != 0; |
| 346 | } else if (value.mValue.getType() == LONG) { |
| 347 | return value.mValue.long_value != 0; |
| 348 | } else { |
| 349 | *err = BAD_TYPE; |
| 350 | return false; |
| 351 | } |
| 352 | } |
| 353 | if ((size_t)value.mField.getPosAtDepth(0) > key) { |
| 354 | break; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 355 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 356 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 357 | |
| 358 | *err = BAD_INDEX; |
| 359 | return false; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | float LogEvent::GetFloat(size_t key, status_t* err) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 363 | int field = getSimpleField(key); |
| 364 | for (const auto& value : mValues) { |
| 365 | if (value.mField.getField() == field) { |
| 366 | if (value.mValue.getType() == FLOAT) { |
| 367 | return value.mValue.float_value; |
| 368 | } else { |
| 369 | *err = BAD_TYPE; |
| 370 | return 0.0; |
| 371 | } |
| 372 | } |
| 373 | if ((size_t)value.mField.getPosAtDepth(0) > key) { |
| 374 | break; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 375 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 376 | } |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 377 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 378 | *err = BAD_INDEX; |
| 379 | return 0.0; |
Yangster-mac | d40053e | 2018-01-09 16:29:22 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 382 | string LogEvent::ToString() const { |
| 383 | ostringstream result; |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 384 | result << "{ " << mLogdTimestampNs << " " << mElapsedTimestampNs << " (" << mTagId << ")"; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 385 | for (const auto& value : mValues) { |
| 386 | result << StringPrintf("%#x", value.mField.getField()); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 387 | result << "->"; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 388 | result << value.mValue.toString(); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 389 | result << " "; |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 390 | } |
| 391 | result << " }"; |
| 392 | return result.str(); |
| 393 | } |
| 394 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 395 | void LogEvent::ToProto(ProtoOutputStream& protoOutput) const { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 396 | writeFieldValueTreeToStream(mTagId, getValues(), &protoOutput); |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | } // namespace statsd |
| 400 | } // namespace os |
| 401 | } // namespace android |