blob: 87dec5d1656d250523df53aad7530a1ca216cb9f [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
Yao Chen8a8d16c2018-02-08 14:50:40 -080017#define DEBUG true // STOPSHIP if true
Joe Onorato9fc9edf2017-10-15 20:08:52 -070018#include "Log.h"
David Chen21582962017-11-01 17:32:46 -070019#include "statslog.h"
Yao Chenab273e22017-09-06 12:53:50 -070020
yro947fbce2017-11-15 22:50:23 -080021#include <android-base/file.h>
22#include <dirent.h>
Joe Onorato9fc9edf2017-10-15 20:08:52 -070023#include "StatsLogProcessor.h"
Yangster-mac330af582018-02-08 15:24:38 -080024#include "stats_log_util.h"
yro947fbce2017-11-15 22:50:23 -080025#include "android-base/stringprintf.h"
Yao Chenb3561512017-11-21 18:07:17 -080026#include "guardrail/StatsdStats.h"
Joe Onorato9fc9edf2017-10-15 20:08:52 -070027#include "metrics/CountMetricProducer.h"
Chenjie Yu85ed8382017-12-14 16:48:54 -080028#include "external/StatsPullerManager.h"
Joe Onorato9fc9edf2017-10-15 20:08:52 -070029#include "stats_util.h"
yro947fbce2017-11-15 22:50:23 -080030#include "storage/StorageManager.h"
Joe Onorato9fc9edf2017-10-15 20:08:52 -070031
yro00698da2017-09-15 10:06:40 -070032#include <log/log_event_list.h>
Yao Chenef99c4f2017-09-22 16:26:54 -070033#include <utils/Errors.h>
David Chen16049572018-02-01 18:27:51 -080034#include <utils/SystemClock.h>
Yao Chenab273e22017-09-06 12:53:50 -070035
36using namespace android;
yro947fbce2017-11-15 22:50:23 -080037using android::base::StringPrintf;
yrob0378b02017-11-09 20:36:25 -080038using android::util::FIELD_COUNT_REPEATED;
yro17adac92017-11-08 23:16:29 -080039using android::util::FIELD_TYPE_BOOL;
40using android::util::FIELD_TYPE_FLOAT;
41using android::util::FIELD_TYPE_INT32;
42using android::util::FIELD_TYPE_INT64;
43using android::util::FIELD_TYPE_MESSAGE;
44using android::util::FIELD_TYPE_STRING;
45using android::util::ProtoOutputStream;
Yao Chen44cf27c2017-09-14 22:32:50 -070046using std::make_unique;
47using std::unique_ptr;
48using std::vector;
Bookatz906a35c2017-09-20 15:26:44 -070049
50namespace android {
51namespace os {
52namespace statsd {
Yao Chenab273e22017-09-06 12:53:50 -070053
yro947fbce2017-11-15 22:50:23 -080054// for ConfigMetricsReportList
yro17adac92017-11-08 23:16:29 -080055const int FIELD_ID_CONFIG_KEY = 1;
yro947fbce2017-11-15 22:50:23 -080056const int FIELD_ID_REPORTS = 2;
yro17adac92017-11-08 23:16:29 -080057// for ConfigKey
58const int FIELD_ID_UID = 1;
Yangster-mac94e197c2018-01-02 16:03:03 -080059const int FIELD_ID_ID = 2;
yro947fbce2017-11-15 22:50:23 -080060// for ConfigMetricsReport
Yao Chen4c959cb2018-02-13 13:27:48 -080061// const int FIELD_ID_METRICS = 1; // written in MetricsManager.cpp
yro947fbce2017-11-15 22:50:23 -080062const int FIELD_ID_UID_MAP = 2;
Yangster-mac330af582018-02-08 15:24:38 -080063const int FIELD_ID_LAST_REPORT_ELAPSED_NANOS = 3;
64const int FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS = 4;
yro947fbce2017-11-15 22:50:23 -080065
yro03faf092017-12-12 00:17:50 -080066#define STATS_DATA_DIR "/data/misc/stats-data"
yro17adac92017-11-08 23:16:29 -080067
yro31eb67b2017-10-24 13:33:21 -070068StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap,
Yangster-mace2cd6d52017-11-09 20:38:30 -080069 const sp<AnomalyMonitor>& anomalyMonitor,
Yangster-mac20877162017-12-22 17:19:39 -080070 const long timeBaseSec,
David Chen1d7b0cd2017-11-15 14:20:04 -080071 const std::function<void(const ConfigKey&)>& sendBroadcast)
Chenjie Yu85ed8382017-12-14 16:48:54 -080072 : mUidMap(uidMap),
73 mAnomalyMonitor(anomalyMonitor),
74 mSendBroadcast(sendBroadcast),
Yangster-mac20877162017-12-22 17:19:39 -080075 mTimeBaseSec(timeBaseSec) {
Chenjie Yu85ed8382017-12-14 16:48:54 -080076 StatsPullerManager statsPullerManager;
77 statsPullerManager.SetTimeBaseSec(mTimeBaseSec);
Yao Chenab273e22017-09-06 12:53:50 -070078}
79
Yao Chenef99c4f2017-09-22 16:26:54 -070080StatsLogProcessor::~StatsLogProcessor() {
Yao Chenab273e22017-09-06 12:53:50 -070081}
82
Yangster-mace2cd6d52017-11-09 20:38:30 -080083void StatsLogProcessor::onAnomalyAlarmFired(
84 const uint64_t timestampNs,
85 unordered_set<sp<const AnomalyAlarm>, SpHash<AnomalyAlarm>> anomalySet) {
Yangster-macb0d06282018-01-05 15:44:07 -080086 std::lock_guard<std::mutex> lock(mMetricsMutex);
Bookatzcc5adef22017-11-21 14:36:23 -080087 for (const auto& itr : mMetricsManagers) {
88 itr.second->onAnomalyAlarmFired(timestampNs, anomalySet);
Yangster-mace2cd6d52017-11-09 20:38:30 -080089 }
90}
91
Yao Chen8a8d16c2018-02-08 14:50:40 -080092void updateUid(Value* value, int hostUid) {
93 int uid = value->int_value;
94 if (uid != hostUid) {
95 value->setInt(hostUid);
96 }
97}
98
Yangster-macd40053e2018-01-09 16:29:22 -080099void StatsLogProcessor::mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const {
Yangster-mac68985802018-01-21 10:05:09 -0800100 if (android::util::kAtomsWithAttributionChain.find(event->GetTagId()) !=
101 android::util::kAtomsWithAttributionChain.end()) {
Yao Chen8a8d16c2018-02-08 14:50:40 -0800102 for (auto& value : *(event->getMutableValues())) {
103 if (value.mField.getPosAtDepth(0) > kAttributionField) {
104 break;
105 }
106 if (isAttributionUidField(value)) {
107 const int hostUid = mUidMap->getHostUidOrSelf(value.mValue.int_value);
108 updateUid(&value.mValue, hostUid);
109 }
Yangster-macd40053e2018-01-09 16:29:22 -0800110 }
Yao Chen8a8d16c2018-02-08 14:50:40 -0800111 } else if (android::util::kAtomsWithUidField.find(event->GetTagId()) !=
112 android::util::kAtomsWithUidField.end() &&
113 event->getValues().size() > 0 && (event->getValues())[0].mValue.getType() == INT) {
114 Value& value = (*event->getMutableValues())[0].mValue;
115 const int hostUid = mUidMap->getHostUidOrSelf(value.int_value);
116 updateUid(&value, hostUid);
Yao Chen312e8982017-12-05 15:29:03 -0800117 }
Yangster-macd40053e2018-01-09 16:29:22 -0800118}
119
120void StatsLogProcessor::onIsolatedUidChangedEventLocked(const LogEvent& event) {
121 status_t err = NO_ERROR, err2 = NO_ERROR, err3 = NO_ERROR;
122 bool is_create = event.GetBool(3, &err);
123 auto parent_uid = int(event.GetLong(1, &err2));
124 auto isolated_uid = int(event.GetLong(2, &err3));
125 if (err == NO_ERROR && err2 == NO_ERROR && err3 == NO_ERROR) {
126 if (is_create) {
127 mUidMap->assignIsolatedUid(isolated_uid, parent_uid);
128 } else {
129 mUidMap->removeIsolatedUid(isolated_uid, parent_uid);
130 }
131 } else {
132 ALOGE("Failed to parse uid in the isolated uid change event.");
133 }
134}
135
136// TODO: what if statsd service restarts? How do we know what logs are already processed before?
137void StatsLogProcessor::OnLogEvent(LogEvent* event) {
138 std::lock_guard<std::mutex> lock(mMetricsMutex);
139 StatsdStats::getInstance().noteAtomLogged(
Yangster-mac330af582018-02-08 15:24:38 -0800140 event->GetTagId(), event->GetElapsedTimestampNs() / NS_PER_SEC);
Yangster-macd40053e2018-01-09 16:29:22 -0800141
David Chen21582962017-11-01 17:32:46 -0700142 // Hard-coded logic to update the isolated uid's in the uid-map.
Stefan Lafonae2df012017-11-14 09:17:21 -0800143 // The field numbers need to be currently updated by hand with atoms.proto
Yangster-macd40053e2018-01-09 16:29:22 -0800144 if (event->GetTagId() == android::util::ISOLATED_UID_CHANGED) {
145 onIsolatedUidChangedEventLocked(*event);
David Chencfc311d2018-01-23 17:55:54 -0800146 }
147
148 if (mMetricsManagers.empty()) {
149 return;
150 }
151
Yangster-mac330af582018-02-08 15:24:38 -0800152 uint64_t curTimeSec = getElapsedRealtimeSec();
153 if (curTimeSec - mLastPullerCacheClearTimeSec > StatsdStats::kPullerCacheClearIntervalSec) {
154 mStatsPullerManager.ClearPullerCacheIfNecessary(curTimeSec);
155 mLastPullerCacheClearTimeSec = curTimeSec;
Chenjie Yufa22d652018-02-05 14:37:48 -0800156 }
157
David Chencfc311d2018-01-23 17:55:54 -0800158 if (event->GetTagId() != android::util::ISOLATED_UID_CHANGED) {
Yangster-macd40053e2018-01-09 16:29:22 -0800159 // Map the isolated uid to host uid if necessary.
160 mapIsolatedUidToHostUidIfNecessaryLocked(event);
161 }
162
163 // pass the event to metrics managers.
164 for (auto& pair : mMetricsManagers) {
165 pair.second->onLogEvent(*event);
Yangster-mac330af582018-02-08 15:24:38 -0800166 flushIfNecessaryLocked(event->GetElapsedTimestampNs(), pair.first, *(pair.second));
David Chen21582962017-11-01 17:32:46 -0700167 }
Yao Chenab273e22017-09-06 12:53:50 -0700168}
169
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700170void StatsLogProcessor::OnConfigUpdated(const ConfigKey& key, const StatsdConfig& config) {
Yangster-macb0d06282018-01-05 15:44:07 -0800171 std::lock_guard<std::mutex> lock(mMetricsMutex);
Tej Singh484524a2018-02-01 15:10:05 -0800172 VLOG("Updated configuration for key %s", key.ToString().c_str());
Yao Chend10f7b12017-12-18 12:53:50 -0800173 sp<MetricsManager> newMetricsManager = new MetricsManager(key, config, mTimeBaseSec, mUidMap);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700174 auto it = mMetricsManagers.find(key);
Yao Chen288c6002017-12-12 13:43:18 -0800175 if (it == mMetricsManagers.end() && mMetricsManagers.size() > StatsdStats::kMaxConfigCount) {
Yao Chenb3561512017-11-21 18:07:17 -0800176 ALOGE("Can't accept more configs!");
177 return;
Yao Chen44cf27c2017-09-14 22:32:50 -0700178 }
179
Yao Chencaf339d2017-10-06 16:01:10 -0700180 if (newMetricsManager->isConfigValid()) {
David Chend6896892017-10-25 11:49:03 -0700181 mUidMap->OnConfigUpdated(key);
Yangster-mace2cd6d52017-11-09 20:38:30 -0800182 newMetricsManager->setAnomalyMonitor(mAnomalyMonitor);
Yao Chen147ce602017-12-22 14:35:34 -0800183 if (newMetricsManager->shouldAddUidMapListener()) {
Yao Chend10f7b12017-12-18 12:53:50 -0800184 // We have to add listener after the MetricsManager is constructed because it's
185 // not safe to create wp or sp from this pointer inside its constructor.
186 mUidMap->addListener(newMetricsManager.get());
187 }
188 mMetricsManagers[key] = newMetricsManager;
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700189 // Why doesn't this work? mMetricsManagers.insert({key, std::move(newMetricsManager)});
Yao Chenb3561512017-11-21 18:07:17 -0800190 VLOG("StatsdConfig valid");
Yao Chencaf339d2017-10-06 16:01:10 -0700191 } else {
192 // If there is any error in the config, don't use it.
Yao Chenb3561512017-11-21 18:07:17 -0800193 ALOGE("StatsdConfig NOT valid");
Yao Chencaf339d2017-10-06 16:01:10 -0700194 }
yro00698da2017-09-15 10:06:40 -0700195}
Bookatz906a35c2017-09-20 15:26:44 -0700196
Yangster7c334a12017-11-22 14:24:24 -0800197size_t StatsLogProcessor::GetMetricsSize(const ConfigKey& key) const {
Yangster-macb0d06282018-01-05 15:44:07 -0800198 std::lock_guard<std::mutex> lock(mMetricsMutex);
Yao Chen729093d2017-10-16 10:33:26 -0700199 auto it = mMetricsManagers.find(key);
200 if (it == mMetricsManagers.end()) {
201 ALOGW("Config source %s does not exist", key.ToString().c_str());
David Chen1d7b0cd2017-11-15 14:20:04 -0800202 return 0;
Yao Chen729093d2017-10-16 10:33:26 -0700203 }
David Chen1d7b0cd2017-11-15 14:20:04 -0800204 return it->second->byteSize();
205}
206
Yao Chen884c8c12018-01-26 10:36:25 -0800207void StatsLogProcessor::dumpStates(FILE* out, bool verbose) {
208 std::lock_guard<std::mutex> lock(mMetricsMutex);
209 fprintf(out, "MetricsManager count: %lu\n", (unsigned long)mMetricsManagers.size());
210 for (auto metricsManager : mMetricsManagers) {
211 metricsManager.second->dumpStates(out, verbose);
212 }
213}
214
Yao Chen8a8d16c2018-02-08 14:50:40 -0800215void StatsLogProcessor::onDumpReport(const ConfigKey& key, const uint64_t dumpTimeStampNs,
216 vector<uint8_t>* outData) {
Yangster-macb0d06282018-01-05 15:44:07 -0800217 std::lock_guard<std::mutex> lock(mMetricsMutex);
Yao Chen8a8d16c2018-02-08 14:50:40 -0800218 onDumpReportLocked(key, dumpTimeStampNs, outData);
Yangster-mac20877162017-12-22 17:19:39 -0800219}
220
Yao Chen8a8d16c2018-02-08 14:50:40 -0800221void StatsLogProcessor::onDumpReportLocked(const ConfigKey& key, const uint64_t dumpTimeStampNs,
222 vector<uint8_t>* outData) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800223 auto it = mMetricsManagers.find(key);
224 if (it == mMetricsManagers.end()) {
225 ALOGW("Config source %s does not exist", key.ToString().c_str());
226 return;
227 }
228
229 // This allows another broadcast to be sent within the rate-limit period if we get close to
230 // filling the buffer again soon.
David Chen1d7b0cd2017-11-15 14:20:04 -0800231 mLastBroadcastTimes.erase(key);
Yao Chen729093d2017-10-16 10:33:26 -0700232
yro17adac92017-11-08 23:16:29 -0800233 ProtoOutputStream proto;
234
yro947fbce2017-11-15 22:50:23 -0800235 // Start of ConfigKey.
yro17adac92017-11-08 23:16:29 -0800236 long long configKeyToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_CONFIG_KEY);
237 proto.write(FIELD_TYPE_INT32 | FIELD_ID_UID, key.GetUid());
Yangster-mac94e197c2018-01-02 16:03:03 -0800238 proto.write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)key.GetId());
yro17adac92017-11-08 23:16:29 -0800239 proto.end(configKeyToken);
yro947fbce2017-11-15 22:50:23 -0800240 // End of ConfigKey.
yro17adac92017-11-08 23:16:29 -0800241
yro947fbce2017-11-15 22:50:23 -0800242 // Start of ConfigMetricsReport (reports).
243 long long reportsToken =
244 proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS);
245
Yangster-mac330af582018-02-08 15:24:38 -0800246 int64_t lastReportTimeNs = it->second->getLastReportTimeNs();
yro947fbce2017-11-15 22:50:23 -0800247 // First, fill in ConfigMetricsReport using current data on memory, which
248 // starts from filling in StatsLogReport's.
Yao Chen8a8d16c2018-02-08 14:50:40 -0800249 it->second->onDumpReport(dumpTimeStampNs, &proto);
yro17adac92017-11-08 23:16:29 -0800250
251 // Fill in UidMap.
252 auto uidMap = mUidMap->getOutput(key);
253 const int uidMapSize = uidMap.ByteSize();
254 char uidMapBuffer[uidMapSize];
255 uidMap.SerializeToArray(&uidMapBuffer[0], uidMapSize);
256 proto.write(FIELD_TYPE_MESSAGE | FIELD_ID_UID_MAP, uidMapBuffer, uidMapSize);
257
David Chen16049572018-02-01 18:27:51 -0800258 // Fill in the timestamps.
Yangster-mac330af582018-02-08 15:24:38 -0800259 proto.write(FIELD_TYPE_INT64 | FIELD_ID_LAST_REPORT_ELAPSED_NANOS,
260 (long long)lastReportTimeNs);
261 proto.write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS,
262 (long long)dumpTimeStampNs);
David Chen16049572018-02-01 18:27:51 -0800263
yro947fbce2017-11-15 22:50:23 -0800264 // End of ConfigMetricsReport (reports).
265 proto.end(reportsToken);
266
267 // Then, check stats-data directory to see there's any file containing
268 // ConfigMetricsReport from previous shutdowns to concatenate to reports.
yro98a28502018-01-18 17:00:14 -0800269 StorageManager::appendConfigMetricsReport(proto);
yro947fbce2017-11-15 22:50:23 -0800270
David Chen1d7b0cd2017-11-15 14:20:04 -0800271 if (outData != nullptr) {
272 outData->clear();
273 outData->resize(proto.size());
274 size_t pos = 0;
275 auto iter = proto.data();
276 while (iter.readBuffer() != NULL) {
277 size_t toRead = iter.currentToRead();
278 std::memcpy(&((*outData)[pos]), iter.readBuffer(), toRead);
279 pos += toRead;
280 iter.rp()->move(toRead);
281 }
yro17adac92017-11-08 23:16:29 -0800282 }
Yao Chen8a8d16c2018-02-08 14:50:40 -0800283
Yao Chen69f1baf2017-11-27 17:25:36 -0800284 StatsdStats::getInstance().noteMetricsReportSent(key);
Yao Chen729093d2017-10-16 10:33:26 -0700285}
286
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700287void StatsLogProcessor::OnConfigRemoved(const ConfigKey& key) {
Yangster-macb0d06282018-01-05 15:44:07 -0800288 std::lock_guard<std::mutex> lock(mMetricsMutex);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700289 auto it = mMetricsManagers.find(key);
290 if (it != mMetricsManagers.end()) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700291 mMetricsManagers.erase(it);
David Chend6896892017-10-25 11:49:03 -0700292 mUidMap->OnConfigRemoved(key);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700293 }
Yao Chenb3561512017-11-21 18:07:17 -0800294 StatsdStats::getInstance().noteConfigRemoved(key);
David Chen1d7b0cd2017-11-15 14:20:04 -0800295
David Chen1d7b0cd2017-11-15 14:20:04 -0800296 mLastBroadcastTimes.erase(key);
Chenjie Yufa22d652018-02-05 14:37:48 -0800297
298 if (mMetricsManagers.empty()) {
299 mStatsPullerManager.ForceClearPullerCache();
300 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700301}
302
Yangster-macb0d06282018-01-05 15:44:07 -0800303void StatsLogProcessor::flushIfNecessaryLocked(
304 uint64_t timestampNs, const ConfigKey& key, MetricsManager& metricsManager) {
David Chend9269e22017-12-05 13:43:51 -0800305 auto lastCheckTime = mLastByteSizeTimes.find(key);
306 if (lastCheckTime != mLastByteSizeTimes.end()) {
307 if (timestampNs - lastCheckTime->second < StatsdStats::kMinByteSizeCheckPeriodNs) {
308 return;
309 }
310 }
311
312 // We suspect that the byteSize() computation is expensive, so we set a rate limit.
313 size_t totalBytes = metricsManager.byteSize();
314 mLastByteSizeTimes[key] = timestampNs;
315 if (totalBytes >
316 StatsdStats::kMaxMetricsBytesPerConfig) { // Too late. We need to start clearing data.
Yao Chen288c6002017-12-12 13:43:18 -0800317 // TODO(b/70571383): By 12/15/2017 add API to drop data directly
318 ProtoOutputStream proto;
Yao Chen8a8d16c2018-02-08 14:50:40 -0800319 metricsManager.onDumpReport(time(nullptr) * NS_PER_SEC, &proto);
David Chen12942952017-12-04 14:28:43 -0800320 StatsdStats::getInstance().noteDataDropped(key);
321 VLOG("StatsD had to toss out metrics for %s", key.ToString().c_str());
David Chend9269e22017-12-05 13:43:51 -0800322 } else if (totalBytes > .9 * StatsdStats::kMaxMetricsBytesPerConfig) {
323 // Send broadcast so that receivers can pull data.
324 auto lastBroadcastTime = mLastBroadcastTimes.find(key);
325 if (lastBroadcastTime != mLastBroadcastTimes.end()) {
326 if (timestampNs - lastBroadcastTime->second < StatsdStats::kMinBroadcastPeriodNs) {
327 VLOG("StatsD would've sent a broadcast but the rate limit stopped us.");
David Chen1d7b0cd2017-11-15 14:20:04 -0800328 return;
329 }
330 }
331 mLastBroadcastTimes[key] = timestampNs;
Yao Chenb3561512017-11-21 18:07:17 -0800332 VLOG("StatsD requesting broadcast for %s", key.ToString().c_str());
David Chen1d7b0cd2017-11-15 14:20:04 -0800333 mSendBroadcast(key);
Yao Chenb3561512017-11-21 18:07:17 -0800334 StatsdStats::getInstance().noteBroadcastSent(key);
yro31eb67b2017-10-24 13:33:21 -0700335 }
336}
337
yro947fbce2017-11-15 22:50:23 -0800338void StatsLogProcessor::WriteDataToDisk() {
Yangster-macb0d06282018-01-05 15:44:07 -0800339 std::lock_guard<std::mutex> lock(mMetricsMutex);
yro947fbce2017-11-15 22:50:23 -0800340 for (auto& pair : mMetricsManagers) {
341 const ConfigKey& key = pair.first;
342 vector<uint8_t> data;
Yao Chen8a8d16c2018-02-08 14:50:40 -0800343 onDumpReportLocked(key, time(nullptr) * NS_PER_SEC, &data);
yro947fbce2017-11-15 22:50:23 -0800344 // TODO: Add a guardrail to prevent accumulation of file on disk.
Yangster-mac330af582018-02-08 15:24:38 -0800345 string file_name = StringPrintf("%s/%ld_%d_%lld", STATS_DATA_DIR,
346 (long)getWallClockSec(), key.GetUid(), (long long)key.GetId());
yro947fbce2017-11-15 22:50:23 -0800347 StorageManager::writeFile(file_name.c_str(), &data[0], data.size());
348 }
349}
350
Yao Chenef99c4f2017-09-22 16:26:54 -0700351} // namespace statsd
352} // namespace os
353} // namespace android