| 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> |
| yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 20 | #include <parse_util.h> |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 21 | #include <utils/Errors.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 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 29 | StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs") { |
| Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 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 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 39 | StatsLogProcessor::~StatsLogProcessor() { |
| Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 40 | if (m_tags != NULL) { |
| 41 | android_closeEventTagMap(m_tags); |
| 42 | } |
| 43 | android_log_format_free(m_format); |
| 44 | } |
| 45 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 46 | void StatsLogProcessor::OnLogEvent(const log_msg& msg) { |
| Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 47 | status_t err; |
| 48 | AndroidLogEntry entry; |
| 49 | char buf[1024]; |
| 50 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 51 | err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1), &entry, |
| 52 | m_tags, buf, sizeof(buf)); |
| Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 53 | |
| 54 | // dump all statsd logs to dropbox for now. |
| 55 | // TODO: Add filtering, aggregation, etc. |
| 56 | if (err == NO_ERROR) { |
| yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 57 | StatsLogReport logReport; |
| 58 | logReport.set_start_report_millis(entry.tv_sec / 1000 + entry.tv_nsec / 1000 / 1000); |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 59 | EventMetricData* eventMetricData = logReport.mutable_event_metrics()->add_data(); |
| yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 60 | *eventMetricData = parse(msg); |
| 61 | |
| 62 | m_dropbox_writer.addStatsLogReport(logReport); |
| Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 66 | void StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config) { |
| David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 67 | m_configs[config_source] = config; |
| 68 | ALOGD("Updated configuration for source %i", config_source); |
| yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 69 | } |
| Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 70 | |
| Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame^] | 71 | } // namespace statsd |
| 72 | } // namespace os |
| 73 | } // namespace android |