blob: c2fffd8a2d840bd7ebda6f01f609403bb662685f [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;
yro00698da2017-09-15 10:06:40 -070024using android::os::statsd::EventMetricData;
25using android::os::statsd::StatsLogReport;
Yao Chenab273e22017-09-06 12:53:50 -070026
27StatsLogProcessor::StatsLogProcessor() : m_dropbox_writer("all-logs")
28{
29 // Initialize the EventTagMap, which is how we know the names of the numeric event tags.
30 // If this fails, we can't print well, but something will print.
31 m_tags = android_openEventTagMap(NULL);
32
33 // Printing format
34 m_format = android_log_format_new();
35 android_log_setPrintFormat(m_format, FORMAT_THREADTIME);
36}
37
38StatsLogProcessor::~StatsLogProcessor()
39{
40 if (m_tags != NULL) {
41 android_closeEventTagMap(m_tags);
42 }
43 android_log_format_free(m_format);
44}
45
46void
47StatsLogProcessor::OnLogEvent(const log_msg& msg)
48{
49 status_t err;
50 AndroidLogEntry entry;
51 char buf[1024];
52
53 err = android_log_processBinaryLogBuffer(&(const_cast<log_msg*>(&msg)->entry_v1),
54 &entry, m_tags, buf, sizeof(buf));
55
56 // dump all statsd logs to dropbox for now.
57 // TODO: Add filtering, aggregation, etc.
58 if (err == NO_ERROR) {
yro00698da2017-09-15 10:06:40 -070059 StatsLogReport logReport;
60 logReport.set_start_report_millis(entry.tv_sec / 1000 + entry.tv_nsec / 1000 / 1000);
61 EventMetricData *eventMetricData = logReport.mutable_event_metrics()->add_data();
62 *eventMetricData = parse(msg);
63
64 m_dropbox_writer.addStatsLogReport(logReport);
Yao Chenab273e22017-09-06 12:53:50 -070065 }
66}
67
David Chen0656b7a2017-09-13 15:53:39 -070068void
69StatsLogProcessor::UpdateConfig(const int config_source, StatsdConfig config)
70{
71 m_configs[config_source] = config;
72 ALOGD("Updated configuration for source %i", config_source);
yro00698da2017-09-15 10:06:40 -070073}