blob: 39c101cc248a4951de83e51acb39717e65247a93 [file] [log] [blame]
Yao Chenab273e22017-09-06 12:53:50 -07001/*
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
yro00698da2017-09-15 10:06:40 -070019#include <log/log_event_list.h>
yro00698da2017-09-15 10:06:40 -070020#include <parse_util.h>
Yao Chenef99c4f2017-09-22 16:26:54 -070021#include <utils/Errors.h>
Yao Chenab273e22017-09-06 12:53:50 -070022
23using namespace android;
Bookatz906a35c2017-09-20 15:26:44 -070024
25namespace android {
26namespace os {
27namespace statsd {
Yao Chenab273e22017-09-06 12:53:50 -070028
Yao Chenef99c4f2017-09-22 16:26:54 -070029StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs") {
Yao Chenab273e22017-09-06 12:53:50 -070030 // 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 Chenef99c4f2017-09-22 16:26:54 -070039StatsLogProcessor::~StatsLogProcessor() {
Yao Chenab273e22017-09-06 12:53:50 -070040 if (m_tags != NULL) {
41 android_closeEventTagMap(m_tags);
42 }
43 android_log_format_free(m_format);
44}
45
Yao Chenef99c4f2017-09-22 16:26:54 -070046void StatsLogProcessor::OnLogEvent(const log_msg& msg) {
Yao Chenab273e22017-09-06 12:53:50 -070047 status_t err;
48 AndroidLogEntry entry;
49 char buf[1024];
50
Yao Chenef99c4f2017-09-22 16:26:54 -070051 err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1), &entry,
52 m_tags, buf, sizeof(buf));
Yao Chenab273e22017-09-06 12:53:50 -070053
54 // dump all statsd logs to dropbox for now.
55 // TODO: Add filtering, aggregation, etc.
56 if (err == NO_ERROR) {
yro00698da2017-09-15 10:06:40 -070057 StatsLogReport logReport;
58 logReport.set_start_report_millis(entry.tv_sec / 1000 + entry.tv_nsec / 1000 / 1000);
Yao Chenef99c4f2017-09-22 16:26:54 -070059 EventMetricData* eventMetricData = logReport.mutable_event_metrics()->add_data();
yro00698da2017-09-15 10:06:40 -070060 *eventMetricData = parse(msg);
61
62 m_dropbox_writer.addStatsLogReport(logReport);
Yao Chenab273e22017-09-06 12:53:50 -070063 }
64}
65
Yao Chenef99c4f2017-09-22 16:26:54 -070066void StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config) {
David Chen0656b7a2017-09-13 15:53:39 -070067 m_configs[config_source] = config;
68 ALOGD("Updated configuration for source %i", config_source);
yro00698da2017-09-15 10:06:40 -070069}
Bookatz906a35c2017-09-20 15:26:44 -070070
Yao Chenef99c4f2017-09-22 16:26:54 -070071} // namespace statsd
72} // namespace os
73} // namespace android