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