StatsPullerManager not use singleton
This is to be consistent with other patterns such as UidMap. This also makes unit test simpler. Change-Id: I1558cd609e470481f269ecf2ae616277a95cfbf0 Bug: 72722120 Test: unit test
This commit is contained in:
@@ -41,7 +41,7 @@ statsd_common_src := \
|
||||
src/external/SubsystemSleepStatePuller.cpp \
|
||||
src/external/ResourceHealthManagerPuller.cpp \
|
||||
src/external/ResourceThermalManagerPuller.cpp \
|
||||
src/external/StatsPullerManagerImpl.cpp \
|
||||
src/external/StatsPullerManager.cpp \
|
||||
src/external/puller_util.cpp \
|
||||
src/logd/LogEvent.cpp \
|
||||
src/logd/LogListener.cpp \
|
||||
|
||||
@@ -362,11 +362,12 @@ std::unique_ptr<LogEvent> CreateSyncEndEvent(
|
||||
sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
|
||||
const ConfigKey& key) {
|
||||
sp<UidMap> uidMap = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
sp<StatsLogProcessor> processor = new StatsLogProcessor(
|
||||
uidMap, anomalyAlarmMonitor, periodicAlarmMonitor, timeBaseSec * NS_PER_SEC,
|
||||
[](const ConfigKey&){return true;});
|
||||
sp<StatsLogProcessor> processor =
|
||||
new StatsLogProcessor(uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec * NS_PER_SEC, [](const ConfigKey&) { return true; });
|
||||
processor->OnConfigUpdated(timeBaseSec * NS_PER_SEC, key, config);
|
||||
return processor;
|
||||
}
|
||||
|
||||
@@ -72,18 +72,20 @@ const int FIELD_ID_STRINGS = 9;
|
||||
#define STATS_DATA_DIR "/data/misc/stats-data"
|
||||
|
||||
StatsLogProcessor::StatsLogProcessor(const sp<UidMap>& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor,
|
||||
const int64_t timeBaseNs,
|
||||
const std::function<bool(const ConfigKey&)>& sendBroadcast)
|
||||
: mUidMap(uidMap),
|
||||
mPullerManager(pullerManager),
|
||||
mAnomalyAlarmMonitor(anomalyAlarmMonitor),
|
||||
mPeriodicAlarmMonitor(periodicAlarmMonitor),
|
||||
mSendBroadcast(sendBroadcast),
|
||||
mTimeBaseNs(timeBaseNs),
|
||||
mLargestTimestampSeen(0),
|
||||
mLastTimestampSeen(0) {
|
||||
mStatsPullerManager.ForceClearPullerCache();
|
||||
mPullerManager->ForceClearPullerCache();
|
||||
}
|
||||
|
||||
StatsLogProcessor::~StatsLogProcessor() {
|
||||
@@ -238,7 +240,7 @@ void StatsLogProcessor::OnLogEvent(LogEvent* event, bool reconnected) {
|
||||
|
||||
int64_t curTimeSec = getElapsedRealtimeSec();
|
||||
if (curTimeSec - mLastPullerCacheClearTimeSec > StatsdStats::kPullerCacheClearIntervalSec) {
|
||||
mStatsPullerManager.ClearPullerCacheIfNecessary(curTimeSec * NS_PER_SEC);
|
||||
mPullerManager->ClearPullerCacheIfNecessary(curTimeSec * NS_PER_SEC);
|
||||
mLastPullerCacheClearTimeSec = curTimeSec;
|
||||
}
|
||||
|
||||
@@ -266,8 +268,8 @@ void StatsLogProcessor::OnConfigUpdatedLocked(
|
||||
const int64_t timestampNs, const ConfigKey& key, const StatsdConfig& config) {
|
||||
VLOG("Updated configuration for key %s", key.ToString().c_str());
|
||||
sp<MetricsManager> newMetricsManager =
|
||||
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap,
|
||||
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
|
||||
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager,
|
||||
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
|
||||
if (newMetricsManager->isConfigValid()) {
|
||||
mUidMap->OnConfigUpdated(key);
|
||||
if (newMetricsManager->shouldAddUidMapListener()) {
|
||||
@@ -453,7 +455,7 @@ void StatsLogProcessor::OnConfigRemoved(const ConfigKey& key) {
|
||||
mLastBroadcastTimes.erase(key);
|
||||
|
||||
if (mMetricsManagers.empty()) {
|
||||
mStatsPullerManager.ForceClearPullerCache();
|
||||
mPullerManager->ForceClearPullerCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +540,7 @@ void StatsLogProcessor::WriteDataToDisk(const DumpReportReason dumpReportReason)
|
||||
|
||||
void StatsLogProcessor::informPullAlarmFired(const int64_t timestampNs) {
|
||||
std::lock_guard<std::mutex> lock(mMetricsMutex);
|
||||
mStatsPullerManager.OnAlarmFired(timestampNs);
|
||||
mPullerManager->OnAlarmFired(timestampNs);
|
||||
}
|
||||
|
||||
int64_t StatsLogProcessor::getLastReportTimeNs(const ConfigKey& key) {
|
||||
|
||||
@@ -45,7 +45,8 @@ enum DumpReportReason {
|
||||
|
||||
class StatsLogProcessor : public ConfigListener {
|
||||
public:
|
||||
StatsLogProcessor(const sp<UidMap>& uidMap, const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
StatsLogProcessor(const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& subscriberTriggerAlarmMonitor,
|
||||
const int64_t timeBaseNs,
|
||||
const std::function<bool(const ConfigKey&)>& sendBroadcast);
|
||||
@@ -126,7 +127,7 @@ private:
|
||||
|
||||
sp<UidMap> mUidMap; // Reference to the UidMap to lookup app name and version for each uid.
|
||||
|
||||
StatsPullerManager mStatsPullerManager;
|
||||
sp<StatsPullerManager> mPullerManager; // Reference to StatsPullerManager
|
||||
|
||||
sp<AlarmMonitor> mAnomalyAlarmMonitor;
|
||||
|
||||
|
||||
@@ -150,25 +150,26 @@ StatsService::StatsService(const sp<Looper>& handlerLooper)
|
||||
|
||||
})) {
|
||||
mUidMap = new UidMap();
|
||||
mPullerManager = new StatsPullerManager();
|
||||
StatsPuller::SetUidMap(mUidMap);
|
||||
mConfigManager = new ConfigManager();
|
||||
mProcessor = new StatsLogProcessor(mUidMap, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor,
|
||||
getElapsedRealtimeNs(), [this](const ConfigKey& key) {
|
||||
sp<IStatsCompanionService> sc = getStatsCompanionService();
|
||||
auto receiver = mConfigManager->GetConfigReceiver(key);
|
||||
if (sc == nullptr) {
|
||||
VLOG("Could not find StatsCompanionService");
|
||||
return false;
|
||||
} else if (receiver == nullptr) {
|
||||
VLOG("Statscompanion could not find a broadcast receiver for %s",
|
||||
key.ToString().c_str());
|
||||
return false;
|
||||
} else {
|
||||
sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
mProcessor = new StatsLogProcessor(
|
||||
mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor,
|
||||
getElapsedRealtimeNs(), [this](const ConfigKey& key) {
|
||||
sp<IStatsCompanionService> sc = getStatsCompanionService();
|
||||
auto receiver = mConfigManager->GetConfigReceiver(key);
|
||||
if (sc == nullptr) {
|
||||
VLOG("Could not find StatsCompanionService");
|
||||
return false;
|
||||
} else if (receiver == nullptr) {
|
||||
VLOG("Statscompanion could not find a broadcast receiver for %s",
|
||||
key.ToString().c_str());
|
||||
return false;
|
||||
} else {
|
||||
sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mConfigManager->AddListener(mProcessor);
|
||||
|
||||
@@ -711,7 +712,7 @@ status_t StatsService::cmd_log_app_breadcrumb(FILE* out, const Vector<String8>&
|
||||
status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) {
|
||||
int s = atoi(args[1].c_str());
|
||||
vector<shared_ptr<LogEvent> > stats;
|
||||
if (mStatsPullerManager.Pull(s, getElapsedRealtimeNs(), &stats)) {
|
||||
if (mPullerManager->Pull(s, getElapsedRealtimeNs(), &stats)) {
|
||||
for (const auto& it : stats) {
|
||||
fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str());
|
||||
}
|
||||
@@ -739,7 +740,7 @@ status_t StatsService::cmd_clear_puller_cache(FILE* out) {
|
||||
VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i",
|
||||
ipc->getCallingPid(), ipc->getCallingUid());
|
||||
if (checkCallingPermission(String16(kPermissionDump))) {
|
||||
int cleared = mStatsPullerManager.ForceClearPullerCache();
|
||||
int cleared = mPullerManager->ForceClearPullerCache();
|
||||
fprintf(out, "Puller removed %d cached data!\n", cleared);
|
||||
return NO_ERROR;
|
||||
} else {
|
||||
@@ -870,7 +871,7 @@ Status StatsService::statsCompanionReady() {
|
||||
}
|
||||
VLOG("StatsService::statsCompanionReady linking to statsCompanion.");
|
||||
IInterface::asBinder(statsCompanion)->linkToDeath(this);
|
||||
mStatsPullerManager.SetStatsCompanionService(statsCompanion);
|
||||
mPullerManager->SetStatsCompanionService(statsCompanion);
|
||||
mAnomalyAlarmMonitor->setStatsCompanionService(statsCompanion);
|
||||
mPeriodicAlarmMonitor->setStatsCompanionService(statsCompanion);
|
||||
SubscriberReporter::getInstance().setStatsCompanionService(statsCompanion);
|
||||
@@ -1014,7 +1015,7 @@ void StatsService::binderDied(const wp <IBinder>& who) {
|
||||
mAnomalyAlarmMonitor->setStatsCompanionService(nullptr);
|
||||
mPeriodicAlarmMonitor->setStatsCompanionService(nullptr);
|
||||
SubscriberReporter::getInstance().setStatsCompanionService(nullptr);
|
||||
mStatsPullerManager.SetStatsCompanionService(nullptr);
|
||||
mPullerManager->SetStatsCompanionService(nullptr);
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
@@ -246,9 +246,9 @@ private:
|
||||
sp<UidMap> mUidMap;
|
||||
|
||||
/**
|
||||
* Fetches external metrics.
|
||||
* Fetches external metrics
|
||||
*/
|
||||
StatsPullerManager mStatsPullerManager;
|
||||
sp<StatsPullerManager> mPullerManager;
|
||||
|
||||
/**
|
||||
* Tracks the configurations that have been passed to statsd.
|
||||
|
||||
4
cmds/statsd/src/external/StatsPuller.cpp
vendored
4
cmds/statsd/src/external/StatsPuller.cpp
vendored
@@ -18,10 +18,10 @@
|
||||
#include "Log.h"
|
||||
|
||||
#include "StatsPuller.h"
|
||||
#include "StatsPullerManager.h"
|
||||
#include "guardrail/StatsdStats.h"
|
||||
#include "puller_util.h"
|
||||
#include "stats_log_util.h"
|
||||
#include "StatsPullerManagerImpl.h"
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
@@ -35,7 +35,7 @@ void StatsPuller::SetUidMap(const sp<UidMap>& uidMap) { mUidMap = uidMap; }
|
||||
// ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently
|
||||
StatsPuller::StatsPuller(const int tagId)
|
||||
: mTagId(tagId) {
|
||||
mCoolDownNs = StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId)->second.coolDownNs;
|
||||
mCoolDownNs = StatsPullerManager::kAllPullAtomInfo.find(tagId)->second.coolDownNs;
|
||||
VLOG("Puller for tag %d created. Cooldown set to %lld", mTagId, (long long)mCoolDownNs);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "ResourceHealthManagerPuller.h"
|
||||
#include "ResourceThermalManagerPuller.h"
|
||||
#include "StatsCompanionServicePuller.h"
|
||||
#include "StatsPullerManagerImpl.h"
|
||||
#include "StatsPullerManager.h"
|
||||
#include "SubsystemSleepStatePuller.h"
|
||||
#include "statslog.h"
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace statsd {
|
||||
// Values smaller than this may require to update the alarm.
|
||||
const int64_t NO_ALARM_UPDATE = INT64_MAX;
|
||||
|
||||
const std::map<int, PullAtomInfo> StatsPullerManagerImpl::kAllPullAtomInfo = {
|
||||
const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
|
||||
// wifi_bytes_transfer
|
||||
{android::util::WIFI_BYTES_TRANSFER,
|
||||
{{2, 3, 4, 5},
|
||||
@@ -173,10 +173,10 @@ const std::map<int, PullAtomInfo> StatsPullerManagerImpl::kAllPullAtomInfo = {
|
||||
// temperature
|
||||
{android::util::TEMPERATURE, {{}, {}, 1, new ResourceThermalManagerPuller()}}};
|
||||
|
||||
StatsPullerManagerImpl::StatsPullerManagerImpl() : mNextPullTimeNs(NO_ALARM_UPDATE) {
|
||||
StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
|
||||
}
|
||||
|
||||
bool StatsPullerManagerImpl::Pull(const int tagId, const int64_t timeNs,
|
||||
bool StatsPullerManager::Pull(const int tagId, const int64_t timeNs,
|
||||
vector<shared_ptr<LogEvent>>* data) {
|
||||
VLOG("Initiating pulling %d", tagId);
|
||||
|
||||
@@ -190,16 +190,11 @@ bool StatsPullerManagerImpl::Pull(const int tagId, const int64_t timeNs,
|
||||
}
|
||||
}
|
||||
|
||||
StatsPullerManagerImpl& StatsPullerManagerImpl::GetInstance() {
|
||||
static StatsPullerManagerImpl instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool StatsPullerManagerImpl::PullerForMatcherExists(int tagId) const {
|
||||
bool StatsPullerManager::PullerForMatcherExists(int tagId) const {
|
||||
return kAllPullAtomInfo.find(tagId) != kAllPullAtomInfo.end();
|
||||
}
|
||||
|
||||
void StatsPullerManagerImpl::updateAlarmLocked() {
|
||||
void StatsPullerManager::updateAlarmLocked() {
|
||||
if (mNextPullTimeNs == NO_ALARM_UPDATE) {
|
||||
VLOG("No need to set alarms. Skipping");
|
||||
return;
|
||||
@@ -214,7 +209,7 @@ void StatsPullerManagerImpl::updateAlarmLocked() {
|
||||
return;
|
||||
}
|
||||
|
||||
void StatsPullerManagerImpl::SetStatsCompanionService(
|
||||
void StatsPullerManager::SetStatsCompanionService(
|
||||
sp<IStatsCompanionService> statsCompanionService) {
|
||||
AutoMutex _l(mLock);
|
||||
sp<IStatsCompanionService> tmpForLock = mStatsCompanionService;
|
||||
@@ -227,7 +222,7 @@ void StatsPullerManagerImpl::SetStatsCompanionService(
|
||||
}
|
||||
}
|
||||
|
||||
void StatsPullerManagerImpl::RegisterReceiver(int tagId, wp<PullDataReceiver> receiver,
|
||||
void StatsPullerManager::RegisterReceiver(int tagId, wp<PullDataReceiver> receiver,
|
||||
int64_t nextPullTimeNs, int64_t intervalNs) {
|
||||
AutoMutex _l(mLock);
|
||||
auto& receivers = mReceivers[tagId];
|
||||
@@ -262,7 +257,7 @@ void StatsPullerManagerImpl::RegisterReceiver(int tagId, wp<PullDataReceiver> re
|
||||
VLOG("Puller for tagId %d registered of %d", tagId, (int)receivers.size());
|
||||
}
|
||||
|
||||
void StatsPullerManagerImpl::UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver) {
|
||||
void StatsPullerManager::UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver) {
|
||||
AutoMutex _l(mLock);
|
||||
if (mReceivers.find(tagId) == mReceivers.end()) {
|
||||
VLOG("Unknown pull code or no receivers: %d", tagId);
|
||||
@@ -278,7 +273,7 @@ void StatsPullerManagerImpl::UnRegisterReceiver(int tagId, wp<PullDataReceiver>
|
||||
}
|
||||
}
|
||||
|
||||
void StatsPullerManagerImpl::OnAlarmFired(const int64_t currentTimeNs) {
|
||||
void StatsPullerManager::OnAlarmFired(const int64_t currentTimeNs) {
|
||||
AutoMutex _l(mLock);
|
||||
|
||||
int64_t minNextPullTimeNs = NO_ALARM_UPDATE;
|
||||
@@ -331,7 +326,7 @@ void StatsPullerManagerImpl::OnAlarmFired(const int64_t currentTimeNs) {
|
||||
updateAlarmLocked();
|
||||
}
|
||||
|
||||
int StatsPullerManagerImpl::ForceClearPullerCache() {
|
||||
int StatsPullerManager::ForceClearPullerCache() {
|
||||
int totalCleared = 0;
|
||||
for (const auto& pulledAtom : kAllPullAtomInfo) {
|
||||
totalCleared += pulledAtom.second.puller->ForceClearCache();
|
||||
@@ -339,7 +334,7 @@ int StatsPullerManagerImpl::ForceClearPullerCache() {
|
||||
return totalCleared;
|
||||
}
|
||||
|
||||
int StatsPullerManagerImpl::ClearPullerCacheIfNecessary(int64_t timestampNs) {
|
||||
int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) {
|
||||
int totalCleared = 0;
|
||||
for (const auto& pulledAtom : kAllPullAtomInfo) {
|
||||
totalCleared += pulledAtom.second.puller->ClearCacheIfNecessary(timestampNs);
|
||||
97
cmds/statsd/src/external/StatsPullerManager.h
vendored
97
cmds/statsd/src/external/StatsPullerManager.h
vendored
@@ -16,54 +16,87 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "StatsPullerManagerImpl.h"
|
||||
#include <android/os/IStatsCompanionService.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "PullDataReceiver.h"
|
||||
#include "StatsPuller.h"
|
||||
#include "logd/LogEvent.h"
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
class StatsPullerManager {
|
||||
public:
|
||||
virtual ~StatsPullerManager() {}
|
||||
typedef struct {
|
||||
// The field numbers of the fields that need to be summed when merging
|
||||
// isolated uid with host uid.
|
||||
std::vector<int> additiveFields;
|
||||
// The field numbers of the fields that can't be merged when merging
|
||||
// data belong to isolated uid and host uid.
|
||||
std::vector<int> nonAdditiveFields;
|
||||
// How long should the puller wait before doing an actual pull again. Default
|
||||
// 1 sec. Set this to 0 if this is handled elsewhere.
|
||||
int64_t coolDownNs = 1 * NS_PER_SEC;
|
||||
// The actual puller
|
||||
sp<StatsPuller> puller;
|
||||
} PullAtomInfo;
|
||||
|
||||
class StatsPullerManager : public virtual RefBase {
|
||||
public:
|
||||
StatsPullerManager();
|
||||
|
||||
virtual ~StatsPullerManager() {
|
||||
}
|
||||
|
||||
virtual void RegisterReceiver(int tagId, wp<PullDataReceiver> receiver, int64_t nextPullTimeNs,
|
||||
int64_t intervalNs) {
|
||||
mPullerManager.RegisterReceiver(tagId, receiver, nextPullTimeNs, intervalNs);
|
||||
};
|
||||
int64_t intervalNs);
|
||||
|
||||
virtual void UnRegisterReceiver(int tagId, wp <PullDataReceiver> receiver) {
|
||||
mPullerManager.UnRegisterReceiver(tagId, receiver);
|
||||
};
|
||||
virtual void UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver);
|
||||
|
||||
// Verify if we know how to pull for this matcher
|
||||
bool PullerForMatcherExists(int tagId) {
|
||||
return mPullerManager.PullerForMatcherExists(tagId);
|
||||
}
|
||||
bool PullerForMatcherExists(int tagId) const;
|
||||
|
||||
void OnAlarmFired(const int64_t currentTimeNs) {
|
||||
mPullerManager.OnAlarmFired(currentTimeNs);
|
||||
}
|
||||
void OnAlarmFired(const int64_t timeNs);
|
||||
|
||||
virtual bool Pull(const int tagId, const int64_t timesNs,
|
||||
vector<std::shared_ptr<LogEvent>>* data) {
|
||||
return mPullerManager.Pull(tagId, timesNs, data);
|
||||
}
|
||||
virtual bool Pull(const int tagId, const int64_t timeNs,
|
||||
vector<std::shared_ptr<LogEvent>>* data);
|
||||
|
||||
int ForceClearPullerCache() {
|
||||
return mPullerManager.ForceClearPullerCache();
|
||||
}
|
||||
int ForceClearPullerCache();
|
||||
|
||||
void SetStatsCompanionService(sp<IStatsCompanionService> statsCompanionService) {
|
||||
mPullerManager.SetStatsCompanionService(statsCompanionService);
|
||||
}
|
||||
int ClearPullerCacheIfNecessary(int64_t timestampNs);
|
||||
|
||||
int ClearPullerCacheIfNecessary(int64_t timestampNs) {
|
||||
return mPullerManager.ClearPullerCacheIfNecessary(timestampNs);
|
||||
}
|
||||
void SetStatsCompanionService(sp<IStatsCompanionService> statsCompanionService);
|
||||
|
||||
private:
|
||||
StatsPullerManagerImpl
|
||||
& mPullerManager = StatsPullerManagerImpl::GetInstance();
|
||||
const static std::map<int, PullAtomInfo> kAllPullAtomInfo;
|
||||
|
||||
private:
|
||||
sp<IStatsCompanionService> mStatsCompanionService = nullptr;
|
||||
|
||||
typedef struct {
|
||||
int64_t nextPullTimeNs;
|
||||
int64_t intervalNs;
|
||||
wp<PullDataReceiver> receiver;
|
||||
} ReceiverInfo;
|
||||
|
||||
// mapping from simple matcher tagId to receivers
|
||||
std::map<int, std::list<ReceiverInfo>> mReceivers;
|
||||
|
||||
// locks for data receiver and StatsCompanionService changes
|
||||
Mutex mLock;
|
||||
|
||||
void updateAlarmLocked();
|
||||
|
||||
int64_t mNextPullTimeNs;
|
||||
|
||||
FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents);
|
||||
FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm);
|
||||
FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents);
|
||||
FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm);
|
||||
};
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
102
cmds/statsd/src/external/StatsPullerManagerImpl.h
vendored
102
cmds/statsd/src/external/StatsPullerManagerImpl.h
vendored
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <android/os/IStatsCompanionService.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "PullDataReceiver.h"
|
||||
#include "StatsPuller.h"
|
||||
#include "logd/LogEvent.h"
|
||||
|
||||
namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
typedef struct {
|
||||
// The field numbers of the fields that need to be summed when merging
|
||||
// isolated uid with host uid.
|
||||
std::vector<int> additiveFields;
|
||||
// The field numbers of the fields that can't be merged when merging
|
||||
// data belong to isolated uid and host uid.
|
||||
std::vector<int> nonAdditiveFields;
|
||||
// How long should the puller wait before doing an actual pull again. Default
|
||||
// 1 sec. Set this to 0 if this is handled elsewhere.
|
||||
int64_t coolDownNs = 1 * NS_PER_SEC;
|
||||
// The actual puller
|
||||
sp<StatsPuller> puller;
|
||||
} PullAtomInfo;
|
||||
|
||||
class StatsPullerManagerImpl : public virtual RefBase {
|
||||
public:
|
||||
static StatsPullerManagerImpl& GetInstance();
|
||||
|
||||
void RegisterReceiver(int tagId, wp<PullDataReceiver> receiver, int64_t nextPullTimeNs,
|
||||
int64_t intervalNs);
|
||||
|
||||
void UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver);
|
||||
|
||||
// Verify if we know how to pull for this matcher
|
||||
bool PullerForMatcherExists(int tagId) const;
|
||||
|
||||
void OnAlarmFired(const int64_t timeNs);
|
||||
|
||||
bool Pull(const int tagId, const int64_t timeNs, vector<std::shared_ptr<LogEvent>>* data);
|
||||
|
||||
int ForceClearPullerCache();
|
||||
|
||||
int ClearPullerCacheIfNecessary(int64_t timestampNs);
|
||||
|
||||
void SetStatsCompanionService(sp<IStatsCompanionService> statsCompanionService);
|
||||
|
||||
const static std::map<int, PullAtomInfo> kAllPullAtomInfo;
|
||||
|
||||
private:
|
||||
StatsPullerManagerImpl();
|
||||
|
||||
sp<IStatsCompanionService> mStatsCompanionService = nullptr;
|
||||
|
||||
typedef struct {
|
||||
int64_t nextPullTimeNs;
|
||||
int64_t intervalNs;
|
||||
wp<PullDataReceiver> receiver;
|
||||
} ReceiverInfo;
|
||||
|
||||
// mapping from simple matcher tagId to receivers
|
||||
std::map<int, std::list<ReceiverInfo>> mReceivers;
|
||||
|
||||
// locks for data receiver and StatsCompanionService changes
|
||||
Mutex mLock;
|
||||
|
||||
void updateAlarmLocked();
|
||||
|
||||
int64_t mNextPullTimeNs;
|
||||
|
||||
FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents);
|
||||
FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm);
|
||||
FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents);
|
||||
FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm);
|
||||
};
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
10
cmds/statsd/src/external/puller_util.cpp
vendored
10
cmds/statsd/src/external/puller_util.cpp
vendored
@@ -17,7 +17,7 @@
|
||||
#define DEBUG false // STOPSHIP if true
|
||||
#include "Log.h"
|
||||
|
||||
#include "StatsPullerManagerImpl.h"
|
||||
#include "StatsPullerManager.h"
|
||||
#include "puller_util.h"
|
||||
#include "statslog.h"
|
||||
|
||||
@@ -107,8 +107,8 @@ bool tryMerge(vector<shared_ptr<LogEvent>>& data, int child_pos, const vector<in
|
||||
*/
|
||||
void mergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<UidMap>& uidMap,
|
||||
int tagId) {
|
||||
if (StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId) ==
|
||||
StatsPullerManagerImpl::kAllPullAtomInfo.end()) {
|
||||
if (StatsPullerManager::kAllPullAtomInfo.find(tagId) ==
|
||||
StatsPullerManager::kAllPullAtomInfo.end()) {
|
||||
VLOG("Unknown pull atom id %d", tagId);
|
||||
return;
|
||||
}
|
||||
@@ -121,9 +121,9 @@ void mergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<Uid
|
||||
uidField = it->second; // uidField is the field number in proto,
|
||||
}
|
||||
const vector<int>& additiveFields =
|
||||
StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId)->second.additiveFields;
|
||||
StatsPullerManager::kAllPullAtomInfo.find(tagId)->second.additiveFields;
|
||||
const vector<int>& nonAdditiveFields =
|
||||
StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId)->second.nonAdditiveFields;
|
||||
StatsPullerManager::kAllPullAtomInfo.find(tagId)->second.nonAdditiveFields;
|
||||
|
||||
// map of host uid to their position in the original vector
|
||||
map<int, vector<int>> hostPosition;
|
||||
|
||||
@@ -72,9 +72,9 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard, const int pullTagId,
|
||||
const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||
shared_ptr<StatsPullerManager> statsPullerManager)
|
||||
const sp<StatsPullerManager>& pullerManager)
|
||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard),
|
||||
mStatsPullerManager(statsPullerManager),
|
||||
mPullerManager(pullerManager),
|
||||
mPullTagId(pullTagId),
|
||||
mMinBucketSizeNs(metric.min_bucket_size_nanos()),
|
||||
mDimensionSoftLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
|
||||
@@ -127,8 +127,8 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
|
||||
flushIfNeededLocked(startTimeNs);
|
||||
// Kicks off the puller immediately.
|
||||
if (mPullTagId != -1 && mSamplingType == GaugeMetric::RANDOM_ONE_SAMPLE) {
|
||||
mStatsPullerManager->RegisterReceiver(
|
||||
mPullTagId, this, getCurrentBucketEndTimeNs(), mBucketSizeNs);
|
||||
mPullerManager->RegisterReceiver(mPullTagId, this, getCurrentBucketEndTimeNs(),
|
||||
mBucketSizeNs);
|
||||
}
|
||||
|
||||
VLOG("Gauge metric %lld created. bucket size %lld start_time: %lld sliced %d",
|
||||
@@ -136,19 +136,10 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
|
||||
mConditionSliced);
|
||||
}
|
||||
|
||||
// for testing
|
||||
GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& metric,
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard, const int pullTagId,
|
||||
const int64_t timeBaseNs, const int64_t startTimeNs)
|
||||
: GaugeMetricProducer(key, metric, conditionIndex, wizard, pullTagId, timeBaseNs, startTimeNs,
|
||||
make_shared<StatsPullerManager>()) {
|
||||
}
|
||||
|
||||
GaugeMetricProducer::~GaugeMetricProducer() {
|
||||
VLOG("~GaugeMetricProducer() called");
|
||||
if (mPullTagId != -1 && mSamplingType == GaugeMetric::RANDOM_ONE_SAMPLE) {
|
||||
mStatsPullerManager->UnRegisterReceiver(mPullTagId, this);
|
||||
mPullerManager->UnRegisterReceiver(mPullTagId, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +327,7 @@ void GaugeMetricProducer::pullLocked(const int64_t timestampNs) {
|
||||
}
|
||||
|
||||
vector<std::shared_ptr<LogEvent>> allData;
|
||||
if (!mStatsPullerManager->Pull(mPullTagId, timestampNs, &allData)) {
|
||||
if (!mPullerManager->Pull(mPullTagId, timestampNs, &allData)) {
|
||||
ALOGE("Gauge Stats puller failed for tag: %d", mPullTagId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ class GaugeMetricProducer : public virtual MetricProducer, public virtual PullDa
|
||||
public:
|
||||
GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& gaugeMetric,
|
||||
const int conditionIndex, const sp<ConditionWizard>& wizard,
|
||||
const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs);
|
||||
const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||
const sp<StatsPullerManager>& pullerManager);
|
||||
|
||||
virtual ~GaugeMetricProducer();
|
||||
|
||||
@@ -94,13 +95,6 @@ private:
|
||||
android::util::ProtoOutputStream* protoOutput) override;
|
||||
void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
|
||||
|
||||
// for testing
|
||||
GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& gaugeMetric,
|
||||
const int conditionIndex, const sp<ConditionWizard>& wizard,
|
||||
const int pullTagId,
|
||||
const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||
std::shared_ptr<StatsPullerManager> statsPullerManager);
|
||||
|
||||
// Internal interface to handle condition change.
|
||||
void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
|
||||
|
||||
@@ -123,7 +117,7 @@ private:
|
||||
|
||||
int mTagId;
|
||||
|
||||
std::shared_ptr<StatsPullerManager> mStatsPullerManager;
|
||||
sp<StatsPullerManager> mPullerManager;
|
||||
// tagId for pulled data. -1 if this is not pulled
|
||||
const int mPullTagId;
|
||||
|
||||
|
||||
@@ -56,10 +56,12 @@ const int FIELD_ID_ANNOTATIONS_INT32 = 2;
|
||||
|
||||
MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
|
||||
const int64_t timeBaseNs, const int64_t currentTimeNs,
|
||||
const sp<UidMap> &uidMap,
|
||||
const sp<UidMap>& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor)
|
||||
: mConfigKey(key), mUidMap(uidMap),
|
||||
: mConfigKey(key),
|
||||
mUidMap(uidMap),
|
||||
mTtlNs(config.has_ttl_in_seconds() ? config.ttl_in_seconds() * NS_PER_SEC : -1),
|
||||
mTtlEndNs(-1),
|
||||
mLastReportTimeNs(currentTimeNs),
|
||||
@@ -67,12 +69,11 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
|
||||
// Init the ttl end timestamp.
|
||||
refreshTtl(timeBaseNs);
|
||||
|
||||
mConfigValid =
|
||||
initStatsdConfig(key, config, *uidMap, anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers,
|
||||
mAllConditionTrackers, mAllMetricProducers, mAllAnomalyTrackers,
|
||||
mAllPeriodicAlarmTrackers, mConditionToMetricMap, mTrackerToMetricMap,
|
||||
mTrackerToConditionMap, mNoReportMetricIds);
|
||||
mConfigValid = initStatsdConfig(
|
||||
key, config, *uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers, mAllConditionTrackers,
|
||||
mAllMetricProducers, mAllAnomalyTrackers, mAllPeriodicAlarmTrackers,
|
||||
mConditionToMetricMap, mTrackerToMetricMap, mTrackerToConditionMap, mNoReportMetricIds);
|
||||
|
||||
mHashStringsInReport = config.hash_strings_in_metric_report();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "external/StatsPullerManager.h"
|
||||
#include "anomaly/AlarmMonitor.h"
|
||||
#include "anomaly/AlarmTracker.h"
|
||||
#include "anomaly/AnomalyTracker.h"
|
||||
@@ -36,9 +37,10 @@ namespace statsd {
|
||||
// A MetricsManager is responsible for managing metrics from one single config source.
|
||||
class MetricsManager : public PackageInfoListener {
|
||||
public:
|
||||
MetricsManager(const ConfigKey& configKey, const StatsdConfig& config,
|
||||
const int64_t timeBaseNs, const int64_t currentTimeNs,
|
||||
const sp<UidMap>& uidMap, const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
MetricsManager(const ConfigKey& configKey, const StatsdConfig& config, const int64_t timeBaseNs,
|
||||
const int64_t currentTimeNs, const sp<UidMap>& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor);
|
||||
|
||||
virtual ~MetricsManager();
|
||||
|
||||
@@ -74,10 +74,10 @@ ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard, const int pullTagId,
|
||||
const int64_t timeBaseNs, const int64_t startTimestampNs,
|
||||
shared_ptr<StatsPullerManager> statsPullerManager)
|
||||
const sp<StatsPullerManager>& pullerManager)
|
||||
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard),
|
||||
mPullerManager(pullerManager),
|
||||
mValueField(metric.value_field()),
|
||||
mStatsPullerManager(statsPullerManager),
|
||||
mPullTagId(pullTagId),
|
||||
mMinBucketSizeNs(metric.min_bucket_size_nanos()),
|
||||
mDimensionSoftLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
|
||||
@@ -127,27 +127,18 @@ ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric
|
||||
// Kicks off the puller immediately.
|
||||
flushIfNeededLocked(startTimestampNs);
|
||||
if (mPullTagId != -1) {
|
||||
mStatsPullerManager->RegisterReceiver(
|
||||
mPullTagId, this, mCurrentBucketStartTimeNs + mBucketSizeNs, mBucketSizeNs);
|
||||
mPullerManager->RegisterReceiver(mPullTagId, this,
|
||||
mCurrentBucketStartTimeNs + mBucketSizeNs, mBucketSizeNs);
|
||||
}
|
||||
|
||||
VLOG("value metric %lld created. bucket size %lld start_time: %lld",
|
||||
(long long)metric.id(), (long long)mBucketSizeNs, (long long)mTimeBaseNs);
|
||||
}
|
||||
|
||||
// for testing
|
||||
ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric& metric,
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard, const int pullTagId,
|
||||
const int64_t timeBaseNs, const int64_t startTimeNs)
|
||||
: ValueMetricProducer(key, metric, conditionIndex, wizard, pullTagId, timeBaseNs, startTimeNs,
|
||||
make_shared<StatsPullerManager>()) {
|
||||
}
|
||||
|
||||
ValueMetricProducer::~ValueMetricProducer() {
|
||||
VLOG("~ValueMetricProducer() called");
|
||||
if (mPullTagId != -1) {
|
||||
mStatsPullerManager->UnRegisterReceiver(mPullTagId, this);
|
||||
mPullerManager->UnRegisterReceiver(mPullTagId, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +274,7 @@ void ValueMetricProducer::onConditionChangedLocked(const bool condition,
|
||||
|
||||
if (mPullTagId != -1) {
|
||||
vector<shared_ptr<LogEvent>> allData;
|
||||
if (mStatsPullerManager->Pull(mPullTagId, eventTimeNs, &allData)) {
|
||||
if (mPullerManager->Pull(mPullTagId, eventTimeNs, &allData)) {
|
||||
if (allData.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ class ValueMetricProducer : public virtual MetricProducer, public virtual PullDa
|
||||
public:
|
||||
ValueMetricProducer(const ConfigKey& key, const ValueMetric& valueMetric,
|
||||
const int conditionIndex, const sp<ConditionWizard>& wizard,
|
||||
const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs);
|
||||
const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||
const sp<StatsPullerManager>& pullerManager);
|
||||
|
||||
virtual ~ValueMetricProducer();
|
||||
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
|
||||
if (mPullTagId != -1 && (mCondition == true || mConditionTrackerIndex < 0) ) {
|
||||
vector<shared_ptr<LogEvent>> allData;
|
||||
mStatsPullerManager->Pull(mPullTagId, eventTimeNs, &allData);
|
||||
mPullerManager->Pull(mPullTagId, eventTimeNs, &allData);
|
||||
if (allData.size() == 0) {
|
||||
// This shouldn't happen since this valuemetric is not useful now.
|
||||
}
|
||||
@@ -112,16 +113,10 @@ private:
|
||||
|
||||
void dropDataLocked(const int64_t dropTimeNs) override;
|
||||
|
||||
sp<StatsPullerManager> mPullerManager;
|
||||
|
||||
const FieldMatcher mValueField;
|
||||
|
||||
std::shared_ptr<StatsPullerManager> mStatsPullerManager;
|
||||
|
||||
// for testing
|
||||
ValueMetricProducer(const ConfigKey& key, const ValueMetric& valueMetric,
|
||||
const int conditionIndex, const sp<ConditionWizard>& wizard,
|
||||
const int pullTagId, const int64_t timeBaseNs, const int64_t startTimeNs,
|
||||
std::shared_ptr<StatsPullerManager> statsPullerManager);
|
||||
|
||||
// tagId for pulled data. -1 if this is not pulled
|
||||
const int mPullTagId;
|
||||
|
||||
|
||||
@@ -262,9 +262,10 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
const int64_t timeBaseTimeNs, const int64_t currentTimeNs,
|
||||
UidMap& uidMap, const unordered_map<int64_t, int>& logTrackerMap,
|
||||
bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs,
|
||||
const int64_t currentTimeNs, UidMap& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const unordered_map<int64_t, int>& logTrackerMap,
|
||||
const unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
@@ -465,9 +466,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
}
|
||||
|
||||
sp<MetricProducer> valueProducer = new ValueMetricProducer(key, metric, conditionIndex,
|
||||
wizard, pullTagId,
|
||||
timeBaseTimeNs, currentTimeNs);
|
||||
sp<MetricProducer> valueProducer =
|
||||
new ValueMetricProducer(key, metric, conditionIndex, wizard, pullTagId,
|
||||
timeBaseTimeNs, currentTimeNs, pullerManager);
|
||||
allMetricProducers.push_back(valueProducer);
|
||||
}
|
||||
|
||||
@@ -525,8 +526,9 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
}
|
||||
|
||||
sp<MetricProducer> gaugeProducer = new GaugeMetricProducer(
|
||||
key, metric, conditionIndex, wizard, pullTagId, timeBaseTimeNs, currentTimeNs);
|
||||
sp<MetricProducer> gaugeProducer =
|
||||
new GaugeMetricProducer(key, metric, conditionIndex, wizard, pullTagId,
|
||||
timeBaseTimeNs, currentTimeNs, pullerManager);
|
||||
allMetricProducers.push_back(gaugeProducer);
|
||||
}
|
||||
for (int i = 0; i < config.no_report_metric_size(); ++i) {
|
||||
@@ -645,10 +647,10 @@ bool initAlarms(const StatsdConfig& config, const ConfigKey& key,
|
||||
}
|
||||
|
||||
bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor,
|
||||
const int64_t timeBaseNs, const int64_t currentTimeNs,
|
||||
set<int>& allTagIds,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor, const int64_t timeBaseNs,
|
||||
const int64_t currentTimeNs, set<int>& allTagIds,
|
||||
vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
vector<sp<MetricProducer>>& allMetricProducers,
|
||||
@@ -674,9 +676,8 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap&
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initMetrics(key, config, timeBaseNs, currentTimeNs, uidMap,
|
||||
logTrackerMap, conditionTrackerMap,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
if (!initMetrics(key, config, timeBaseNs, currentTimeNs, uidMap, pullerManager, logTrackerMap,
|
||||
conditionTrackerMap, allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
conditionToMetricMap, trackerToMetricMap, metricProducerMap,
|
||||
noReportMetricIds)) {
|
||||
ALOGE("initMetricProducers failed");
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "../anomaly/AlarmTracker.h"
|
||||
#include "../condition/ConditionTracker.h"
|
||||
#include "../external/StatsPullerManagerImpl.h"
|
||||
#include "../external/StatsPullerManager.h"
|
||||
#include "../matchers/LogMatchingTracker.h"
|
||||
#include "../metrics/MetricProducer.h"
|
||||
|
||||
@@ -81,9 +81,8 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
// the list of MetricProducer index
|
||||
// [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
|
||||
bool initMetrics(
|
||||
const ConfigKey& key, const StatsdConfig& config,
|
||||
const int64_t timeBaseTimeNs, const int64_t currentTimeNs,
|
||||
UidMap& uidMap,
|
||||
const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs,
|
||||
const int64_t currentTimeNs, UidMap& uidMap, const sp<StatsPullerManager>& pullerManager,
|
||||
const std::unordered_map<int64_t, int>& logTrackerMap,
|
||||
const std::unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
const std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks,
|
||||
@@ -97,10 +96,10 @@ bool initMetrics(
|
||||
// Initialize MetricsManager from StatsdConfig.
|
||||
// Parameters are the members of MetricsManager. See MetricsManager for declaration.
|
||||
bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& uidMap,
|
||||
const sp<StatsPullerManager>& pullerManager,
|
||||
const sp<AlarmMonitor>& anomalyAlarmMonitor,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor,
|
||||
const int64_t timeBaseNs, const int64_t currentTimeNs,
|
||||
std::set<int>& allTagIds,
|
||||
const sp<AlarmMonitor>& periodicAlarmMonitor, const int64_t timeBaseNs,
|
||||
const int64_t currentTimeNs, std::set<int>& allTagIds,
|
||||
std::vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::vector<sp<MetricProducer>>& allMetricProducers,
|
||||
|
||||
@@ -271,6 +271,7 @@ StatsdConfig buildCirclePredicates() {
|
||||
|
||||
TEST(MetricsManagerTest, TestGoodConfig) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildGoodConfig();
|
||||
@@ -285,13 +286,11 @@ TEST(MetricsManagerTest, TestGoodConfig) {
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_TRUE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_TRUE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
EXPECT_EQ(1u, allMetricProducers.size());
|
||||
EXPECT_EQ(1u, allAnomalyTrackers.size());
|
||||
EXPECT_EQ(1u, noReportMetricIds.size());
|
||||
@@ -299,6 +298,7 @@ TEST(MetricsManagerTest, TestGoodConfig) {
|
||||
|
||||
TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildDimensionMetricsWithMultiTags();
|
||||
@@ -313,17 +313,16 @@ TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) {
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestCircleLogMatcherDependency) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildCircleMatchers();
|
||||
@@ -338,17 +337,16 @@ TEST(MetricsManagerTest, TestCircleLogMatcherDependency) {
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestMissingMatchers) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildMissingMatchers();
|
||||
@@ -362,17 +360,16 @@ TEST(MetricsManagerTest, TestMissingMatchers) {
|
||||
unordered_map<int, std::vector<int>> trackerToMetricMap;
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestMissingPredicate) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildMissingPredicate();
|
||||
@@ -386,17 +383,16 @@ TEST(MetricsManagerTest, TestMissingPredicate) {
|
||||
unordered_map<int, std::vector<int>> trackerToMetricMap;
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestCirclePredicateDependency) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildCirclePredicates();
|
||||
@@ -411,17 +407,16 @@ TEST(MetricsManagerTest, TestCirclePredicateDependency) {
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, testAlertWithUnknownMetric) {
|
||||
UidMap uidMap;
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
StatsdConfig config = buildAlertWithUnknownMetric();
|
||||
@@ -436,13 +431,11 @@ TEST(MetricsManagerTest, testAlertWithUnknownMetric) {
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap,
|
||||
anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseSec, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
allAlarmTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_FALSE(initStatsdConfig(kConfigKey, config, uidMap, pullerManager, anomalyAlarmMonitor,
|
||||
periodicAlarmMonitor, timeBaseSec, timeBaseSec, allTagIds,
|
||||
allAtomMatchers, allConditionTrackers, allMetricProducers,
|
||||
allAnomalyTrackers, allAlarmTrackers, conditionToMetricMap,
|
||||
trackerToMetricMap, trackerToConditionMap, noReportMetricIds));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -44,13 +44,13 @@ using android::util::ProtoOutputStream;
|
||||
*/
|
||||
class MockMetricsManager : public MetricsManager {
|
||||
public:
|
||||
MockMetricsManager() : MetricsManager(
|
||||
ConfigKey(1, 12345), StatsdConfig(), 1000, 1000,
|
||||
new UidMap(),
|
||||
new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t){},
|
||||
[](const sp<IStatsCompanionService>&){}),
|
||||
new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t){},
|
||||
[](const sp<IStatsCompanionService>&){})) {
|
||||
MockMetricsManager()
|
||||
: MetricsManager(ConfigKey(1, 12345), StatsdConfig(), 1000, 1000, new UidMap(),
|
||||
new StatsPullerManager(),
|
||||
new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t) {},
|
||||
[](const sp<IStatsCompanionService>&) {}),
|
||||
new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t) {},
|
||||
[](const sp<IStatsCompanionService>&) {})) {
|
||||
}
|
||||
|
||||
MOCK_METHOD0(byteSize, size_t());
|
||||
@@ -60,11 +60,12 @@ public:
|
||||
|
||||
TEST(StatsLogProcessorTest, TestRateLimitByteSize) {
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> periodicAlarmMonitor;
|
||||
// Construct the processor with a dummy sendBroadcast function that does nothing.
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, periodicAlarmMonitor, 0,
|
||||
[](const ConfigKey& key) {return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor, 0,
|
||||
[](const ConfigKey& key) { return true; });
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
@@ -79,11 +80,15 @@ TEST(StatsLogProcessorTest, TestRateLimitByteSize) {
|
||||
|
||||
TEST(StatsLogProcessorTest, TestRateLimitBroadcast) {
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
@@ -105,11 +110,15 @@ TEST(StatsLogProcessorTest, TestRateLimitBroadcast) {
|
||||
|
||||
TEST(StatsLogProcessorTest, TestDropWhenByteSizeTooLarge) {
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
@@ -143,12 +152,16 @@ StatsdConfig MakeConfig(bool includeMetric) {
|
||||
TEST(StatsLogProcessorTest, TestUidMapHasSnapshot) {
|
||||
// Setup simple config key corresponding to empty config.
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
m->updateMap(1, {1, 2}, {1, 2}, {String16("p1"), String16("p2")});
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
ConfigKey key(3, 4);
|
||||
StatsdConfig config = MakeConfig(true);
|
||||
p.OnConfigUpdated(0, key, config);
|
||||
@@ -168,12 +181,16 @@ TEST(StatsLogProcessorTest, TestUidMapHasSnapshot) {
|
||||
TEST(StatsLogProcessorTest, TestEmptyConfigHasNoUidMap) {
|
||||
// Setup simple config key corresponding to empty config.
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
m->updateMap(1, {1, 2}, {1, 2}, {String16("p1"), String16("p2")});
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
ConfigKey key(3, 4);
|
||||
StatsdConfig config = MakeConfig(false);
|
||||
p.OnConfigUpdated(0, key, config);
|
||||
@@ -191,11 +208,15 @@ TEST(StatsLogProcessorTest, TestEmptyConfigHasNoUidMap) {
|
||||
TEST(StatsLogProcessorTest, TestReportIncludesSubConfig) {
|
||||
// Setup simple config key corresponding to empty config.
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
ConfigKey key(3, 4);
|
||||
StatsdConfig config;
|
||||
auto annotation = config.add_annotation();
|
||||
@@ -220,11 +241,15 @@ TEST(StatsLogProcessorTest, TestReportIncludesSubConfig) {
|
||||
TEST(StatsLogProcessorTest, TestOutOfOrderLogs) {
|
||||
// Setup simple config key corresponding to empty config.
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
int broadcastCount = 0;
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) { broadcastCount++; return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[&broadcastCount](const ConfigKey& key) {
|
||||
broadcastCount++;
|
||||
return true;
|
||||
});
|
||||
|
||||
LogEvent event1(0, 1 /*logd timestamp*/, 1001 /*elapsedRealtime*/);
|
||||
event1.init();
|
||||
|
||||
@@ -40,11 +40,12 @@ const string kApp2 = "app2.sharing.1";
|
||||
|
||||
TEST(UidMapTest, TestIsolatedUID) {
|
||||
sp<UidMap> m = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor;
|
||||
sp<AlarmMonitor> subscriberAlarmMonitor;
|
||||
// Construct the processor with a dummy sendBroadcast function that does nothing.
|
||||
StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[](const ConfigKey& key) {return true;});
|
||||
StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
|
||||
[](const ConfigKey& key) { return true; });
|
||||
LogEvent addEvent(android::util::ISOLATED_UID_CHANGED, 1);
|
||||
addEvent.write(100); // parent UID
|
||||
addEvent.write(101); // isolated UID
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents) {
|
||||
baseTimeNs, configAddedTimeNs, config, cfgKey);
|
||||
EXPECT_EQ(processor->mMetricsManagers.size(), 1u);
|
||||
EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
|
||||
processor->mStatsPullerManager.ForceClearPullerCache();
|
||||
processor->mPullerManager->ForceClearPullerCache();
|
||||
|
||||
int startBucketNum = processor->mMetricsManagers.begin()->second->
|
||||
mAllMetricProducers[0]->getCurrentBucketNum();
|
||||
@@ -74,12 +74,11 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents) {
|
||||
|
||||
// When creating the config, the gauge metric producer should register the alarm at the
|
||||
// end of the current bucket.
|
||||
EXPECT_EQ((size_t)1, StatsPullerManagerImpl::GetInstance().mReceivers.size());
|
||||
EXPECT_EQ((size_t)1, processor->mPullerManager->mReceivers.size());
|
||||
EXPECT_EQ(bucketSizeNs,
|
||||
StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().intervalNs);
|
||||
int64_t& nextPullTimeNs = StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().nextPullTimeNs;
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().intervalNs);
|
||||
int64_t& nextPullTimeNs =
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().nextPullTimeNs;
|
||||
EXPECT_EQ(baseTimeNs + startBucketNum * bucketSizeNs + bucketSizeNs, nextPullTimeNs);
|
||||
|
||||
auto screenOffEvent = CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF,
|
||||
@@ -212,7 +211,7 @@ TEST(GaugeMetricE2eTest, TestAllConditionChangesSamplePulledEvents) {
|
||||
baseTimeNs, configAddedTimeNs, config, cfgKey);
|
||||
EXPECT_EQ(processor->mMetricsManagers.size(), 1u);
|
||||
EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
|
||||
processor->mStatsPullerManager.ForceClearPullerCache();
|
||||
processor->mPullerManager->ForceClearPullerCache();
|
||||
|
||||
int startBucketNum = processor->mMetricsManagers.begin()->second->
|
||||
mAllMetricProducers[0]->getCurrentBucketNum();
|
||||
@@ -313,7 +312,7 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm) {
|
||||
baseTimeNs, configAddedTimeNs, config, cfgKey);
|
||||
EXPECT_EQ(processor->mMetricsManagers.size(), 1u);
|
||||
EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
|
||||
processor->mStatsPullerManager.ForceClearPullerCache();
|
||||
processor->mPullerManager->ForceClearPullerCache();
|
||||
|
||||
int startBucketNum = processor->mMetricsManagers.begin()->second->
|
||||
mAllMetricProducers[0]->getCurrentBucketNum();
|
||||
@@ -321,12 +320,11 @@ TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm) {
|
||||
|
||||
// When creating the config, the gauge metric producer should register the alarm at the
|
||||
// end of the current bucket.
|
||||
EXPECT_EQ((size_t)1, StatsPullerManagerImpl::GetInstance().mReceivers.size());
|
||||
EXPECT_EQ((size_t)1, processor->mPullerManager->mReceivers.size());
|
||||
EXPECT_EQ(bucketSizeNs,
|
||||
StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().intervalNs);
|
||||
int64_t& nextPullTimeNs = StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().nextPullTimeNs;
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().intervalNs);
|
||||
int64_t& nextPullTimeNs =
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().nextPullTimeNs;
|
||||
EXPECT_EQ(baseTimeNs + startBucketNum * bucketSizeNs + bucketSizeNs, nextPullTimeNs);
|
||||
|
||||
auto screenOffEvent = CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF,
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST(ValueMetricE2eTest, TestPulledEvents) {
|
||||
baseTimeNs, configAddedTimeNs, config, cfgKey);
|
||||
EXPECT_EQ(processor->mMetricsManagers.size(), 1u);
|
||||
EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
|
||||
processor->mStatsPullerManager.ForceClearPullerCache();
|
||||
processor->mPullerManager->ForceClearPullerCache();
|
||||
|
||||
int startBucketNum = processor->mMetricsManagers.begin()->second->
|
||||
mAllMetricProducers[0]->getCurrentBucketNum();
|
||||
@@ -74,12 +74,11 @@ TEST(ValueMetricE2eTest, TestPulledEvents) {
|
||||
|
||||
// When creating the config, the gauge metric producer should register the alarm at the
|
||||
// end of the current bucket.
|
||||
EXPECT_EQ((size_t)1, StatsPullerManagerImpl::GetInstance().mReceivers.size());
|
||||
EXPECT_EQ((size_t)1, processor->mPullerManager->mReceivers.size());
|
||||
EXPECT_EQ(bucketSizeNs,
|
||||
StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().intervalNs);
|
||||
int64_t& expectedPullTimeNs = StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().nextPullTimeNs;
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().intervalNs);
|
||||
int64_t& expectedPullTimeNs =
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().nextPullTimeNs;
|
||||
EXPECT_EQ(baseTimeNs + startBucketNum * bucketSizeNs + bucketSizeNs, expectedPullTimeNs);
|
||||
|
||||
auto screenOffEvent = CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF,
|
||||
@@ -173,7 +172,7 @@ TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm) {
|
||||
baseTimeNs, configAddedTimeNs, config, cfgKey);
|
||||
EXPECT_EQ(processor->mMetricsManagers.size(), 1u);
|
||||
EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
|
||||
processor->mStatsPullerManager.ForceClearPullerCache();
|
||||
processor->mPullerManager->ForceClearPullerCache();
|
||||
|
||||
int startBucketNum = processor->mMetricsManagers.begin()->second->
|
||||
mAllMetricProducers[0]->getCurrentBucketNum();
|
||||
@@ -181,12 +180,11 @@ TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm) {
|
||||
|
||||
// When creating the config, the gauge metric producer should register the alarm at the
|
||||
// end of the current bucket.
|
||||
EXPECT_EQ((size_t)1, StatsPullerManagerImpl::GetInstance().mReceivers.size());
|
||||
EXPECT_EQ((size_t)1, processor->mPullerManager->mReceivers.size());
|
||||
EXPECT_EQ(bucketSizeNs,
|
||||
StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().intervalNs);
|
||||
int64_t& expectedPullTimeNs = StatsPullerManagerImpl::GetInstance().mReceivers.begin()->
|
||||
second.front().nextPullTimeNs;
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().intervalNs);
|
||||
int64_t& expectedPullTimeNs =
|
||||
processor->mPullerManager->mReceivers.begin()->second.front().nextPullTimeNs;
|
||||
EXPECT_EQ(baseTimeNs + startBucketNum * bucketSizeNs + bucketSizeNs, expectedPullTimeNs);
|
||||
|
||||
// Screen off/on/off events.
|
||||
|
||||
@@ -61,8 +61,7 @@ TEST(GaugeMetricProducerTest, TestNoCondition) {
|
||||
|
||||
// TODO: pending refactor of StatsPullerManager
|
||||
// For now we still need this so that it doesn't do real pulling.
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -89,8 +88,7 @@ TEST(GaugeMetricProducerTest, TestNoCondition) {
|
||||
EXPECT_EQ(0UL, gaugeProducer.mPastBuckets.size());
|
||||
|
||||
allData.clear();
|
||||
std::shared_ptr<LogEvent> event2 =
|
||||
std::make_shared<LogEvent>(tagId, bucket3StartTimeNs + 10);
|
||||
std::shared_ptr<LogEvent> event2 = std::make_shared<LogEvent>(tagId, bucket3StartTimeNs + 10);
|
||||
event2->write(24);
|
||||
event2->write("some value");
|
||||
event2->write(25);
|
||||
@@ -140,8 +138,7 @@ TEST(GaugeMetricProducerTest, TestPushedEventsWithUpgrade) {
|
||||
alert.set_trigger_if_sum_gt(25);
|
||||
alert.set_num_buckets(100);
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
||||
-1 /* -1 means no pulling */, bucketStartTimeNs,
|
||||
bucketStartTimeNs, pullerManager);
|
||||
@@ -211,8 +208,7 @@ TEST(GaugeMetricProducerTest, TestPulledWithUpgrade) {
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, Pull(tagId, _, _))
|
||||
@@ -280,8 +276,7 @@ TEST(GaugeMetricProducerTest, TestWithCondition) {
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, Pull(tagId, _, _))
|
||||
@@ -296,8 +291,8 @@ TEST(GaugeMetricProducerTest, TestWithCondition) {
|
||||
return true;
|
||||
}));
|
||||
|
||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, tagId,
|
||||
bucketStartTimeNs, bucketStartTimeNs, pullerManager);
|
||||
GaugeMetricProducer gaugeProducer(kConfigKey, metric, 1, wizard, tagId, bucketStartTimeNs,
|
||||
bucketStartTimeNs, pullerManager);
|
||||
gaugeProducer.setBucketSize(60 * NS_PER_SEC);
|
||||
|
||||
gaugeProducer.onConditionChanged(true, bucketStartTimeNs + 8);
|
||||
@@ -372,8 +367,7 @@ TEST(GaugeMetricProducerTest, TestWithSlicedCondition) {
|
||||
return ConditionState::kTrue;
|
||||
}));
|
||||
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, Pull(tagId, _, _))
|
||||
@@ -421,8 +415,7 @@ TEST(GaugeMetricProducerTest, TestAnomalyDetection) {
|
||||
sp<AlarmMonitor> alarmMonitor;
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -472,7 +465,7 @@ TEST(GaugeMetricProducerTest, TestAnomalyDetection) {
|
||||
.mFields->begin()
|
||||
->mValue.int_value);
|
||||
EXPECT_EQ(anomalyTracker->getRefractoryPeriodEndsSec(DEFAULT_METRIC_DIMENSION_KEY),
|
||||
std::ceil(1.0 * event2->GetElapsedTimestampNs() / NS_PER_SEC) + refPeriodSec);
|
||||
std::ceil(1.0 * event2->GetElapsedTimestampNs() / NS_PER_SEC) + refPeriodSec);
|
||||
|
||||
std::shared_ptr<LogEvent> event3 =
|
||||
std::make_shared<LogEvent>(tagId, bucketStartTimeNs + 2 * bucketSizeNs + 10);
|
||||
@@ -487,7 +480,7 @@ TEST(GaugeMetricProducerTest, TestAnomalyDetection) {
|
||||
.mFields->begin()
|
||||
->mValue.int_value);
|
||||
EXPECT_EQ(anomalyTracker->getRefractoryPeriodEndsSec(DEFAULT_METRIC_DIMENSION_KEY),
|
||||
std::ceil(1.0 * event2->GetElapsedTimestampNs() / NS_PER_SEC + refPeriodSec));
|
||||
std::ceil(1.0 * event2->GetElapsedTimestampNs() / NS_PER_SEC + refPeriodSec));
|
||||
|
||||
// The event4 does not have the gauge field. Thus the current bucket value is 0.
|
||||
std::shared_ptr<LogEvent> event4 =
|
||||
|
||||
@@ -62,8 +62,7 @@ TEST(ValueMetricProducerTest, TestNonDimensionalEvents) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
// TODO: pending refactor of StatsPullerManager
|
||||
// For now we still need this so that it doesn't do real pulling.
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -140,8 +139,7 @@ TEST(ValueMetricProducerTest, TestPulledEventsTakeAbsoluteValueOnReset) {
|
||||
metric.set_use_absolute_value_on_reset(true);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -214,8 +212,7 @@ TEST(ValueMetricProducerTest, TestPulledEventsTakeZeroOnReset) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -287,8 +284,7 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillRepeatedly(Return());
|
||||
|
||||
@@ -365,8 +361,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithUpgrade) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, -1, bucketStartTimeNs,
|
||||
bucketStartTimeNs, pullerManager);
|
||||
valueProducer.setBucketSize(60 * NS_PER_SEC);
|
||||
@@ -408,8 +403,7 @@ TEST(ValueMetricProducerTest, TestPulledValueWithUpgrade) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, Pull(tagId, _, _))
|
||||
@@ -464,8 +458,7 @@ TEST(ValueMetricProducerTest, TestPulledValueWithUpgradeWhileConditionFalse) {
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, Pull(tagId, _, _))
|
||||
@@ -514,8 +507,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
|
||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1, wizard, -1, bucketStartTimeNs,
|
||||
bucketStartTimeNs, pullerManager);
|
||||
@@ -556,8 +548,7 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithCondition) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
|
||||
ValueMetricProducer valueProducer(kConfigKey, metric, 1, wizard, -1, bucketStartTimeNs,
|
||||
bucketStartTimeNs, pullerManager);
|
||||
@@ -631,8 +622,10 @@ TEST(ValueMetricProducerTest, TestAnomalyDetection) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
ValueMetricProducer valueProducer(kConfigKey, metric, -1 /*-1 meaning no condition*/, wizard,
|
||||
-1 /*not pulled*/, bucketStartTimeNs, bucketStartTimeNs);
|
||||
-1 /*not pulled*/, bucketStartTimeNs, bucketStartTimeNs,
|
||||
pullerManager);
|
||||
valueProducer.setBucketSize(60 * NS_PER_SEC);
|
||||
|
||||
sp<AnomalyTracker> anomalyTracker = valueProducer.addAnomalyTracker(alert, alarmMonitor);
|
||||
@@ -705,8 +698,7 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryNoCondition) {
|
||||
metric.mutable_value_field()->add_child()->set_field(2);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
@@ -790,8 +782,7 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition) {
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillRepeatedly(Return());
|
||||
|
||||
@@ -873,8 +864,7 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition2) {
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillRepeatedly(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillRepeatedly(Return());
|
||||
|
||||
@@ -976,8 +966,7 @@ TEST(ValueMetricProducerTest, TestBucketBoundaryWithCondition3) {
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
make_shared<StrictMock<MockStatsPullerManager>>();
|
||||
sp<MockStatsPullerManager> pullerManager = new StrictMock<MockStatsPullerManager>();
|
||||
EXPECT_CALL(*pullerManager, RegisterReceiver(tagId, _, _, _)).WillOnce(Return());
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillRepeatedly(Return());
|
||||
|
||||
|
||||
@@ -452,14 +452,16 @@ std::unique_ptr<LogEvent> CreateIsolatedUidChangedEvent(
|
||||
sp<StatsLogProcessor> CreateStatsLogProcessor(const int64_t timeBaseNs, const int64_t currentTimeNs,
|
||||
const StatsdConfig& config, const ConfigKey& key) {
|
||||
sp<UidMap> uidMap = new UidMap();
|
||||
sp<StatsPullerManager> pullerManager = new StatsPullerManager();
|
||||
sp<AlarmMonitor> anomalyAlarmMonitor =
|
||||
new AlarmMonitor(1, [](const sp<IStatsCompanionService>&, int64_t){},
|
||||
[](const sp<IStatsCompanionService>&){});
|
||||
sp<AlarmMonitor> periodicAlarmMonitor =
|
||||
new AlarmMonitor(1, [](const sp<IStatsCompanionService>&, int64_t){},
|
||||
[](const sp<IStatsCompanionService>&){});
|
||||
sp<StatsLogProcessor> processor = new StatsLogProcessor(
|
||||
uidMap, anomalyAlarmMonitor, periodicAlarmMonitor, timeBaseNs, [](const ConfigKey&){return true;});
|
||||
sp<StatsLogProcessor> processor =
|
||||
new StatsLogProcessor(uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor,
|
||||
timeBaseNs, [](const ConfigKey&) { return true; });
|
||||
processor->OnConfigUpdated(currentTimeNs, key, config);
|
||||
return processor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user