Yao Chen | ab273e2 | 2017-09-06 12:53:50 -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 | #include <StatsLogProcessor.h> |
| 18 | |
| 19 | #include <log/event_tag_map.h> |
| 20 | #include <log/logprint.h> |
| 21 | #include <utils/Errors.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 22 | #include <cutils/log.h> |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 23 | #include <frameworks/base/cmds/statsd/src/stats_log.pb.h> |
| 24 | |
| 25 | using namespace android; |
| 26 | using android::os::statsd::StatsLogEntry; |
| 27 | |
| 28 | StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs") |
| 29 | { |
| 30 | // Initialize the EventTagMap, which is how we know the names of the numeric event tags. |
| 31 | // If this fails, we can't print well, but something will print. |
| 32 | m_tags = android_openEventTagMap(NULL); |
| 33 | |
| 34 | // Printing format |
| 35 | m_format = android_log_format_new(); |
| 36 | android_log_setPrintFormat(m_format, FORMAT_THREADTIME); |
| 37 | } |
| 38 | |
| 39 | StatsLogProcessor::~StatsLogProcessor() |
| 40 | { |
| 41 | if (m_tags != NULL) { |
| 42 | android_closeEventTagMap(m_tags); |
| 43 | } |
| 44 | android_log_format_free(m_format); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | StatsLogProcessor::OnLogEvent(const log_msg& msg) |
| 49 | { |
| 50 | status_t err; |
| 51 | AndroidLogEntry entry; |
| 52 | char buf[1024]; |
| 53 | |
| 54 | err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1), |
| 55 | &entry, m_tags, buf, sizeof(buf)); |
| 56 | |
| 57 | // dump all statsd logs to dropbox for now. |
| 58 | // TODO: Add filtering, aggregation, etc. |
| 59 | if (err == NO_ERROR) { |
| 60 | StatsLogEntry logEntry; |
| 61 | logEntry.set_uid(entry.uid); |
| 62 | logEntry.set_pid(entry.pid); |
| 63 | logEntry.set_start_report_millis(entry.tv_sec / 1000 + entry.tv_nsec / 1000 / 1000); |
| 64 | logEntry.add_pairs()->set_value_str(entry.message, entry.messageLen); |
| 65 | m_dropbox_writer.addEntry(logEntry); |
| 66 | } |
| 67 | } |
| 68 | |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 69 | void |
| 70 | StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config) |
| 71 | { |
| 72 | m_configs[config_source] = config; |
| 73 | ALOGD("Updated configuration for source %i", config_source); |
| 74 | } |