blob: 1ae23ef8af1350b56cb731a05fec0db89feb096c [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>
Yao Chenab273e22017-09-06 12:53:50 -070020#include <utils/Errors.h>
yro00698da2017-09-15 10:06:40 -070021#include <parse_util.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
29StatsLogProcessor::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
40StatsLogProcessor::~StatsLogProcessor()
41{
42 if (m_tags != NULL) {
43 android_closeEventTagMap(m_tags);
44 }
45 android_log_format_free(m_format);
46}
47
48void
49StatsLogProcessor::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) {
yro00698da2017-09-15 10:06:40 -070061 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 Chenab273e22017-09-06 12:53:50 -070067 }
68}
69
David Chen0656b7a2017-09-13 15:53:39 -070070void
71StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config)
72{
73 m_configs[config_source] = config;
74 ALOGD("Updated configuration for source %i", config_source);
yro00698da2017-09-15 10:06:40 -070075}
Bookatz906a35c2017-09-20 15:26:44 -070076
77} // namespace statsd
78} // namespace os
79} // namespace android