1/ Change all "name" to id in statsD.
2/ Handle Subscription for alert. 3/ Support no_report_metric Bug: 69522276 Test: all statsd unit tests passed. Change-Id: I851b235f2d149b8602b0cad632d5bf541962f40a
This commit is contained in:
@@ -4368,10 +4368,10 @@ package android.util {
|
||||
}
|
||||
|
||||
public final class StatsManager {
|
||||
method public boolean addConfiguration(java.lang.String, byte[], java.lang.String, java.lang.String);
|
||||
method public byte[] getData(java.lang.String);
|
||||
method public boolean addConfiguration(long, byte[], java.lang.String, java.lang.String);
|
||||
method public byte[] getData(long);
|
||||
method public byte[] getMetadata();
|
||||
method public boolean removeConfiguration(java.lang.String);
|
||||
method public boolean removeConfiguration(long);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
android::hash_t hashDimensionsValue(const DimensionsValue& value) {
|
||||
android::hash_t hash = 0;
|
||||
android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value) {
|
||||
android::hash_t hash = seed;
|
||||
hash = android::JenkinsHashMix(hash, android::hash_type(value.field()));
|
||||
|
||||
hash = android::JenkinsHashMix(hash, android::hash_type((int)value.value_case()));
|
||||
@@ -63,6 +63,10 @@ android::hash_t hashDimensionsValue(const DimensionsValue& value) {
|
||||
return JenkinsHashWhiten(hash);
|
||||
}
|
||||
|
||||
android::hash_t hashDimensionsValue(const DimensionsValue& value) {
|
||||
return hashDimensionsValue(0, value);
|
||||
}
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
DimensionsValue mDimensionsValue;
|
||||
};
|
||||
|
||||
android::hash_t hashDimensionsValue(int64_t seed, const DimensionsValue& value);
|
||||
android::hash_t hashDimensionsValue(const DimensionsValue& value);
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
@@ -54,7 +54,7 @@ const int FIELD_ID_CONFIG_KEY = 1;
|
||||
const int FIELD_ID_REPORTS = 2;
|
||||
// for ConfigKey
|
||||
const int FIELD_ID_UID = 1;
|
||||
const int FIELD_ID_NAME = 2;
|
||||
const int FIELD_ID_ID = 2;
|
||||
// for ConfigMetricsReport
|
||||
const int FIELD_ID_METRICS = 1;
|
||||
const int FIELD_ID_UID_MAP = 2;
|
||||
@@ -157,7 +157,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, const uint64_t& dumpT
|
||||
return;
|
||||
}
|
||||
report->mutable_config_key()->set_uid(key.GetUid());
|
||||
report->mutable_config_key()->set_name(key.GetName());
|
||||
report->mutable_config_key()->set_id(key.GetId());
|
||||
ConfigMetricsReport* configMetricsReport = report->add_reports();
|
||||
it->second->onDumpReport(dumpTimeStampNs, configMetricsReport);
|
||||
// TODO: dump uid mapping.
|
||||
@@ -181,7 +181,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, vector<uint8_t>* outD
|
||||
// Start of ConfigKey.
|
||||
long long configKeyToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_CONFIG_KEY);
|
||||
proto.write(FIELD_TYPE_INT32 | FIELD_ID_UID, key.GetUid());
|
||||
proto.write(FIELD_TYPE_STRING | FIELD_ID_NAME, key.GetName());
|
||||
proto.write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)key.GetId());
|
||||
proto.end(configKeyToken);
|
||||
// End of ConfigKey.
|
||||
|
||||
@@ -278,8 +278,8 @@ void StatsLogProcessor::WriteDataToDisk() {
|
||||
vector<uint8_t> data;
|
||||
onDumpReport(key, &data);
|
||||
// TODO: Add a guardrail to prevent accumulation of file on disk.
|
||||
string file_name = StringPrintf("%s/%d-%s-%ld", STATS_DATA_DIR, key.GetUid(),
|
||||
key.GetName().c_str(), time(nullptr));
|
||||
string file_name = StringPrintf("%s/%d-%lld-%ld", STATS_DATA_DIR, key.GetUid(),
|
||||
(long long)key.GetId(), time(nullptr));
|
||||
StorageManager::writeFile(file_name.c_str(), &data[0], data.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) {
|
||||
print_cmd_help(out);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, name));
|
||||
auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, StrToInt64(name)));
|
||||
sp<IStatsCompanionService> sc = getStatsCompanionService();
|
||||
if (sc != nullptr) {
|
||||
sc->sendBroadcast(String16(receiver.first.c_str()), String16(receiver.second.c_str()));
|
||||
@@ -404,13 +404,13 @@ status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8
|
||||
}
|
||||
|
||||
// Add / update the config.
|
||||
mConfigManager->UpdateConfig(ConfigKey(uid, name), config);
|
||||
mConfigManager->UpdateConfig(ConfigKey(uid, StrToInt64(name)), config);
|
||||
} else {
|
||||
if (argCount == 2) {
|
||||
cmd_remove_all_configs(out);
|
||||
} else {
|
||||
// Remove the config.
|
||||
mConfigManager->RemoveConfig(ConfigKey(uid, name));
|
||||
mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String
|
||||
}
|
||||
if (good) {
|
||||
vector<uint8_t> data;
|
||||
mProcessor->onDumpReport(ConfigKey(uid, name), &data);
|
||||
mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), &data);
|
||||
// TODO: print the returned StatsLogReport to file instead of printing to logcat.
|
||||
if (proto) {
|
||||
for (size_t i = 0; i < data.size(); i ++) {
|
||||
@@ -699,12 +699,11 @@ void StatsService::OnLogEvent(const LogEvent& event) {
|
||||
mProcessor->OnLogEvent(event);
|
||||
}
|
||||
|
||||
Status StatsService::getData(const String16& key, vector<uint8_t>* output) {
|
||||
Status StatsService::getData(int64_t key, vector<uint8_t>* output) {
|
||||
IPCThreadState* ipc = IPCThreadState::self();
|
||||
VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
|
||||
if (checkCallingPermission(String16(kPermissionDump))) {
|
||||
string keyStr = string(String8(key).string());
|
||||
ConfigKey configKey(ipc->getCallingUid(), keyStr);
|
||||
ConfigKey configKey(ipc->getCallingUid(), key);
|
||||
mProcessor->onDumpReport(configKey, output);
|
||||
return Status::ok();
|
||||
} else {
|
||||
@@ -724,14 +723,13 @@ Status StatsService::getMetadata(vector<uint8_t>* output) {
|
||||
}
|
||||
}
|
||||
|
||||
Status StatsService::addConfiguration(const String16& key,
|
||||
Status StatsService::addConfiguration(int64_t key,
|
||||
const vector <uint8_t>& config,
|
||||
const String16& package, const String16& cls,
|
||||
bool* success) {
|
||||
IPCThreadState* ipc = IPCThreadState::self();
|
||||
if (checkCallingPermission(String16(kPermissionDump))) {
|
||||
string keyString = string(String8(key).string());
|
||||
ConfigKey configKey(ipc->getCallingUid(), keyString);
|
||||
ConfigKey configKey(ipc->getCallingUid(), key);
|
||||
StatsdConfig cfg;
|
||||
if (!cfg.ParseFromArray(&config[0], config.size())) {
|
||||
*success = false;
|
||||
@@ -748,11 +746,10 @@ Status StatsService::addConfiguration(const String16& key,
|
||||
}
|
||||
}
|
||||
|
||||
Status StatsService::removeConfiguration(const String16& key, bool* success) {
|
||||
Status StatsService::removeConfiguration(int64_t key, bool* success) {
|
||||
IPCThreadState* ipc = IPCThreadState::self();
|
||||
if (checkCallingPermission(String16(kPermissionDump))) {
|
||||
string keyStr = string(String8(key).string());
|
||||
mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), keyStr));
|
||||
mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), key));
|
||||
*success = true;
|
||||
return Status::ok();
|
||||
} else {
|
||||
|
||||
@@ -77,25 +77,27 @@ public:
|
||||
/**
|
||||
* Binder call for clients to request data for this configuration key.
|
||||
*/
|
||||
virtual Status getData(const String16& key, vector<uint8_t>* output) override;
|
||||
virtual Status getData(int64_t key, vector<uint8_t>* output) override;
|
||||
|
||||
|
||||
/**
|
||||
* Binder call for clients to get metadata across all configs in statsd.
|
||||
*/
|
||||
virtual Status getMetadata(vector<uint8_t>* output) override;
|
||||
|
||||
|
||||
/**
|
||||
* Binder call to let clients send a configuration and indicate they're interested when they
|
||||
* should requestData for this configuration.
|
||||
*/
|
||||
virtual Status addConfiguration(const String16& key, const vector <uint8_t>& config,
|
||||
const String16& package, const String16& cls, bool* success)
|
||||
virtual Status addConfiguration(int64_t key, const vector <uint8_t>& config,
|
||||
const String16& package, const String16& cls, bool* success)
|
||||
override;
|
||||
|
||||
/**
|
||||
* Binder call to allow clients to remove the specified configuration.
|
||||
*/
|
||||
virtual Status removeConfiguration(const String16& key, bool* success) override;
|
||||
virtual Status removeConfiguration(int64_t key, bool* success) override;
|
||||
|
||||
// TODO: public for testing since statsd doesn't run when system starts. Change to private
|
||||
// later.
|
||||
|
||||
@@ -205,23 +205,21 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) {
|
||||
// TODO: If we had access to the bucket_size_millis, consider calling resetStorage()
|
||||
// if (mAlert.refractory_period_secs() > mNumOfPastBuckets * bucketSizeNs) { resetStorage(); }
|
||||
|
||||
if (mAlert.has_incidentd_details()) {
|
||||
if (mAlert.has_name()) {
|
||||
ALOGI("An anomaly (%s) has occurred! Informing incidentd.",
|
||||
mAlert.name().c_str());
|
||||
if (!mSubscriptions.empty()) {
|
||||
if (mAlert.has_id()) {
|
||||
ALOGI("An anomaly (%llu) has occurred! Informing subscribers.",mAlert.id());
|
||||
informSubscribers();
|
||||
} else {
|
||||
// TODO: Can construct a name based on the criteria (and/or relay the criteria).
|
||||
ALOGI("An anomaly (nameless) has occurred! Informing incidentd.");
|
||||
ALOGI("An anomaly (with no id) has occurred! Not informing any subscribers.");
|
||||
}
|
||||
informIncidentd();
|
||||
} else {
|
||||
ALOGI("An anomaly has occurred! (But informing incidentd not requested.)");
|
||||
ALOGI("An anomaly has occurred! (But no subscriber for that alert.)");
|
||||
}
|
||||
|
||||
StatsdStats::getInstance().noteAnomalyDeclared(mConfigKey, mAlert.name());
|
||||
StatsdStats::getInstance().noteAnomalyDeclared(mConfigKey, mAlert.id());
|
||||
|
||||
android::util::stats_write(android::util::ANOMALY_DETECTED, mConfigKey.GetUid(),
|
||||
mConfigKey.GetName().c_str(), mAlert.name().c_str());
|
||||
mConfigKey.GetId(), mAlert.id());
|
||||
}
|
||||
|
||||
void AnomalyTracker::detectAndDeclareAnomaly(const uint64_t& timestampNs,
|
||||
@@ -246,27 +244,46 @@ bool AnomalyTracker::isInRefractoryPeriod(const uint64_t& timestampNs) const {
|
||||
timestampNs - mLastAnomalyTimestampNs <= mAlert.refractory_period_secs() * NS_PER_SEC;
|
||||
}
|
||||
|
||||
void AnomalyTracker::informIncidentd() {
|
||||
VLOG("informIncidentd called.");
|
||||
if (!mAlert.has_incidentd_details()) {
|
||||
ALOGE("Attempted to call incidentd without any incidentd_details.");
|
||||
return;
|
||||
}
|
||||
sp<IIncidentManager> service = interface_cast<IIncidentManager>(
|
||||
defaultServiceManager()->getService(android::String16("incident")));
|
||||
if (service == NULL) {
|
||||
ALOGW("Couldn't get the incident service.");
|
||||
void AnomalyTracker::informSubscribers() {
|
||||
VLOG("informSubscribers called.");
|
||||
if (mSubscriptions.empty()) {
|
||||
ALOGE("Attempt to call with no subscribers.");
|
||||
return;
|
||||
}
|
||||
|
||||
IncidentReportArgs incidentReport;
|
||||
const Alert::IncidentdDetails& details = mAlert.incidentd_details();
|
||||
for (int i = 0; i < details.section_size(); i++) {
|
||||
incidentReport.addSection(details.section(i));
|
||||
std::set<int> incidentdSections;
|
||||
for (const Subscription& subscription : mSubscriptions) {
|
||||
switch (subscription.subscriber_information_case()) {
|
||||
case Subscription::SubscriberInformationCase::kIncidentdDetails:
|
||||
for (int i = 0; i < subscription.incidentd_details().section_size(); i++) {
|
||||
incidentdSections.insert(subscription.incidentd_details().section(i));
|
||||
}
|
||||
break;
|
||||
case Subscription::SubscriberInformationCase::kPerfettoDetails:
|
||||
ALOGW("Perfetto reports not implemented.");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!incidentdSections.empty()) {
|
||||
sp<IIncidentManager> service = interface_cast<IIncidentManager>(
|
||||
defaultServiceManager()->getService(android::String16("incident")));
|
||||
if (service != NULL) {
|
||||
IncidentReportArgs incidentReport;
|
||||
for (const auto section : incidentdSections) {
|
||||
incidentReport.addSection(section);
|
||||
}
|
||||
int64_t alertId = mAlert.id();
|
||||
std::vector<uint8_t> header;
|
||||
uint8_t* src = static_cast<uint8_t*>(static_cast<void*>(&alertId));
|
||||
header.insert(header.end(), src, src + sizeof(int64_t));
|
||||
incidentReport.addHeader(header);
|
||||
service->reportIncident(incidentReport);
|
||||
} else {
|
||||
ALOGW("Couldn't get the incident service.");
|
||||
}
|
||||
}
|
||||
// TODO: Pass in mAlert.name() into the addHeader?
|
||||
|
||||
service->reportIncident(incidentReport);
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
@@ -40,6 +40,11 @@ public:
|
||||
|
||||
virtual ~AnomalyTracker();
|
||||
|
||||
// Add subscriptions that depend on this alert.
|
||||
void addSubscription(const Subscription& subscription) {
|
||||
mSubscriptions.push_back(subscription);
|
||||
}
|
||||
|
||||
// Adds a bucket.
|
||||
// Bucket index starts from 0.
|
||||
void addPastBucket(std::shared_ptr<DimToValMap> bucketValues, const int64_t& bucketNum);
|
||||
@@ -97,6 +102,9 @@ protected:
|
||||
// statsd_config.proto Alert message that defines this tracker.
|
||||
const Alert mAlert;
|
||||
|
||||
// The subscriptions that depend on this alert.
|
||||
std::vector<Subscription> mSubscriptions;
|
||||
|
||||
// A reference to the Alert's config key.
|
||||
const ConfigKey& mConfigKey;
|
||||
|
||||
@@ -104,7 +112,7 @@ protected:
|
||||
// for the anomaly detection (since the current bucket is not in the past).
|
||||
int mNumOfPastBuckets;
|
||||
|
||||
// The exisiting bucket list.
|
||||
// The existing bucket list.
|
||||
std::vector<shared_ptr<DimToValMap>> mPastBuckets;
|
||||
|
||||
// Sum over all existing buckets cached in mPastBuckets.
|
||||
@@ -133,8 +141,8 @@ protected:
|
||||
// Resets all bucket data. For use when all the data gets stale.
|
||||
virtual void resetStorage();
|
||||
|
||||
// Informs the incident service that an anomaly has occurred.
|
||||
void informIncidentd();
|
||||
// Informs the subscribers that an anomaly has occurred.
|
||||
void informSubscribers();
|
||||
|
||||
FRIEND_TEST(AnomalyTrackerTest, TestConsecutiveBuckets);
|
||||
FRIEND_TEST(AnomalyTrackerTest, TestSparseBuckets);
|
||||
|
||||
@@ -845,11 +845,11 @@ message AnomalyDetected {
|
||||
// Uid that owns the config whose anomaly detection alert fired.
|
||||
optional int32 config_uid = 1;
|
||||
|
||||
// Name of the config whose anomaly detection alert fired.
|
||||
optional string config_name = 2;
|
||||
// Id of the config whose anomaly detection alert fired.
|
||||
optional int64 config_id = 2;
|
||||
|
||||
// Name of the alert (i.e. name of the anomaly that was detected).
|
||||
optional string alert_name = 3;
|
||||
// Id of the alert (i.e. name of the anomaly that was detected).
|
||||
optional int64 alert_id = 3;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,20 +30,20 @@ using std::unique_ptr;
|
||||
using std::unordered_map;
|
||||
using std::vector;
|
||||
|
||||
CombinationConditionTracker::CombinationConditionTracker(const string& name, const int index)
|
||||
: ConditionTracker(name, index) {
|
||||
VLOG("creating CombinationConditionTracker %s", mName.c_str());
|
||||
CombinationConditionTracker::CombinationConditionTracker(const int64_t& id, const int index)
|
||||
: ConditionTracker(id, index) {
|
||||
VLOG("creating CombinationConditionTracker %lld", (long long)mConditionId);
|
||||
}
|
||||
|
||||
CombinationConditionTracker::~CombinationConditionTracker() {
|
||||
VLOG("~CombinationConditionTracker() %s", mName.c_str());
|
||||
VLOG("~CombinationConditionTracker() %lld", (long long)mConditionId);
|
||||
}
|
||||
|
||||
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
||||
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
const unordered_map<string, int>& conditionNameIndexMap,
|
||||
const unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||
vector<bool>& stack) {
|
||||
VLOG("Combination predicate init() %s", mName.c_str());
|
||||
VLOG("Combination predicate init() %lld", (long long)mConditionId);
|
||||
if (mInitialized) {
|
||||
return true;
|
||||
}
|
||||
@@ -62,11 +62,11 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
|
||||
return false;
|
||||
}
|
||||
|
||||
for (string child : combinationCondition.predicate()) {
|
||||
auto it = conditionNameIndexMap.find(child);
|
||||
for (auto child : combinationCondition.predicate()) {
|
||||
auto it = conditionIdIndexMap.find(child);
|
||||
|
||||
if (it == conditionNameIndexMap.end()) {
|
||||
ALOGW("Predicate %s not found in the config", child.c_str());
|
||||
if (it == conditionIdIndexMap.end()) {
|
||||
ALOGW("Predicate %lld not found in the config", (long long)child);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
|
||||
}
|
||||
|
||||
bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers,
|
||||
conditionNameIndexMap, stack);
|
||||
conditionIdIndexMap, stack);
|
||||
|
||||
if (!initChildSucceeded) {
|
||||
ALOGW("Child initialization failed %s ", child.c_str());
|
||||
ALOGW("Child initialization failed %lld ", (long long)child);
|
||||
return false;
|
||||
} else {
|
||||
ALOGW("Child initialization success %s ", child.c_str());
|
||||
ALOGW("Child initialization success %lld ", (long long)child);
|
||||
}
|
||||
|
||||
mChildren.push_back(childIndex);
|
||||
@@ -154,8 +154,8 @@ void CombinationConditionTracker::evaluateCondition(
|
||||
}
|
||||
}
|
||||
nonSlicedConditionCache[mIndex] = ConditionState::kUnknown;
|
||||
ALOGD("CombinationPredicate %s sliced may changed? %d", mName.c_str(),
|
||||
conditionChangedCache[mIndex] == true);
|
||||
ALOGD("CombinationPredicate %lld sliced may changed? %d", (long long)mConditionId,
|
||||
conditionChangedCache[mIndex] == true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ namespace statsd {
|
||||
|
||||
class CombinationConditionTracker : public virtual ConditionTracker {
|
||||
public:
|
||||
CombinationConditionTracker(const std::string& name, const int index);
|
||||
CombinationConditionTracker(const int64_t& id, const int index);
|
||||
|
||||
~CombinationConditionTracker();
|
||||
|
||||
bool init(const std::vector<Predicate>& allConditionConfig,
|
||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
const std::unordered_map<std::string, int>& conditionNameIndexMap,
|
||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||
std::vector<bool>& stack) override;
|
||||
|
||||
void evaluateCondition(const LogEvent& event,
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace statsd {
|
||||
|
||||
class ConditionTracker : public virtual RefBase {
|
||||
public:
|
||||
ConditionTracker(const std::string& name, const int index)
|
||||
: mName(name),
|
||||
ConditionTracker(const int64_t& id, const int index)
|
||||
: mConditionId(id),
|
||||
mIndex(index),
|
||||
mInitialized(false),
|
||||
mTrackerIndex(),
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
virtual ~ConditionTracker(){};
|
||||
|
||||
inline const string& getName() { return mName; }
|
||||
inline const int64_t& getId() { return mConditionId; }
|
||||
|
||||
// Initialize this ConditionTracker. This initialization is done recursively (DFS). It can also
|
||||
// be done in the constructor, but we do it separately because (1) easy to return a bool to
|
||||
@@ -50,11 +50,11 @@ public:
|
||||
// allConditionConfig: the list of all Predicate config from statsd_config.
|
||||
// allConditionTrackers: the list of all ConditionTrackers (this is needed because we may also
|
||||
// need to call init() on children conditions)
|
||||
// conditionNameIndexMap: the mapping from condition name to its index.
|
||||
// conditionIdIndexMap: the mapping from condition id to its index.
|
||||
// stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
|
||||
virtual bool init(const std::vector<Predicate>& allConditionConfig,
|
||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
const std::unordered_map<std::string, int>& conditionNameIndexMap,
|
||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||
std::vector<bool>& stack) = 0;
|
||||
|
||||
// evaluate current condition given the new event.
|
||||
@@ -99,9 +99,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
// We don't really need the string name, but having a name here makes log messages
|
||||
// easy to debug.
|
||||
const std::string mName;
|
||||
const int64_t mConditionId;
|
||||
|
||||
// the index of this condition in the manager's condition list.
|
||||
const int mIndex;
|
||||
|
||||
@@ -33,17 +33,17 @@ using std::unordered_map;
|
||||
using std::vector;
|
||||
|
||||
SimpleConditionTracker::SimpleConditionTracker(
|
||||
const ConfigKey& key, const string& name, const int index,
|
||||
const ConfigKey& key, const int64_t& id, const int index,
|
||||
const SimplePredicate& simplePredicate,
|
||||
const unordered_map<string, int>& trackerNameIndexMap)
|
||||
: ConditionTracker(name, index), mConfigKey(key) {
|
||||
VLOG("creating SimpleConditionTracker %s", mName.c_str());
|
||||
const unordered_map<int64_t, int>& trackerNameIndexMap)
|
||||
: ConditionTracker(id, index), mConfigKey(key) {
|
||||
VLOG("creating SimpleConditionTracker %lld", (long long)mConditionId);
|
||||
mCountNesting = simplePredicate.count_nesting();
|
||||
|
||||
if (simplePredicate.has_start()) {
|
||||
auto pair = trackerNameIndexMap.find(simplePredicate.start());
|
||||
if (pair == trackerNameIndexMap.end()) {
|
||||
ALOGW("Start matcher %s not found in the config", simplePredicate.start().c_str());
|
||||
ALOGW("Start matcher %lld not found in the config", (long long)simplePredicate.start());
|
||||
return;
|
||||
}
|
||||
mStartLogMatcherIndex = pair->second;
|
||||
@@ -55,7 +55,7 @@ SimpleConditionTracker::SimpleConditionTracker(
|
||||
if (simplePredicate.has_stop()) {
|
||||
auto pair = trackerNameIndexMap.find(simplePredicate.stop());
|
||||
if (pair == trackerNameIndexMap.end()) {
|
||||
ALOGW("Stop matcher %s not found in the config", simplePredicate.stop().c_str());
|
||||
ALOGW("Stop matcher %lld not found in the config", (long long)simplePredicate.stop());
|
||||
return;
|
||||
}
|
||||
mStopLogMatcherIndex = pair->second;
|
||||
@@ -67,7 +67,7 @@ SimpleConditionTracker::SimpleConditionTracker(
|
||||
if (simplePredicate.has_stop_all()) {
|
||||
auto pair = trackerNameIndexMap.find(simplePredicate.stop_all());
|
||||
if (pair == trackerNameIndexMap.end()) {
|
||||
ALOGW("Stop all matcher %s not found in the config", simplePredicate.stop().c_str());
|
||||
ALOGW("Stop all matcher %lld found in the config", (long long)simplePredicate.stop_all());
|
||||
return;
|
||||
}
|
||||
mStopAllLogMatcherIndex = pair->second;
|
||||
@@ -99,15 +99,15 @@ SimpleConditionTracker::~SimpleConditionTracker() {
|
||||
|
||||
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
|
||||
const vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
const unordered_map<string, int>& conditionNameIndexMap,
|
||||
const unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||
vector<bool>& stack) {
|
||||
// SimpleConditionTracker does not have dependency on other conditions, thus we just return
|
||||
// if the initialization was successful.
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
void print(map<HashableDimensionKey, int>& conditions, const string& name) {
|
||||
VLOG("%s DUMP:", name.c_str());
|
||||
void print(map<HashableDimensionKey, int>& conditions, const int64_t& id) {
|
||||
VLOG("%lld DUMP:", (long long)id);
|
||||
for (const auto& pair : conditions) {
|
||||
VLOG("\t%s : %d", pair.first.c_str(), pair.second);
|
||||
}
|
||||
@@ -135,10 +135,11 @@ bool SimpleConditionTracker::hitGuardRail(const HashableDimensionKey& newKey) {
|
||||
// 1. Report the tuple count if the tuple count > soft limit
|
||||
if (mSlicedConditionState.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mSlicedConditionState.size() + 1;
|
||||
StatsdStats::getInstance().noteConditionDimensionSize(mConfigKey, mName, newTupleCount);
|
||||
StatsdStats::getInstance().noteConditionDimensionSize(mConfigKey, mConditionId, newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("Predicate %s dropping data for dimension key %s", mName.c_str(), newKey.c_str());
|
||||
ALOGE("Predicate %lld dropping data for dimension key %s",
|
||||
(long long)mConditionId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -222,13 +223,13 @@ void SimpleConditionTracker::handleConditionEvent(const HashableDimensionKey& ou
|
||||
|
||||
// dump all dimensions for debugging
|
||||
if (DEBUG) {
|
||||
print(mSlicedConditionState, mName);
|
||||
print(mSlicedConditionState, mConditionId);
|
||||
}
|
||||
|
||||
conditionChangedCache[mIndex] = changed;
|
||||
conditionCache[mIndex] = newCondition;
|
||||
|
||||
VLOG("SimplePredicate %s nonSlicedChange? %d", mName.c_str(),
|
||||
VLOG("SimplePredicate %lld nonSlicedChange? %d", (long long)mConditionId,
|
||||
conditionChangedCache[mIndex] == true);
|
||||
}
|
||||
|
||||
@@ -239,7 +240,8 @@ void SimpleConditionTracker::evaluateCondition(const LogEvent& event,
|
||||
vector<bool>& conditionChangedCache) {
|
||||
if (conditionCache[mIndex] != ConditionState::kNotEvaluated) {
|
||||
// it has been evaluated.
|
||||
VLOG("Yes, already evaluated, %s %d", mName.c_str(), conditionCache[mIndex]);
|
||||
VLOG("Yes, already evaluated, %lld %d",
|
||||
(long long)mConditionId, conditionCache[mIndex]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -320,11 +322,11 @@ void SimpleConditionTracker::isConditionMet(
|
||||
const ConditionKey& conditionParameters,
|
||||
const vector<sp<ConditionTracker>>& allConditions,
|
||||
vector<ConditionState>& conditionCache) const {
|
||||
const auto pair = conditionParameters.find(mName);
|
||||
const auto pair = conditionParameters.find(mConditionId);
|
||||
|
||||
if (pair == conditionParameters.end() && mOutputDimensions.child_size() > 0) {
|
||||
ALOGE("Predicate %s output has dimension, but it's not specified in the query!",
|
||||
mName.c_str());
|
||||
ALOGE("Predicate %lld output has dimension, but it's not specified in the query!",
|
||||
(long long)mConditionId);
|
||||
conditionCache[mIndex] = mInitialValue;
|
||||
return;
|
||||
}
|
||||
@@ -343,7 +345,7 @@ void SimpleConditionTracker::isConditionMet(
|
||||
}
|
||||
}
|
||||
conditionCache[mIndex] = conditionState;
|
||||
VLOG("Predicate %s return %d", mName.c_str(), conditionCache[mIndex]);
|
||||
VLOG("Predicate %lld return %d", (long long)mConditionId, conditionCache[mIndex]);
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
@@ -29,15 +29,15 @@ namespace statsd {
|
||||
|
||||
class SimpleConditionTracker : public virtual ConditionTracker {
|
||||
public:
|
||||
SimpleConditionTracker(const ConfigKey& key, const std::string& name, const int index,
|
||||
SimpleConditionTracker(const ConfigKey& key, const int64_t& id, const int index,
|
||||
const SimplePredicate& simplePredicate,
|
||||
const std::unordered_map<std::string, int>& trackerNameIndexMap);
|
||||
const std::unordered_map<int64_t, int>& trackerNameIndexMap);
|
||||
|
||||
~SimpleConditionTracker();
|
||||
|
||||
bool init(const std::vector<Predicate>& allConditionConfig,
|
||||
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
const std::unordered_map<std::string, int>& conditionNameIndexMap,
|
||||
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
|
||||
std::vector<bool>& stack) override;
|
||||
|
||||
void evaluateCondition(const LogEvent& event,
|
||||
|
||||
@@ -27,10 +27,10 @@ using std::ostringstream;
|
||||
ConfigKey::ConfigKey() {
|
||||
}
|
||||
|
||||
ConfigKey::ConfigKey(const ConfigKey& that) : mName(that.mName), mUid(that.mUid) {
|
||||
ConfigKey::ConfigKey(const ConfigKey& that) : mId(that.mId), mUid(that.mUid) {
|
||||
}
|
||||
|
||||
ConfigKey::ConfigKey(int uid, const string& name) : mName(name), mUid(uid) {
|
||||
ConfigKey::ConfigKey(int uid, const int64_t& id) : mId(id), mUid(uid) {
|
||||
}
|
||||
|
||||
ConfigKey::~ConfigKey() {
|
||||
@@ -38,10 +38,21 @@ ConfigKey::~ConfigKey() {
|
||||
|
||||
string ConfigKey::ToString() const {
|
||||
ostringstream out;
|
||||
out << '(' << mUid << ',' << mName << ')';
|
||||
out << '(' << mUid << ',' << mId << ')';
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
int64_t StrToInt64(const string& str) {
|
||||
char* endp;
|
||||
int64_t value;
|
||||
value = strtoll(str.c_str(), &endp, 0);
|
||||
if (endp == str.c_str() || *endp != '\0') {
|
||||
value = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
|
||||
@@ -37,14 +37,14 @@ class ConfigKey {
|
||||
public:
|
||||
ConfigKey();
|
||||
explicit ConfigKey(const ConfigKey& that);
|
||||
ConfigKey(int uid, const string& name);
|
||||
ConfigKey(int uid, const int64_t& id);
|
||||
~ConfigKey();
|
||||
|
||||
inline int GetUid() const {
|
||||
return mUid;
|
||||
}
|
||||
inline const string& GetName() const {
|
||||
return mName;
|
||||
inline const int64_t& GetId() const {
|
||||
return mId;
|
||||
}
|
||||
|
||||
inline bool operator<(const ConfigKey& that) const {
|
||||
@@ -54,17 +54,17 @@ public:
|
||||
if (mUid > that.mUid) {
|
||||
return false;
|
||||
}
|
||||
return mName < that.mName;
|
||||
return mId < that.mId;
|
||||
};
|
||||
|
||||
inline bool operator==(const ConfigKey& that) const {
|
||||
return mUid == that.mUid && mName == that.mName;
|
||||
return mUid == that.mUid && mId == that.mId;
|
||||
};
|
||||
|
||||
string ToString() const;
|
||||
|
||||
private:
|
||||
string mName;
|
||||
int64_t mId;
|
||||
int mUid;
|
||||
};
|
||||
|
||||
@@ -72,6 +72,8 @@ inline ostream& operator<<(ostream& os, const ConfigKey& config) {
|
||||
return os << config.ToString();
|
||||
}
|
||||
|
||||
int64_t StrToInt64(const string& str);
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
@@ -87,7 +89,7 @@ using android::os::statsd::ConfigKey;
|
||||
template <>
|
||||
struct hash<ConfigKey> {
|
||||
std::size_t operator()(const ConfigKey& key) const {
|
||||
return (7 * key.GetUid()) ^ ((hash<string>()(key.GetName())));
|
||||
return (7 * key.GetUid()) ^ ((hash<long long>()(key.GetId())));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void ConfigManager::RemoveConfig(const ConfigKey& key) {
|
||||
}
|
||||
|
||||
void ConfigManager::remove_saved_configs(const ConfigKey& key) {
|
||||
string prefix = StringPrintf("%d-%s", key.GetUid(), key.GetName().c_str());
|
||||
string prefix = StringPrintf("%d-%lld", key.GetUid(), (long long)key.GetId());
|
||||
StorageManager::deletePrefixedFiles(STATS_SERVICE_DIR, prefix.c_str());
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ void ConfigManager::Dump(FILE* out) {
|
||||
fprintf(out, "CONFIGURATIONS (%d)\n", (int)mConfigs.size());
|
||||
fprintf(out, " uid name\n");
|
||||
for (const auto& key : mConfigs) {
|
||||
fprintf(out, " %6d %s\n", key.GetUid(), key.GetName().c_str());
|
||||
fprintf(out, " %6d %lld\n", key.GetUid(), (long long)key.GetId());
|
||||
auto receiverIt = mConfigReceivers.find(key);
|
||||
if (receiverIt != mConfigReceivers.end()) {
|
||||
fprintf(out, " -> received by %s, %s\n", receiverIt->second.first.c_str(),
|
||||
@@ -189,8 +189,8 @@ void ConfigManager::update_saved_configs(const ConfigKey& key, const StatsdConfi
|
||||
remove_saved_configs(key);
|
||||
|
||||
// Then we save the latest config.
|
||||
string file_name = StringPrintf("%s/%d-%s-%ld", STATS_SERVICE_DIR, key.GetUid(),
|
||||
key.GetName().c_str(), time(nullptr));
|
||||
string file_name = StringPrintf("%s/%d-%lld-%ld", STATS_SERVICE_DIR, key.GetUid(),
|
||||
(long long)key.GetId(), time(nullptr));
|
||||
const int numBytes = config.ByteSize();
|
||||
vector<uint8_t> buffer(numBytes);
|
||||
config.SerializeToArray(&buffer[0], numBytes);
|
||||
@@ -200,7 +200,7 @@ void ConfigManager::update_saved_configs(const ConfigKey& key, const StatsdConfi
|
||||
StatsdConfig build_fake_config() {
|
||||
// HACK: Hard code a test metric for counting screen on events...
|
||||
StatsdConfig config;
|
||||
config.set_name("CONFIG_12345");
|
||||
config.set_id(12345);
|
||||
|
||||
int WAKE_LOCK_TAG_ID = 1111; // put a fake id here to make testing easier.
|
||||
int WAKE_LOCK_UID_KEY_ID = 1;
|
||||
@@ -232,14 +232,14 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Count Screen ON events.
|
||||
CountMetric* metric = config.add_count_metric();
|
||||
metric->set_name("METRIC_1");
|
||||
metric->set_what("SCREEN_TURNED_ON");
|
||||
metric->set_id(1); // METRIC_1
|
||||
metric->set_what(102); // "SCREEN_TURNED_ON"
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
|
||||
// Anomaly threshold for screen-on count.
|
||||
// TODO(b/70627390): Uncomment once the bug is fixed.
|
||||
/*Alert* alert = config.add_alert();
|
||||
alert->set_name("ALERT_1");
|
||||
alert->set_id("ALERT_1");
|
||||
alert->set_metric_name("METRIC_1");
|
||||
alert->set_number_of_buckets(6);
|
||||
alert->set_trigger_if_sum_gt(10);
|
||||
@@ -256,8 +256,8 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Count process state changes, slice by uid.
|
||||
metric = config.add_count_metric();
|
||||
metric->set_name("METRIC_2");
|
||||
metric->set_what("PROCESS_STATE_CHANGE");
|
||||
metric->set_id(2); // "METRIC_2"
|
||||
metric->set_what(104);
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
FieldMatcher* dimensions = metric->mutable_dimensions();
|
||||
dimensions->set_field(UID_PROCESS_STATE_TAG_ID);
|
||||
@@ -267,7 +267,7 @@ StatsdConfig build_fake_config() {
|
||||
// TODO(b/70627390): Uncomment once the bug is fixed.
|
||||
/*
|
||||
alert = config.add_alert();
|
||||
alert->set_name("ALERT_2");
|
||||
alert->set_id("ALERT_2");
|
||||
alert->set_metric_name("METRIC_2");
|
||||
alert->set_number_of_buckets(4);
|
||||
alert->set_trigger_if_sum_gt(30);
|
||||
@@ -278,28 +278,28 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Count process state changes, slice by uid, while SCREEN_IS_OFF
|
||||
metric = config.add_count_metric();
|
||||
metric->set_name("METRIC_3");
|
||||
metric->set_what("PROCESS_STATE_CHANGE");
|
||||
metric->set_id(3);
|
||||
metric->set_what(104);
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
|
||||
dimensions = metric->mutable_dimensions();
|
||||
dimensions->set_field(UID_PROCESS_STATE_TAG_ID);
|
||||
dimensions->add_child()->set_field(UID_PROCESS_STATE_UID_KEY);
|
||||
metric->set_condition("SCREEN_IS_OFF");
|
||||
metric->set_condition(202);
|
||||
|
||||
// Count wake lock, slice by uid, while SCREEN_IS_ON and app in background
|
||||
metric = config.add_count_metric();
|
||||
metric->set_name("METRIC_4");
|
||||
metric->set_what("APP_GET_WL");
|
||||
metric->set_id(4);
|
||||
metric->set_what(107);
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
dimensions = metric->mutable_dimensions();
|
||||
dimensions->set_field(WAKE_LOCK_TAG_ID);
|
||||
dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
|
||||
|
||||
metric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
metric->set_condition(204);
|
||||
MetricConditionLink* link = metric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->set_condition(203);
|
||||
link->mutable_dimensions_in_what()->set_field(WAKE_LOCK_TAG_ID);
|
||||
link->mutable_dimensions_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
link->mutable_dimensions_in_condition()->set_field(APP_USAGE_TAG_ID);
|
||||
@@ -307,16 +307,16 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Duration of an app holding any wl, while screen on and app in background, slice by uid
|
||||
DurationMetric* durationMetric = config.add_duration_metric();
|
||||
durationMetric->set_name("METRIC_5");
|
||||
durationMetric->set_id(5);
|
||||
durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||
dimensions = durationMetric->mutable_dimensions();
|
||||
dimensions->set_field(WAKE_LOCK_TAG_ID);
|
||||
dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
durationMetric->set_what(205);
|
||||
durationMetric->set_condition(204);
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->set_condition(203);
|
||||
link->mutable_dimensions_in_what()->set_field(WAKE_LOCK_TAG_ID);
|
||||
link->mutable_dimensions_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
link->mutable_dimensions_in_condition()->set_field(APP_USAGE_TAG_ID);
|
||||
@@ -324,16 +324,16 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// max Duration of an app holding any wl, while screen on and app in background, slice by uid
|
||||
durationMetric = config.add_duration_metric();
|
||||
durationMetric->set_name("METRIC_6");
|
||||
durationMetric->set_id(6);
|
||||
durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE);
|
||||
dimensions = durationMetric->mutable_dimensions();
|
||||
dimensions->set_field(WAKE_LOCK_TAG_ID);
|
||||
dimensions->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
durationMetric->set_what(205);
|
||||
durationMetric->set_condition(204);
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->set_condition(203);
|
||||
link->mutable_dimensions_in_what()->set_field(WAKE_LOCK_TAG_ID);
|
||||
link->mutable_dimensions_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
link->mutable_dimensions_in_condition()->set_field(APP_USAGE_TAG_ID);
|
||||
@@ -341,13 +341,13 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Duration of an app holding any wl, while screen on and app in background
|
||||
durationMetric = config.add_duration_metric();
|
||||
durationMetric->set_name("METRIC_7");
|
||||
durationMetric->set_id(7);
|
||||
durationMetric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
durationMetric->set_aggregation_type(DurationMetric_AggregationType_MAX_SPARSE);
|
||||
durationMetric->set_what("WL_HELD_PER_APP_PER_NAME");
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
durationMetric->set_what(205);
|
||||
durationMetric->set_condition(204);
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->set_condition(203);
|
||||
link->mutable_dimensions_in_what()->set_field(WAKE_LOCK_TAG_ID);
|
||||
link->mutable_dimensions_in_what()->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
link->mutable_dimensions_in_condition()->set_field(APP_USAGE_TAG_ID);
|
||||
@@ -356,17 +356,17 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Duration of screen on time.
|
||||
durationMetric = config.add_duration_metric();
|
||||
durationMetric->set_name("METRIC_8");
|
||||
durationMetric->set_id(8);
|
||||
durationMetric->mutable_bucket()->set_bucket_size_millis(10 * 1000L);
|
||||
durationMetric->set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||
durationMetric->set_what("SCREEN_IS_ON");
|
||||
durationMetric->set_what(201);
|
||||
|
||||
// Anomaly threshold for background count.
|
||||
// TODO(b/70627390): Uncomment once the bug is fixed.
|
||||
/*
|
||||
alert = config.add_alert();
|
||||
alert->set_name("ALERT_8");
|
||||
alert->set_metric_name("METRIC_8");
|
||||
alert->set_id(308);
|
||||
alert->set_metric_id(8);
|
||||
alert->set_number_of_buckets(4);
|
||||
alert->set_trigger_if_sum_gt(2000000000); // 2 seconds
|
||||
alert->set_refractory_period_secs(120);
|
||||
@@ -375,10 +375,10 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Value metric to count KERNEL_WAKELOCK when screen turned on
|
||||
ValueMetric* valueMetric = config.add_value_metric();
|
||||
valueMetric->set_name("METRIC_6");
|
||||
valueMetric->set_what("KERNEL_WAKELOCK");
|
||||
valueMetric->set_id(11);
|
||||
valueMetric->set_what(109);
|
||||
valueMetric->set_value_field(KERNEL_WAKELOCK_COUNT_KEY);
|
||||
valueMetric->set_condition("SCREEN_IS_ON");
|
||||
valueMetric->set_condition(201);
|
||||
dimensions = valueMetric->mutable_dimensions();
|
||||
dimensions->set_field(KERNEL_WAKELOCK_TAG_ID);
|
||||
dimensions->add_child()->set_field(KERNEL_WAKELOCK_NAME_KEY);
|
||||
@@ -387,13 +387,13 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Add an EventMetric to log process state change events.
|
||||
EventMetric* eventMetric = config.add_event_metric();
|
||||
eventMetric->set_name("METRIC_9");
|
||||
eventMetric->set_what("SCREEN_TURNED_ON");
|
||||
eventMetric->set_id(9);
|
||||
eventMetric->set_what(102); // "SCREEN_TURNED_ON"
|
||||
|
||||
// Add an GaugeMetric.
|
||||
GaugeMetric* gaugeMetric = config.add_gauge_metric();
|
||||
gaugeMetric->set_name("METRIC_10");
|
||||
gaugeMetric->set_what("DEVICE_TEMPERATURE");
|
||||
gaugeMetric->set_id(10);
|
||||
gaugeMetric->set_what(101);
|
||||
auto gaugeFieldMatcher = gaugeMetric->mutable_gauge_fields_filter()->mutable_fields();
|
||||
gaugeFieldMatcher->set_field(DEVICE_TEMPERATURE_TAG_ID);
|
||||
gaugeFieldMatcher->add_child()->set_field(DEVICE_TEMPERATURE_KEY);
|
||||
@@ -401,12 +401,12 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// Event matchers.
|
||||
AtomMatcher* temperatureAtomMatcher = config.add_atom_matcher();
|
||||
temperatureAtomMatcher->set_name("DEVICE_TEMPERATURE");
|
||||
temperatureAtomMatcher->set_id(101); // "DEVICE_TEMPERATURE"
|
||||
temperatureAtomMatcher->mutable_simple_atom_matcher()->set_atom_id(
|
||||
DEVICE_TEMPERATURE_TAG_ID);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_TURNED_ON");
|
||||
eventMatcher->set_id(102); // "SCREEN_TURNED_ON"
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(SCREEN_EVENT_TAG_ID);
|
||||
FieldValueMatcher* fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -414,7 +414,7 @@ StatsdConfig build_fake_config() {
|
||||
fieldValueMatcher->set_eq_int(SCREEN_EVENT_ON_VALUE);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_TURNED_OFF");
|
||||
eventMatcher->set_id(103); // "SCREEN_TURNED_OFF"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(SCREEN_EVENT_TAG_ID);
|
||||
fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -422,12 +422,12 @@ StatsdConfig build_fake_config() {
|
||||
fieldValueMatcher->set_eq_int(SCREEN_EVENT_OFF_VALUE);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("PROCESS_STATE_CHANGE");
|
||||
eventMatcher->set_id(104); // "PROCESS_STATE_CHANGE"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(UID_PROCESS_STATE_TAG_ID);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("APP_GOES_BACKGROUND");
|
||||
eventMatcher->set_id(105); // "APP_GOES_BACKGROUND"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(APP_USAGE_TAG_ID);
|
||||
fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -435,7 +435,7 @@ StatsdConfig build_fake_config() {
|
||||
fieldValueMatcher->set_eq_int(APP_USAGE_BACKGROUND);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("APP_GOES_FOREGROUND");
|
||||
eventMatcher->set_id(106); // "APP_GOES_FOREGROUND"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(APP_USAGE_TAG_ID);
|
||||
fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -443,7 +443,7 @@ StatsdConfig build_fake_config() {
|
||||
fieldValueMatcher->set_eq_int(APP_USAGE_FOREGROUND);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("APP_GET_WL");
|
||||
eventMatcher->set_id(107); // "APP_GET_WL"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(WAKE_LOCK_TAG_ID);
|
||||
fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -451,7 +451,7 @@ StatsdConfig build_fake_config() {
|
||||
fieldValueMatcher->set_eq_int(WAKE_LOCK_ACQUIRE_VALUE);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("APP_RELEASE_WL");
|
||||
eventMatcher->set_id(108); //"APP_RELEASE_WL"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(WAKE_LOCK_TAG_ID);
|
||||
fieldValueMatcher = simpleAtomMatcher->add_field_value_matcher();
|
||||
@@ -460,47 +460,47 @@ StatsdConfig build_fake_config() {
|
||||
|
||||
// pulled events
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("KERNEL_WAKELOCK");
|
||||
eventMatcher->set_id(109); // "KERNEL_WAKELOCK"
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(KERNEL_WAKELOCK_TAG_ID);
|
||||
|
||||
// Predicates.............
|
||||
Predicate* predicate = config.add_predicate();
|
||||
predicate->set_name("SCREEN_IS_ON");
|
||||
predicate->set_id(201); // "SCREEN_IS_ON"
|
||||
SimplePredicate* simplePredicate = predicate->mutable_simple_predicate();
|
||||
simplePredicate->set_start("SCREEN_TURNED_ON");
|
||||
simplePredicate->set_stop("SCREEN_TURNED_OFF");
|
||||
simplePredicate->set_start(102); // "SCREEN_TURNED_ON"
|
||||
simplePredicate->set_stop(103);
|
||||
simplePredicate->set_count_nesting(false);
|
||||
|
||||
predicate = config.add_predicate();
|
||||
predicate->set_name("SCREEN_IS_OFF");
|
||||
predicate->set_id(202); // "SCREEN_IS_OFF"
|
||||
simplePredicate = predicate->mutable_simple_predicate();
|
||||
simplePredicate->set_start("SCREEN_TURNED_OFF");
|
||||
simplePredicate->set_stop("SCREEN_TURNED_ON");
|
||||
simplePredicate->set_start(103);
|
||||
simplePredicate->set_stop(102); // "SCREEN_TURNED_ON"
|
||||
simplePredicate->set_count_nesting(false);
|
||||
|
||||
predicate = config.add_predicate();
|
||||
predicate->set_name("APP_IS_BACKGROUND");
|
||||
predicate->set_id(203); // "APP_IS_BACKGROUND"
|
||||
simplePredicate = predicate->mutable_simple_predicate();
|
||||
simplePredicate->set_start("APP_GOES_BACKGROUND");
|
||||
simplePredicate->set_stop("APP_GOES_FOREGROUND");
|
||||
simplePredicate->set_start(105);
|
||||
simplePredicate->set_stop(106);
|
||||
FieldMatcher* predicate_dimension1 = simplePredicate->mutable_dimensions();
|
||||
predicate_dimension1->set_field(APP_USAGE_TAG_ID);
|
||||
predicate_dimension1->add_child()->set_field(APP_USAGE_UID_KEY_ID);
|
||||
simplePredicate->set_count_nesting(false);
|
||||
|
||||
predicate = config.add_predicate();
|
||||
predicate->set_name("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
predicate->set_id(204); // "APP_IS_BACKGROUND_AND_SCREEN_ON"
|
||||
Predicate_Combination* combination_predicate = predicate->mutable_combination();
|
||||
combination_predicate->set_operation(LogicalOperation::AND);
|
||||
combination_predicate->add_predicate("APP_IS_BACKGROUND");
|
||||
combination_predicate->add_predicate("SCREEN_IS_ON");
|
||||
combination_predicate->add_predicate(203);
|
||||
combination_predicate->add_predicate(201);
|
||||
|
||||
predicate = config.add_predicate();
|
||||
predicate->set_name("WL_HELD_PER_APP_PER_NAME");
|
||||
predicate->set_id(205); // "WL_HELD_PER_APP_PER_NAME"
|
||||
simplePredicate = predicate->mutable_simple_predicate();
|
||||
simplePredicate->set_start("APP_GET_WL");
|
||||
simplePredicate->set_stop("APP_RELEASE_WL");
|
||||
simplePredicate->set_start(107);
|
||||
simplePredicate->set_stop(108);
|
||||
FieldMatcher* predicate_dimension = simplePredicate->mutable_dimensions();
|
||||
predicate_dimension1->set_field(WAKE_LOCK_TAG_ID);
|
||||
predicate_dimension->add_child()->set_field(WAKE_LOCK_UID_KEY_ID);
|
||||
@@ -508,10 +508,10 @@ StatsdConfig build_fake_config() {
|
||||
simplePredicate->set_count_nesting(true);
|
||||
|
||||
predicate = config.add_predicate();
|
||||
predicate->set_name("WL_HELD_PER_APP");
|
||||
predicate->set_id(206); // "WL_HELD_PER_APP"
|
||||
simplePredicate = predicate->mutable_simple_predicate();
|
||||
simplePredicate->set_start("APP_GET_WL");
|
||||
simplePredicate->set_stop("APP_RELEASE_WL");
|
||||
simplePredicate->set_start(107);
|
||||
simplePredicate->set_stop(108);
|
||||
simplePredicate->set_initial_value(SimplePredicate_InitialValue_FALSE);
|
||||
predicate_dimension = simplePredicate->mutable_dimensions();
|
||||
predicate_dimension->set_field(WAKE_LOCK_TAG_ID);
|
||||
|
||||
@@ -80,7 +80,7 @@ void StatsdStats::noteConfigReceived(const ConfigKey& key, int metricsCount, int
|
||||
|
||||
StatsdStatsReport_ConfigStats configStats;
|
||||
configStats.set_uid(key.GetUid());
|
||||
configStats.set_name(key.GetName());
|
||||
configStats.set_id(key.GetId());
|
||||
configStats.set_creation_time_sec(nowTimeSec);
|
||||
configStats.set_metric_count(metricsCount);
|
||||
configStats.set_condition_count(conditionsCount);
|
||||
@@ -196,34 +196,34 @@ void StatsdStats::setCurrentUidMapMemory(int bytes) {
|
||||
mUidMapStats.set_bytes_used(bytes);
|
||||
}
|
||||
|
||||
void StatsdStats::noteConditionDimensionSize(const ConfigKey& key, const string& name, int size) {
|
||||
void StatsdStats::noteConditionDimensionSize(const ConfigKey& key, const int64_t& id, int size) {
|
||||
lock_guard<std::mutex> lock(mLock);
|
||||
// if name doesn't exist before, it will create the key with count 0.
|
||||
auto& conditionSizeMap = mConditionStats[key];
|
||||
if (size > conditionSizeMap[name]) {
|
||||
conditionSizeMap[name] = size;
|
||||
if (size > conditionSizeMap[id]) {
|
||||
conditionSizeMap[id] = size;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsdStats::noteMetricDimensionSize(const ConfigKey& key, const string& name, int size) {
|
||||
void StatsdStats::noteMetricDimensionSize(const ConfigKey& key, const int64_t& id, int size) {
|
||||
lock_guard<std::mutex> lock(mLock);
|
||||
// if name doesn't exist before, it will create the key with count 0.
|
||||
auto& metricsDimensionMap = mMetricsStats[key];
|
||||
if (size > metricsDimensionMap[name]) {
|
||||
metricsDimensionMap[name] = size;
|
||||
if (size > metricsDimensionMap[id]) {
|
||||
metricsDimensionMap[id] = size;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsdStats::noteMatcherMatched(const ConfigKey& key, const string& name) {
|
||||
void StatsdStats::noteMatcherMatched(const ConfigKey& key, const int64_t& id) {
|
||||
lock_guard<std::mutex> lock(mLock);
|
||||
auto& matcherStats = mMatcherStats[key];
|
||||
matcherStats[name]++;
|
||||
matcherStats[id]++;
|
||||
}
|
||||
|
||||
void StatsdStats::noteAnomalyDeclared(const ConfigKey& key, const string& name) {
|
||||
void StatsdStats::noteAnomalyDeclared(const ConfigKey& key, const int64_t& id) {
|
||||
lock_guard<std::mutex> lock(mLock);
|
||||
auto& alertStats = mAlertStats[key];
|
||||
alertStats[name]++;
|
||||
alertStats[id]++;
|
||||
}
|
||||
|
||||
void StatsdStats::noteRegisteredAnomalyAlarmChanged() {
|
||||
@@ -279,9 +279,10 @@ void StatsdStats::addSubStatsToConfigLocked(const ConfigKey& key,
|
||||
const auto& matcherStats = mMatcherStats[key];
|
||||
for (const auto& stats : matcherStats) {
|
||||
auto output = configStats.add_matcher_stats();
|
||||
output->set_name(stats.first);
|
||||
output->set_id(stats.first);
|
||||
output->set_matched_times(stats.second);
|
||||
VLOG("matcher %s matched %d times", stats.first.c_str(), stats.second);
|
||||
VLOG("matcher %lld matched %d times",
|
||||
(long long)stats.first, stats.second);
|
||||
}
|
||||
}
|
||||
// Add condition stats
|
||||
@@ -289,9 +290,10 @@ void StatsdStats::addSubStatsToConfigLocked(const ConfigKey& key,
|
||||
const auto& conditionStats = mConditionStats[key];
|
||||
for (const auto& stats : conditionStats) {
|
||||
auto output = configStats.add_condition_stats();
|
||||
output->set_name(stats.first);
|
||||
output->set_id(stats.first);
|
||||
output->set_max_tuple_counts(stats.second);
|
||||
VLOG("condition %s max output tuple size %d", stats.first.c_str(), stats.second);
|
||||
VLOG("condition %lld max output tuple size %d",
|
||||
(long long)stats.first, stats.second);
|
||||
}
|
||||
}
|
||||
// Add metrics stats
|
||||
@@ -299,9 +301,10 @@ void StatsdStats::addSubStatsToConfigLocked(const ConfigKey& key,
|
||||
const auto& conditionStats = mMetricsStats[key];
|
||||
for (const auto& stats : conditionStats) {
|
||||
auto output = configStats.add_metric_stats();
|
||||
output->set_name(stats.first);
|
||||
output->set_id(stats.first);
|
||||
output->set_max_tuple_counts(stats.second);
|
||||
VLOG("metrics %s max output tuple size %d", stats.first.c_str(), stats.second);
|
||||
VLOG("metrics %lld max output tuple size %d",
|
||||
(long long)stats.first, stats.second);
|
||||
}
|
||||
}
|
||||
// Add anomaly detection alert stats
|
||||
@@ -309,9 +312,9 @@ void StatsdStats::addSubStatsToConfigLocked(const ConfigKey& key,
|
||||
const auto& alertStats = mAlertStats[key];
|
||||
for (const auto& stats : alertStats) {
|
||||
auto output = configStats.add_alert_stats();
|
||||
output->set_name(stats.first);
|
||||
output->set_id(stats.first);
|
||||
output->set_alerted_times(stats.second);
|
||||
VLOG("alert %s declared %d times", stats.first.c_str(), stats.second);
|
||||
VLOG("alert %lld declared %d times", (long long)stats.first, stats.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,9 +346,9 @@ void StatsdStats::dumpStats(std::vector<uint8_t>* output, bool reset) {
|
||||
// in production.
|
||||
if (DEBUG) {
|
||||
VLOG("*****ICEBOX*****");
|
||||
VLOG("Config {%d-%s}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
|
||||
VLOG("Config {%d-%lld}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
|
||||
"#matcher=%d, #alert=%d, #valid=%d",
|
||||
configStats.uid(), configStats.name().c_str(), configStats.creation_time_sec(),
|
||||
configStats.uid(), (long long)configStats.id(), configStats.creation_time_sec(),
|
||||
configStats.deletion_time_sec(), configStats.metric_count(),
|
||||
configStats.condition_count(), configStats.matcher_count(),
|
||||
configStats.alert_count(), configStats.is_valid());
|
||||
@@ -364,9 +367,9 @@ void StatsdStats::dumpStats(std::vector<uint8_t>* output, bool reset) {
|
||||
auto& configStats = pair.second;
|
||||
if (DEBUG) {
|
||||
VLOG("********Active Configs***********");
|
||||
VLOG("Config {%d-%s}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
|
||||
VLOG("Config {%d-%lld}: creation=%d, deletion=%d, #metric=%d, #condition=%d, "
|
||||
"#matcher=%d, #alert=%d, #valid=%d",
|
||||
configStats.uid(), configStats.name().c_str(), configStats.creation_time_sec(),
|
||||
configStats.uid(), (long long)configStats.id(), configStats.creation_time_sec(),
|
||||
configStats.deletion_time_sec(), configStats.metric_count(),
|
||||
configStats.condition_count(), configStats.matcher_count(),
|
||||
configStats.alert_count(), configStats.is_valid());
|
||||
|
||||
@@ -99,10 +99,10 @@ public:
|
||||
* count > kDimensionKeySizeSoftLimit.
|
||||
*
|
||||
* [key]: The config key that this condition belongs to.
|
||||
* [name]: The name of the condition.
|
||||
* [id]: The id of the condition.
|
||||
* [size]: The output tuple size.
|
||||
*/
|
||||
void noteConditionDimensionSize(const ConfigKey& key, const std::string& name, int size);
|
||||
void noteConditionDimensionSize(const ConfigKey& key, const int64_t& id, int size);
|
||||
|
||||
/**
|
||||
* Report the size of output tuple of a metric.
|
||||
@@ -111,26 +111,26 @@ public:
|
||||
* count > kDimensionKeySizeSoftLimit.
|
||||
*
|
||||
* [key]: The config key that this metric belongs to.
|
||||
* [name]: The name of the metric.
|
||||
* [id]: The id of the metric.
|
||||
* [size]: The output tuple size.
|
||||
*/
|
||||
void noteMetricDimensionSize(const ConfigKey& key, const std::string& name, int size);
|
||||
void noteMetricDimensionSize(const ConfigKey& key, const int64_t& id, int size);
|
||||
|
||||
/**
|
||||
* Report a matcher has been matched.
|
||||
*
|
||||
* [key]: The config key that this matcher belongs to.
|
||||
* [name]: The name of the matcher.
|
||||
* [id]: The id of the matcher.
|
||||
*/
|
||||
void noteMatcherMatched(const ConfigKey& key, const std::string& name);
|
||||
void noteMatcherMatched(const ConfigKey& key, const int64_t& id);
|
||||
|
||||
/**
|
||||
* Report that an anomaly detection alert has been declared.
|
||||
*
|
||||
* [key]: The config key that this alert belongs to.
|
||||
* [name]: The name of the alert.
|
||||
* [id]: The id of the alert.
|
||||
*/
|
||||
void noteAnomalyDeclared(const ConfigKey& key, const std::string& name);
|
||||
void noteAnomalyDeclared(const ConfigKey& key, const int64_t& id);
|
||||
|
||||
/**
|
||||
* Report an atom event has been logged.
|
||||
@@ -187,12 +187,12 @@ private:
|
||||
// Stores the number of output tuple of condition trackers when it's bigger than
|
||||
// kDimensionKeySizeSoftLimit. When you see the number is kDimensionKeySizeHardLimit +1,
|
||||
// it means some data has been dropped.
|
||||
std::map<const ConfigKey, std::map<const std::string, int>> mConditionStats;
|
||||
std::map<const ConfigKey, std::map<const int64_t, int>> mConditionStats;
|
||||
|
||||
// Stores the number of output tuple of metric producers when it's bigger than
|
||||
// kDimensionKeySizeSoftLimit. When you see the number is kDimensionKeySizeHardLimit +1,
|
||||
// it means some data has been dropped.
|
||||
std::map<const ConfigKey, std::map<const std::string, int>> mMetricsStats;
|
||||
std::map<const ConfigKey, std::map<const int64_t, int>> mMetricsStats;
|
||||
|
||||
// Stores the number of times a pushed atom is logged.
|
||||
// The size of the vector is the largest pushed atom id in atoms.proto + 1. Atoms
|
||||
@@ -206,10 +206,10 @@ private:
|
||||
|
||||
// Stores the number of times an anomaly detection alert has been declared
|
||||
// (per config, per alert name).
|
||||
std::map<const ConfigKey, std::map<const std::string, int>> mAlertStats;
|
||||
std::map<const ConfigKey, std::map<const int64_t, int>> mAlertStats;
|
||||
|
||||
// Stores how many times a matcher have been matched.
|
||||
std::map<const ConfigKey, std::map<const std::string, int>> mMatcherStats;
|
||||
std::map<const ConfigKey, std::map<const int64_t, int>> mMatcherStats;
|
||||
|
||||
void noteConfigRemovedInternalLocked(const ConfigKey& key);
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ using std::unique_ptr;
|
||||
using std::unordered_map;
|
||||
using std::vector;
|
||||
|
||||
CombinationLogMatchingTracker::CombinationLogMatchingTracker(const string& name, const int index)
|
||||
: LogMatchingTracker(name, index) {
|
||||
CombinationLogMatchingTracker::CombinationLogMatchingTracker(const int64_t& id, const int index)
|
||||
: LogMatchingTracker(id, index) {
|
||||
}
|
||||
|
||||
CombinationLogMatchingTracker::~CombinationLogMatchingTracker() {
|
||||
@@ -38,7 +38,7 @@ CombinationLogMatchingTracker::~CombinationLogMatchingTracker() {
|
||||
|
||||
bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
|
||||
const vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
const unordered_map<string, int>& matcherMap,
|
||||
const unordered_map<int64_t, int>& matcherMap,
|
||||
vector<bool>& stack) {
|
||||
if (mInitialized) {
|
||||
return true;
|
||||
@@ -60,10 +60,10 @@ bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatche
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const string& child : matcher.matcher()) {
|
||||
for (const auto& child : matcher.matcher()) {
|
||||
auto pair = matcherMap.find(child);
|
||||
if (pair == matcherMap.end()) {
|
||||
ALOGW("Matcher %s not found in the config", child.c_str());
|
||||
ALOGW("Matcher %lld not found in the config", (long long)child);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ bool CombinationLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatche
|
||||
}
|
||||
|
||||
if (!allTrackers[childIndex]->init(allLogMatchers, allTrackers, matcherMap, stack)) {
|
||||
ALOGW("child matcher init failed %s", child.c_str());
|
||||
ALOGW("child matcher init failed %lld", (long long)child);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace statsd {
|
||||
// Represents a AtomMatcher_Combination in the StatsdConfig.
|
||||
class CombinationLogMatchingTracker : public virtual LogMatchingTracker {
|
||||
public:
|
||||
CombinationLogMatchingTracker(const std::string& name, const int index);
|
||||
CombinationLogMatchingTracker(const int64_t& id, const int index);
|
||||
|
||||
bool init(const std::vector<AtomMatcher>& allLogMatchers,
|
||||
const std::vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
const std::unordered_map<std::string, int>& matcherMap,
|
||||
const std::unordered_map<int64_t, int>& matcherMap,
|
||||
std::vector<bool>& stack);
|
||||
|
||||
~CombinationLogMatchingTracker();
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace statsd {
|
||||
|
||||
class LogMatchingTracker : public virtual RefBase {
|
||||
public:
|
||||
LogMatchingTracker(const std::string& name, const int index)
|
||||
: mName(name), mIndex(index), mInitialized(false){};
|
||||
LogMatchingTracker(const int64_t& id, const int index)
|
||||
: mId(id), mIndex(index), mInitialized(false){};
|
||||
|
||||
virtual ~LogMatchingTracker(){};
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
// circle dependency.
|
||||
virtual bool init(const std::vector<AtomMatcher>& allLogMatchers,
|
||||
const std::vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
const std::unordered_map<std::string, int>& matcherMap,
|
||||
const std::unordered_map<int64_t, int>& matcherMap,
|
||||
std::vector<bool>& stack) = 0;
|
||||
|
||||
// Called when a log event comes.
|
||||
@@ -69,13 +69,13 @@ public:
|
||||
return mAtomIds;
|
||||
}
|
||||
|
||||
const std::string& getName() const {
|
||||
return mName;
|
||||
const int64_t& getId() const {
|
||||
return mId;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Name of this matching. We don't really need the name, but it makes log message easy to debug.
|
||||
const std::string mName;
|
||||
const int64_t mId;
|
||||
|
||||
// Index of this LogMatchingTracker in MetricsManager's container.
|
||||
const int mIndex;
|
||||
|
||||
@@ -29,10 +29,10 @@ using std::unordered_map;
|
||||
using std::vector;
|
||||
|
||||
|
||||
SimpleLogMatchingTracker::SimpleLogMatchingTracker(const string& name, const int index,
|
||||
SimpleLogMatchingTracker::SimpleLogMatchingTracker(const int64_t& id, const int index,
|
||||
const SimpleAtomMatcher& matcher,
|
||||
const UidMap& uidMap)
|
||||
: LogMatchingTracker(name, index), mMatcher(matcher), mUidMap(uidMap) {
|
||||
: LogMatchingTracker(id, index), mMatcher(matcher), mUidMap(uidMap) {
|
||||
if (!matcher.has_atom_id()) {
|
||||
mInitialized = false;
|
||||
} else {
|
||||
@@ -46,7 +46,7 @@ SimpleLogMatchingTracker::~SimpleLogMatchingTracker() {
|
||||
|
||||
bool SimpleLogMatchingTracker::init(const vector<AtomMatcher>& allLogMatchers,
|
||||
const vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
const unordered_map<string, int>& matcherMap,
|
||||
const unordered_map<int64_t, int>& matcherMap,
|
||||
vector<bool>& stack) {
|
||||
// no need to do anything.
|
||||
return mInitialized;
|
||||
@@ -56,7 +56,7 @@ void SimpleLogMatchingTracker::onLogEvent(const LogEvent& event,
|
||||
const vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
vector<MatchingState>& matcherResults) {
|
||||
if (matcherResults[mIndex] != MatchingState::kNotComputed) {
|
||||
VLOG("Matcher %s already evaluated ", mName.c_str());
|
||||
VLOG("Matcher %lld already evaluated ", (long long)mId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ void SimpleLogMatchingTracker::onLogEvent(const LogEvent& event,
|
||||
|
||||
bool matched = matchesSimple(mUidMap, mMatcher, event);
|
||||
matcherResults[mIndex] = matched ? MatchingState::kMatched : MatchingState::kNotMatched;
|
||||
VLOG("Stats SimpleLogMatcher %s matched? %d", mName.c_str(), matched);
|
||||
VLOG("Stats SimpleLogMatcher %lld matched? %d", (long long)mId, matched);
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace statsd {
|
||||
|
||||
class SimpleLogMatchingTracker : public virtual LogMatchingTracker {
|
||||
public:
|
||||
SimpleLogMatchingTracker(const std::string& name, const int index,
|
||||
SimpleLogMatchingTracker(const int64_t& id, const int index,
|
||||
const SimpleAtomMatcher& matcher,
|
||||
const UidMap& uidMap);
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
bool init(const std::vector<AtomMatcher>& allLogMatchers,
|
||||
const std::vector<sp<LogMatchingTracker>>& allTrackers,
|
||||
const std::unordered_map<std::string, int>& matcherMap,
|
||||
const std::unordered_map<int64_t, int>& matcherMap,
|
||||
std::vector<bool>& stack) override;
|
||||
|
||||
void onLogEvent(const LogEvent& event,
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// for StatsLogReport
|
||||
const int FIELD_ID_NAME = 1;
|
||||
const int FIELD_ID_ID = 1;
|
||||
const int FIELD_ID_START_REPORT_NANOS = 2;
|
||||
const int FIELD_ID_END_REPORT_NANOS = 3;
|
||||
const int FIELD_ID_COUNT_METRICS = 5;
|
||||
@@ -61,7 +61,7 @@ CountMetricProducer::CountMetricProducer(const ConfigKey& key, const CountMetric
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard,
|
||||
const uint64_t startTimeNs)
|
||||
: MetricProducer(metric.name(), key, startTimeNs, conditionIndex, wizard) {
|
||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard) {
|
||||
// TODO: evaluate initial conditions. and set mConditionMet.
|
||||
if (metric.has_bucket() && metric.bucket().has_bucket_size_millis()) {
|
||||
mBucketSizeNs = metric.bucket().bucket_size_millis() * 1000 * 1000;
|
||||
@@ -78,7 +78,7 @@ CountMetricProducer::CountMetricProducer(const ConfigKey& key, const CountMetric
|
||||
mConditionSliced = true;
|
||||
}
|
||||
|
||||
VLOG("metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
|
||||
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ CountMetricProducer::~CountMetricProducer() {
|
||||
}
|
||||
|
||||
void CountMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
|
||||
VLOG("Metric %s onSlicedConditionMayChange", mName.c_str());
|
||||
VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
|
||||
}
|
||||
|
||||
void CountMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) {
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
report->set_metric_name(mName);
|
||||
report->set_metric_id(mMetricId);
|
||||
report->set_start_report_nanos(mStartTimeNs);
|
||||
|
||||
auto count_metrics = report->mutable_count_metrics();
|
||||
@@ -112,11 +112,11 @@ void CountMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
ProtoOutputStream* protoOutput) {
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
|
||||
protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mName);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
|
||||
long long protoToken = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_ID_COUNT_METRICS);
|
||||
|
||||
VLOG("metric %s dump report now...", mName.c_str());
|
||||
VLOG("metric %lld dump report now...",(long long)mMetricId);
|
||||
|
||||
for (const auto& counter : mPastBuckets) {
|
||||
const HashableDimensionKey& hashableKey = counter.first;
|
||||
@@ -158,7 +158,7 @@ void CountMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
|
||||
void CountMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
const uint64_t eventTime) {
|
||||
VLOG("Metric %s onConditionChanged", mName.c_str());
|
||||
VLOG("Metric %lld onConditionChanged", (long long)mMetricId);
|
||||
mCondition = conditionMet;
|
||||
}
|
||||
|
||||
@@ -170,11 +170,11 @@ bool CountMetricProducer::hitGuardRailLocked(const HashableDimensionKey& newKey)
|
||||
// 1. Report the tuple count if the tuple count > soft limit
|
||||
if (mCurrentSlicedCounter->size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mCurrentSlicedCounter->size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName, newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("CountMetric %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("CountMetric %lld dropping data for dimension key %s",
|
||||
(long long)mMetricId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void CountMetricProducer::onMatchedLogEventInternalLocked(
|
||||
mCurrentSlicedCounter->find(eventKey)->second);
|
||||
}
|
||||
|
||||
VLOG("metric %s %s->%lld", mName.c_str(), eventKey.c_str(),
|
||||
VLOG("metric %lld %s->%lld", (long long)mMetricId, eventKey.c_str(),
|
||||
(long long)(*mCurrentSlicedCounter)[eventKey]);
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ void CountMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
|
||||
info.mCount = counter.second;
|
||||
auto& bucketList = mPastBuckets[counter.first];
|
||||
bucketList.push_back(info);
|
||||
VLOG("metric %s, dump key value: %s -> %lld", mName.c_str(), counter.first.c_str(),
|
||||
(long long)counter.second);
|
||||
VLOG("metric %lld, dump key value: %s -> %lld",
|
||||
(long long)mMetricId, counter.first.c_str(), (long long)counter.second);
|
||||
}
|
||||
|
||||
for (auto& tracker : mAnomalyTrackers) {
|
||||
@@ -247,7 +247,7 @@ void CountMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
|
||||
uint64_t numBucketsForward = (eventTimeNs - mCurrentBucketStartTimeNs) / mBucketSizeNs;
|
||||
mCurrentBucketStartTimeNs = mCurrentBucketStartTimeNs + numBucketsForward * mBucketSizeNs;
|
||||
mCurrentBucketNum += numBucketsForward;
|
||||
VLOG("metric %s: new bucket start time: %lld", mName.c_str(),
|
||||
VLOG("metric %lld: new bucket start time: %lld", (long long)mMetricId,
|
||||
(long long)mCurrentBucketStartTimeNs);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// for StatsLogReport
|
||||
const int FIELD_ID_NAME = 1;
|
||||
const int FIELD_ID_ID = 1;
|
||||
const int FIELD_ID_START_REPORT_NANOS = 2;
|
||||
const int FIELD_ID_END_REPORT_NANOS = 3;
|
||||
const int FIELD_ID_DURATION_METRICS = 6;
|
||||
@@ -63,7 +63,7 @@ DurationMetricProducer::DurationMetricProducer(const ConfigKey& key, const Durat
|
||||
const sp<ConditionWizard>& wizard,
|
||||
const FieldMatcher& internalDimensions,
|
||||
const uint64_t startTimeNs)
|
||||
: MetricProducer(metric.name(), key, startTimeNs, conditionIndex, wizard),
|
||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard),
|
||||
mAggregationType(metric.aggregation_type()),
|
||||
mStartIndex(startIndex),
|
||||
mStopIndex(stopIndex),
|
||||
@@ -88,7 +88,7 @@ DurationMetricProducer::DurationMetricProducer(const ConfigKey& key, const Durat
|
||||
mConditionSliced = true;
|
||||
}
|
||||
|
||||
VLOG("metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
|
||||
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
|
||||
@@ -116,17 +116,17 @@ unique_ptr<DurationTracker> DurationMetricProducer::createDurationTracker(
|
||||
switch (mAggregationType) {
|
||||
case DurationMetric_AggregationType_SUM:
|
||||
return make_unique<OringDurationTracker>(
|
||||
mConfigKey, mName, eventKey, mWizard, mConditionTrackerIndex, mNested,
|
||||
mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
|
||||
mCurrentBucketStartTimeNs, mBucketSizeNs, mAnomalyTrackers);
|
||||
case DurationMetric_AggregationType_MAX_SPARSE:
|
||||
return make_unique<MaxDurationTracker>(
|
||||
mConfigKey, mName, eventKey, mWizard, mConditionTrackerIndex, mNested,
|
||||
mConfigKey, mMetricId, eventKey, mWizard, mConditionTrackerIndex, mNested,
|
||||
mCurrentBucketStartTimeNs, mBucketSizeNs, mAnomalyTrackers);
|
||||
}
|
||||
}
|
||||
|
||||
void DurationMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
|
||||
VLOG("Metric %s onSlicedConditionMayChange", mName.c_str());
|
||||
VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
|
||||
flushIfNeededLocked(eventTime);
|
||||
// Now for each of the on-going event, check if the condition has changed for them.
|
||||
for (auto& pair : mCurrentSlicedDuration) {
|
||||
@@ -136,7 +136,7 @@ void DurationMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eve
|
||||
|
||||
void DurationMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
const uint64_t eventTime) {
|
||||
VLOG("Metric %s onConditionChanged", mName.c_str());
|
||||
VLOG("Metric %lld onConditionChanged", (long long)mMetricId);
|
||||
mCondition = conditionMet;
|
||||
flushIfNeededLocked(eventTime);
|
||||
// TODO: need to populate the condition change time from the event which triggers the condition
|
||||
@@ -148,7 +148,7 @@ void DurationMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
|
||||
void DurationMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) {
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
report->set_metric_name(mName);
|
||||
report->set_metric_id(mMetricId);
|
||||
report->set_start_report_nanos(mStartTimeNs);
|
||||
|
||||
auto duration_metrics = report->mutable_duration_metrics();
|
||||
@@ -168,11 +168,11 @@ void DurationMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
ProtoOutputStream* protoOutput) {
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
|
||||
protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mName);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
|
||||
long long protoToken = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_ID_DURATION_METRICS);
|
||||
|
||||
VLOG("metric %s dump report now...", mName.c_str());
|
||||
VLOG("metric %lld dump report now...", (long long)mMetricId);
|
||||
|
||||
for (const auto& pair : mPastBuckets) {
|
||||
const HashableDimensionKey& hashableKey = pair.first;
|
||||
@@ -237,11 +237,11 @@ bool DurationMetricProducer::hitGuardRailLocked(const HashableDimensionKey& newK
|
||||
// 1. Report the tuple count if the tuple count > soft limit
|
||||
if (mCurrentSlicedDuration.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mCurrentSlicedDuration.size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName, newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("DurationMetric %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("DurationMetric %lld dropping data for dimension key %s",
|
||||
(long long)mMetricId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// for StatsLogReport
|
||||
const int FIELD_ID_NAME = 1;
|
||||
const int FIELD_ID_ID = 1;
|
||||
const int FIELD_ID_START_REPORT_NANOS = 2;
|
||||
const int FIELD_ID_END_REPORT_NANOS = 3;
|
||||
const int FIELD_ID_EVENT_METRICS = 4;
|
||||
@@ -55,7 +55,7 @@ EventMetricProducer::EventMetricProducer(const ConfigKey& key, const EventMetric
|
||||
const int conditionIndex,
|
||||
const sp<ConditionWizard>& wizard,
|
||||
const uint64_t startTimeNs)
|
||||
: MetricProducer(metric.name(), key, startTimeNs, conditionIndex, wizard) {
|
||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard) {
|
||||
if (metric.links().size() > 0) {
|
||||
mConditionLinks.insert(mConditionLinks.begin(), metric.links().begin(),
|
||||
metric.links().end());
|
||||
@@ -64,7 +64,7 @@ EventMetricProducer::EventMetricProducer(const ConfigKey& key, const EventMetric
|
||||
|
||||
startNewProtoOutputStreamLocked();
|
||||
|
||||
VLOG("metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
|
||||
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
|
||||
@@ -102,12 +102,13 @@ void EventMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLog
|
||||
|
||||
void EventMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
ProtoOutputStream* protoOutput) {
|
||||
protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mName);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_END_REPORT_NANOS, (long long)dumpTimeNs);
|
||||
|
||||
size_t bufferSize = mProto->size();
|
||||
VLOG("metric %s dump report now... proto size: %zu ", mName.c_str(), bufferSize);
|
||||
VLOG("metric %lld dump report now... proto size: %zu ",
|
||||
(long long)mMetricId, bufferSize);
|
||||
std::unique_ptr<std::vector<uint8_t>> buffer = serializeProtoLocked(*mProto);
|
||||
|
||||
protoOutput->write(FIELD_TYPE_MESSAGE | FIELD_ID_EVENT_METRICS,
|
||||
@@ -119,7 +120,7 @@ void EventMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
|
||||
void EventMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
const uint64_t eventTime) {
|
||||
VLOG("Metric %s onConditionChanged", mName.c_str());
|
||||
VLOG("Metric %lld onConditionChanged", (long long)mMetricId);
|
||||
mCondition = conditionMet;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// for StatsLogReport
|
||||
const int FIELD_ID_NAME = 1;
|
||||
const int FIELD_ID_ID = 1;
|
||||
const int FIELD_ID_START_REPORT_NANOS = 2;
|
||||
const int FIELD_ID_END_REPORT_NANOS = 3;
|
||||
const int FIELD_ID_GAUGE_METRICS = 8;
|
||||
@@ -63,7 +63,7 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
|
||||
const sp<ConditionWizard>& wizard, const int atomTagId,
|
||||
const int pullTagId, const uint64_t startTimeNs,
|
||||
shared_ptr<StatsPullerManager> statsPullerManager)
|
||||
: MetricProducer(metric.name(), key, startTimeNs, conditionIndex, wizard),
|
||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard),
|
||||
mStatsPullerManager(statsPullerManager),
|
||||
mPullTagId(pullTagId),
|
||||
mAtomTagId(atomTagId) {
|
||||
@@ -92,7 +92,7 @@ GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric
|
||||
metric.bucket().bucket_size_millis());
|
||||
}
|
||||
|
||||
VLOG("metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
|
||||
VLOG("metric %lld created. bucket size %lld start_time: %lld", (long long)metric.id(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
|
||||
@@ -118,11 +118,11 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLog
|
||||
|
||||
void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
ProtoOutputStream* protoOutput) {
|
||||
VLOG("gauge metric %s dump report now...", mName.c_str());
|
||||
VLOG("gauge metric %lld report now...", (long long)mMetricId);
|
||||
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
|
||||
protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mName);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
|
||||
long long protoToken = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_ID_GAUGE_METRICS);
|
||||
|
||||
@@ -166,7 +166,7 @@ void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
|
||||
void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
const uint64_t eventTime) {
|
||||
VLOG("Metric %s onConditionChanged", mName.c_str());
|
||||
VLOG("Metric %lld onConditionChanged", (long long)mMetricId);
|
||||
flushIfNeededLocked(eventTime);
|
||||
mCondition = conditionMet;
|
||||
|
||||
@@ -194,7 +194,7 @@ void GaugeMetricProducer::onConditionChangedLocked(const bool conditionMet,
|
||||
}
|
||||
|
||||
void GaugeMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
|
||||
VLOG("Metric %s onSlicedConditionMayChange", mName.c_str());
|
||||
VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
|
||||
}
|
||||
|
||||
std::shared_ptr<FieldValueMap> GaugeMetricProducer::getGaugeFields(const LogEvent& event) {
|
||||
@@ -223,11 +223,11 @@ bool GaugeMetricProducer::hitGuardRailLocked(const HashableDimensionKey& newKey)
|
||||
// 1. Report the tuple count if the tuple count > soft limit
|
||||
if (mCurrentSlicedBucket->size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mCurrentSlicedBucket->size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName, newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("GaugeMetric %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("GaugeMetric %lld dropping data for dimension key %s",
|
||||
(long long)mMetricId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,8 @@ void GaugeMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
|
||||
info.mGaugeFields = slice.second;
|
||||
auto& bucketList = mPastBuckets[slice.first];
|
||||
bucketList.push_back(info);
|
||||
VLOG("gauge metric %s, dump key value: %s", mName.c_str(), slice.first.c_str());
|
||||
VLOG("gauge metric %lld, dump key value: %s",
|
||||
(long long)mMetricId, slice.first.c_str());
|
||||
}
|
||||
|
||||
// Reset counters
|
||||
@@ -331,7 +332,7 @@ void GaugeMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
|
||||
int64_t numBucketsForward = (eventTimeNs - mCurrentBucketStartTimeNs) / mBucketSizeNs;
|
||||
mCurrentBucketStartTimeNs = mCurrentBucketStartTimeNs + numBucketsForward * mBucketSizeNs;
|
||||
mCurrentBucketNum += numBucketsForward;
|
||||
VLOG("metric %s: new bucket start time: %lld", mName.c_str(),
|
||||
VLOG("metric %lld: new bucket start time: %lld", (long long)mMetricId,
|
||||
(long long)mCurrentBucketStartTimeNs);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const Lo
|
||||
}
|
||||
|
||||
bool condition;
|
||||
map<string, std::vector<HashableDimensionKey>> conditionKeys;
|
||||
ConditionKey conditionKey;
|
||||
if (mConditionSliced) {
|
||||
for (const auto& link : mConditionLinks) {
|
||||
conditionKeys.insert(std::make_pair(link.condition(),
|
||||
getDimensionKeysForCondition(event, link)));
|
||||
conditionKey.insert(std::make_pair(link.condition(),
|
||||
getDimensionKeysForCondition(event, link)));
|
||||
}
|
||||
if (mWizard->query(mConditionTrackerIndex, conditionKeys) != ConditionState::kTrue) {
|
||||
if (mWizard->query(mConditionTrackerIndex, conditionKey) != ConditionState::kTrue) {
|
||||
condition = false;
|
||||
} else {
|
||||
condition = true;
|
||||
@@ -48,11 +48,11 @@ void MetricProducer::onMatchedLogEventLocked(const size_t matcherIndex, const Lo
|
||||
vector<DimensionsValue> dimensionValues = getDimensionKeys(event, mDimensions);
|
||||
for (const DimensionsValue& dimensionValue : dimensionValues) {
|
||||
onMatchedLogEventInternalLocked(
|
||||
matcherIndex, HashableDimensionKey(dimensionValue), conditionKeys, condition, event);
|
||||
matcherIndex, HashableDimensionKey(dimensionValue), conditionKey, condition, event);
|
||||
}
|
||||
} else {
|
||||
onMatchedLogEventInternalLocked(
|
||||
matcherIndex, DEFAULT_DIMENSION_KEY, conditionKeys, condition, event);
|
||||
matcherIndex, DEFAULT_DIMENSION_KEY, conditionKey, condition, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace statsd {
|
||||
// be a no-op.
|
||||
class MetricProducer : public virtual PackageInfoListener {
|
||||
public:
|
||||
MetricProducer(const std::string& name, const ConfigKey& key, const int64_t startTimeNs,
|
||||
MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t startTimeNs,
|
||||
const int conditionIndex, const sp<ConditionWizard>& wizard)
|
||||
: mName(name),
|
||||
: mMetricId(metricId),
|
||||
mConfigKey(key),
|
||||
mStartTimeNs(startTimeNs),
|
||||
mCurrentBucketStartTimeNs(startTimeNs),
|
||||
@@ -117,8 +117,8 @@ public:
|
||||
return mBucketSizeNs;
|
||||
}
|
||||
|
||||
inline const string& getName() {
|
||||
return mName;
|
||||
inline const int64_t& getMetricId() {
|
||||
return mMetricId;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -129,7 +129,7 @@ protected:
|
||||
virtual void onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) = 0;
|
||||
virtual size_t byteSizeLocked() const = 0;
|
||||
|
||||
const std::string mName;
|
||||
const int64_t mMetricId;
|
||||
|
||||
const ConfigKey mConfigKey;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
|
||||
mConfigValid =
|
||||
initStatsdConfig(key, config, *uidMap, timeBaseSec, mTagIds, mAllAtomMatchers, mAllConditionTrackers,
|
||||
mAllMetricProducers, mAllAnomalyTrackers, mConditionToMetricMap,
|
||||
mTrackerToMetricMap, mTrackerToConditionMap);
|
||||
mTrackerToMetricMap, mTrackerToConditionMap, mNoReportMetricIds);
|
||||
|
||||
if (!config.has_log_source()) {
|
||||
// TODO(b/70794411): uncomment the following line and remove the hard coded log source
|
||||
@@ -143,8 +143,10 @@ void MetricsManager::onUidMapReceived() {
|
||||
}
|
||||
|
||||
void MetricsManager::onDumpReport(const uint64_t& dumpTimeStampNs, ConfigMetricsReport* report) {
|
||||
for (auto& producer : mAllMetricProducers) {
|
||||
producer->onDumpReport(dumpTimeStampNs, report->add_metrics());
|
||||
for (const auto& producer : mAllMetricProducers) {
|
||||
if (mNoReportMetricIds.find(producer->getMetricId()) == mNoReportMetricIds.end()) {
|
||||
producer->onDumpReport(dumpTimeStampNs, report->add_metrics());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,11 +154,13 @@ void MetricsManager::onDumpReport(ProtoOutputStream* protoOutput) {
|
||||
VLOG("=========================Metric Reports Start==========================");
|
||||
uint64_t dumpTimeStampNs = time(nullptr) * NS_PER_SEC;
|
||||
// one StatsLogReport per MetricProduer
|
||||
for (auto& metric : mAllMetricProducers) {
|
||||
long long token =
|
||||
protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS);
|
||||
metric->onDumpReport(dumpTimeStampNs, protoOutput);
|
||||
protoOutput->end(token);
|
||||
for (const auto& producer : mAllMetricProducers) {
|
||||
if (mNoReportMetricIds.find(producer->getMetricId()) == mNoReportMetricIds.end()) {
|
||||
long long token =
|
||||
protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS);
|
||||
producer->onDumpReport(dumpTimeStampNs, protoOutput);
|
||||
protoOutput->end(token);
|
||||
}
|
||||
}
|
||||
VLOG("=========================Metric Reports End==========================");
|
||||
}
|
||||
@@ -240,7 +244,7 @@ void MetricsManager::onLogEvent(const LogEvent& event) {
|
||||
for (size_t i = 0; i < mAllAtomMatchers.size(); i++) {
|
||||
if (matcherCache[i] == MatchingState::kMatched) {
|
||||
StatsdStats::getInstance().noteMatcherMatched(mConfigKey,
|
||||
mAllAtomMatchers[i]->getName());
|
||||
mAllAtomMatchers[i]->getId());
|
||||
auto pair = mTrackerToMetricMap.find(i);
|
||||
if (pair != mTrackerToMetricMap.end()) {
|
||||
auto& metricList = pair->second;
|
||||
|
||||
@@ -131,6 +131,9 @@ private:
|
||||
|
||||
void initLogSourceWhiteList();
|
||||
|
||||
// The metrics that don't need to be uploaded or even reported.
|
||||
std::set<int64_t> mNoReportMetricIds;
|
||||
|
||||
FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensions);
|
||||
FRIEND_TEST(MetricConditionLinkE2eTest, TestMultiplePredicatesAndLinks);
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// for StatsLogReport
|
||||
const int FIELD_ID_NAME = 1;
|
||||
const int FIELD_ID_ID = 1;
|
||||
const int FIELD_ID_START_REPORT_NANOS = 2;
|
||||
const int FIELD_ID_END_REPORT_NANOS = 3;
|
||||
const int FIELD_ID_VALUE_METRICS = 7;
|
||||
@@ -68,7 +68,7 @@ ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric
|
||||
const sp<ConditionWizard>& wizard, const int pullTagId,
|
||||
const uint64_t startTimeNs,
|
||||
shared_ptr<StatsPullerManager> statsPullerManager)
|
||||
: MetricProducer(metric.name(), key, startTimeNs, conditionIndex, wizard),
|
||||
: MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard),
|
||||
mValueField(metric.value_field()),
|
||||
mStatsPullerManager(statsPullerManager),
|
||||
mPullTagId(pullTagId) {
|
||||
@@ -92,8 +92,8 @@ ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric
|
||||
mStatsPullerManager->RegisterReceiver(mPullTagId, this,
|
||||
metric.bucket().bucket_size_millis());
|
||||
}
|
||||
VLOG("value metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
|
||||
(long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
VLOG("value metric %lld created. bucket size %lld start_time: %lld",
|
||||
(long long)metric.id(), (long long)mBucketSizeNs, (long long)mStartTimeNs);
|
||||
}
|
||||
|
||||
// for testing
|
||||
@@ -113,12 +113,12 @@ ValueMetricProducer::~ValueMetricProducer() {
|
||||
}
|
||||
|
||||
void ValueMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
|
||||
VLOG("Metric %s onSlicedConditionMayChange", mName.c_str());
|
||||
VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
|
||||
}
|
||||
|
||||
void ValueMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) {
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
report->set_metric_name(mName);
|
||||
report->set_metric_id(mMetricId);
|
||||
report->set_start_report_nanos(mStartTimeNs);
|
||||
auto value_metrics = report->mutable_value_metrics();
|
||||
for (const auto& pair : mPastBuckets) {
|
||||
@@ -135,9 +135,9 @@ void ValueMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs, StatsLog
|
||||
|
||||
void ValueMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
ProtoOutputStream* protoOutput) {
|
||||
VLOG("metric %s dump report now...", mName.c_str());
|
||||
VLOG("metric %lld dump report now...", (long long)mMetricId);
|
||||
flushIfNeededLocked(dumpTimeNs);
|
||||
protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mName);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ID, (long long)mMetricId);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
|
||||
long long protoToken = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_ID_VALUE_METRICS);
|
||||
|
||||
@@ -171,7 +171,7 @@ void ValueMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
|
||||
protoOutput->end(protoToken);
|
||||
protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_END_REPORT_NANOS, (long long)dumpTimeNs);
|
||||
|
||||
VLOG("metric %s dump report now...", mName.c_str());
|
||||
VLOG("metric %lld dump report now...", (long long)mMetricId);
|
||||
mPastBuckets.clear();
|
||||
mStartTimeNs = mCurrentBucketStartTimeNs;
|
||||
// TODO: Clear mDimensionKeyMap once the report is dumped.
|
||||
@@ -242,11 +242,11 @@ bool ValueMetricProducer::hitGuardRailLocked(const HashableDimensionKey& newKey)
|
||||
}
|
||||
if (mCurrentSlicedBucket.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mCurrentSlicedBucket.size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName, newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("ValueMetric %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("ValueMetric %lld dropping data for dimension key %s",
|
||||
(long long)mMetricId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ void ValueMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
|
||||
if (numBucketsForward > 1) {
|
||||
VLOG("Skipping forward %lld buckets", (long long)numBucketsForward);
|
||||
}
|
||||
VLOG("metric %s: new bucket start time: %lld", mName.c_str(),
|
||||
VLOG("metric %lld: new bucket start time: %lld", (long long)mMetricId,
|
||||
(long long)mCurrentBucketStartTimeNs);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,12 +60,12 @@ struct DurationBucket {
|
||||
|
||||
class DurationTracker {
|
||||
public:
|
||||
DurationTracker(const ConfigKey& key, const string& name, const HashableDimensionKey& eventKey,
|
||||
DurationTracker(const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
|
||||
sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
|
||||
uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
|
||||
const std::vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
|
||||
: mConfigKey(key),
|
||||
mName(name),
|
||||
mTrackerId(id),
|
||||
mEventKey(eventKey),
|
||||
mWizard(wizard),
|
||||
mConditionTrackerIndex(conditionIndex),
|
||||
@@ -145,7 +145,7 @@ protected:
|
||||
// A reference to the DurationMetricProducer's config key.
|
||||
const ConfigKey& mConfigKey;
|
||||
|
||||
const std::string mName;
|
||||
const int64_t mTrackerId;
|
||||
|
||||
HashableDimensionKey mEventKey;
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
MaxDurationTracker::MaxDurationTracker(const ConfigKey& key, const string& name,
|
||||
MaxDurationTracker::MaxDurationTracker(const ConfigKey& key, const int64_t& id,
|
||||
const HashableDimensionKey& eventKey,
|
||||
sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
|
||||
uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
|
||||
const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
|
||||
: DurationTracker(key, name, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
|
||||
: DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
|
||||
bucketSizeNs, anomalyTrackers) {
|
||||
}
|
||||
|
||||
@@ -42,12 +42,13 @@ bool MaxDurationTracker::hitGuardRail(const HashableDimensionKey& newKey) {
|
||||
// 1. Report the tuple count if the tuple count > soft limit
|
||||
if (mInfos.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mInfos.size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName + mEventKey.toString(),
|
||||
newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(
|
||||
mConfigKey, hashDimensionsValue(mTrackerId, mEventKey.getDimensionsValue()),
|
||||
newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("MaxDurTracker %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("MaxDurTracker %lld dropping data for dimension key %s",
|
||||
(long long)mTrackerId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace statsd {
|
||||
// they stop or bucket expires.
|
||||
class MaxDurationTracker : public DurationTracker {
|
||||
public:
|
||||
MaxDurationTracker(const ConfigKey& key, const string& name,
|
||||
MaxDurationTracker(const ConfigKey& key, const int64_t& id,
|
||||
const HashableDimensionKey& eventKey, sp<ConditionWizard> wizard,
|
||||
int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
|
||||
uint64_t bucketSizeNs,
|
||||
|
||||
@@ -25,11 +25,11 @@ namespace statsd {
|
||||
using std::pair;
|
||||
|
||||
OringDurationTracker::OringDurationTracker(
|
||||
const ConfigKey& key, const string& name, const HashableDimensionKey& eventKey,
|
||||
const ConfigKey& key, const int64_t& id, const HashableDimensionKey& eventKey,
|
||||
sp<ConditionWizard> wizard, int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
|
||||
uint64_t bucketSizeNs, const vector<sp<DurationAnomalyTracker>>& anomalyTrackers)
|
||||
|
||||
: DurationTracker(key, name, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
|
||||
: DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
|
||||
bucketSizeNs, anomalyTrackers),
|
||||
mStarted(),
|
||||
mPaused() {
|
||||
@@ -44,12 +44,13 @@ bool OringDurationTracker::hitGuardRail(const HashableDimensionKey& newKey) {
|
||||
}
|
||||
if (mConditionKeyMap.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
|
||||
size_t newTupleCount = mConditionKeyMap.size() + 1;
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mName + mEventKey.toString(),
|
||||
newTupleCount);
|
||||
StatsdStats::getInstance().noteMetricDimensionSize(
|
||||
mConfigKey, hashDimensionsValue(mTrackerId, mEventKey.getDimensionsValue()),
|
||||
newTupleCount);
|
||||
// 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
|
||||
if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
|
||||
ALOGE("OringDurTracker %s dropping data for dimension key %s", mName.c_str(),
|
||||
newKey.c_str());
|
||||
ALOGE("OringDurTracker %lld dropping data for dimension key %s",
|
||||
(long long)mTrackerId, newKey.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace statsd {
|
||||
// Tracks the "Or'd" duration -- if 2 durations are overlapping, they won't be double counted.
|
||||
class OringDurationTracker : public DurationTracker {
|
||||
public:
|
||||
OringDurationTracker(const ConfigKey& key, const string& name,
|
||||
OringDurationTracker(const ConfigKey& key, const int64_t& id,
|
||||
const HashableDimensionKey& eventKey, sp<ConditionWizard> wizard,
|
||||
int conditionIndex, bool nesting, uint64_t currentBucketStartNs,
|
||||
uint64_t bucketSizeNs,
|
||||
|
||||
@@ -38,21 +38,21 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
bool handleMetricWithLogTrackers(const string what, const int metricIndex,
|
||||
bool handleMetricWithLogTrackers(const int64_t what, const int metricIndex,
|
||||
const bool usedForDimension,
|
||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
const unordered_map<string, int>& logTrackerMap,
|
||||
const unordered_map<int64_t, int>& logTrackerMap,
|
||||
unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||
int& logTrackerIndex) {
|
||||
auto logTrackerIt = logTrackerMap.find(what);
|
||||
if (logTrackerIt == logTrackerMap.end()) {
|
||||
ALOGW("cannot find the AtomMatcher \"%s\" in config", what.c_str());
|
||||
ALOGW("cannot find the AtomMatcher \"%lld\" in config", (long long)what);
|
||||
return false;
|
||||
}
|
||||
if (usedForDimension && allAtomMatchers[logTrackerIt->second]->getAtomIds().size() > 1) {
|
||||
ALOGE("AtomMatcher \"%s\" has more than one tag ids. When a metric has dimension, "
|
||||
ALOGE("AtomMatcher \"%lld\" has more than one tag ids. When a metric has dimension, "
|
||||
"the \"what\" can only about one atom type.",
|
||||
what.c_str());
|
||||
(long long)what);
|
||||
return false;
|
||||
}
|
||||
logTrackerIndex = logTrackerIt->second;
|
||||
@@ -62,22 +62,22 @@ bool handleMetricWithLogTrackers(const string what, const int metricIndex,
|
||||
}
|
||||
|
||||
bool handleMetricWithConditions(
|
||||
const string condition, const int metricIndex,
|
||||
const unordered_map<string, int>& conditionTrackerMap,
|
||||
const int64_t condition, const int metricIndex,
|
||||
const unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
const ::google::protobuf::RepeatedPtrField<::android::os::statsd::MetricConditionLink>&
|
||||
links,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers, int& conditionIndex,
|
||||
unordered_map<int, std::vector<int>>& conditionToMetricMap) {
|
||||
auto condition_it = conditionTrackerMap.find(condition);
|
||||
if (condition_it == conditionTrackerMap.end()) {
|
||||
ALOGW("cannot find Predicate \"%s\" in the config", condition.c_str());
|
||||
ALOGW("cannot find Predicate \"%lld\" in the config", (long long)condition);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& link : links) {
|
||||
auto it = conditionTrackerMap.find(link.condition());
|
||||
if (it == conditionTrackerMap.end()) {
|
||||
ALOGW("cannot find Predicate \"%s\" in the config", link.condition().c_str());
|
||||
ALOGW("cannot find Predicate \"%lld\" in the config", (long long)link.condition());
|
||||
return false;
|
||||
}
|
||||
allConditionTrackers[condition_it->second]->setSliced(true);
|
||||
@@ -93,7 +93,7 @@ bool handleMetricWithConditions(
|
||||
}
|
||||
|
||||
bool initLogTrackers(const StatsdConfig& config, const UidMap& uidMap,
|
||||
unordered_map<string, int>& logTrackerMap,
|
||||
unordered_map<int64_t, int>& logTrackerMap,
|
||||
vector<sp<LogMatchingTracker>>& allAtomMatchers, set<int>& allTagIds) {
|
||||
vector<AtomMatcher> matcherConfigs;
|
||||
const int atomMatcherCount = config.atom_matcher_size();
|
||||
@@ -107,22 +107,22 @@ bool initLogTrackers(const StatsdConfig& config, const UidMap& uidMap,
|
||||
switch (logMatcher.contents_case()) {
|
||||
case AtomMatcher::ContentsCase::kSimpleAtomMatcher:
|
||||
allAtomMatchers.push_back(new SimpleLogMatchingTracker(
|
||||
logMatcher.name(), index, logMatcher.simple_atom_matcher(), uidMap));
|
||||
logMatcher.id(), index, logMatcher.simple_atom_matcher(), uidMap));
|
||||
break;
|
||||
case AtomMatcher::ContentsCase::kCombination:
|
||||
allAtomMatchers.push_back(
|
||||
new CombinationLogMatchingTracker(logMatcher.name(), index));
|
||||
new CombinationLogMatchingTracker(logMatcher.id(), index));
|
||||
break;
|
||||
default:
|
||||
ALOGE("Matcher \"%s\" malformed", logMatcher.name().c_str());
|
||||
ALOGE("Matcher \"%lld\" malformed", (long long)logMatcher.id());
|
||||
return false;
|
||||
// continue;
|
||||
}
|
||||
if (logTrackerMap.find(logMatcher.name()) != logTrackerMap.end()) {
|
||||
if (logTrackerMap.find(logMatcher.id()) != logTrackerMap.end()) {
|
||||
ALOGE("Duplicate AtomMatcher found!");
|
||||
return false;
|
||||
}
|
||||
logTrackerMap[logMatcher.name()] = index;
|
||||
logTrackerMap[logMatcher.id()] = index;
|
||||
matcherConfigs.push_back(logMatcher);
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ bool initLogTrackers(const StatsdConfig& config, const UidMap& uidMap,
|
||||
}
|
||||
|
||||
bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
const unordered_map<string, int>& logTrackerMap,
|
||||
unordered_map<string, int>& conditionTrackerMap,
|
||||
const unordered_map<int64_t, int>& logTrackerMap,
|
||||
unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
unordered_map<int, std::vector<int>>& trackerToConditionMap) {
|
||||
vector<Predicate> conditionConfigs;
|
||||
@@ -154,23 +154,23 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
switch (condition.contents_case()) {
|
||||
case Predicate::ContentsCase::kSimplePredicate: {
|
||||
allConditionTrackers.push_back(new SimpleConditionTracker(
|
||||
key, condition.name(), index, condition.simple_predicate(), logTrackerMap));
|
||||
key, condition.id(), index, condition.simple_predicate(), logTrackerMap));
|
||||
break;
|
||||
}
|
||||
case Predicate::ContentsCase::kCombination: {
|
||||
allConditionTrackers.push_back(
|
||||
new CombinationConditionTracker(condition.name(), index));
|
||||
new CombinationConditionTracker(condition.id(), index));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ALOGE("Predicate \"%s\" malformed", condition.name().c_str());
|
||||
ALOGE("Predicate \"%lld\" malformed", (long long)condition.id());
|
||||
return false;
|
||||
}
|
||||
if (conditionTrackerMap.find(condition.name()) != conditionTrackerMap.end()) {
|
||||
if (conditionTrackerMap.find(condition.id()) != conditionTrackerMap.end()) {
|
||||
ALOGE("Duplicate Predicate found!");
|
||||
return false;
|
||||
}
|
||||
conditionTrackerMap[condition.name()] = index;
|
||||
conditionTrackerMap[condition.id()] = index;
|
||||
conditionConfigs.push_back(condition);
|
||||
}
|
||||
|
||||
@@ -190,14 +190,15 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
|
||||
bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long timeBaseSec,
|
||||
const unordered_map<string, int>& logTrackerMap,
|
||||
const unordered_map<string, int>& conditionTrackerMap,
|
||||
const unordered_map<int64_t, int>& logTrackerMap,
|
||||
const unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
vector<sp<MetricProducer>>& allMetricProducers,
|
||||
unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
||||
unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||
unordered_map<string, int>& metricMap) {
|
||||
unordered_map<int64_t, int>& metricMap,
|
||||
std::set<int64_t> &noReportMetricIds) {
|
||||
sp<ConditionWizard> wizard = new ConditionWizard(allConditionTrackers);
|
||||
const int allMetricsCount = config.count_metric_size() + config.duration_metric_size() +
|
||||
config.event_metric_size() + config.value_metric_size();
|
||||
@@ -219,12 +220,12 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
for (int i = 0; i < config.count_metric_size(); i++) {
|
||||
const CountMetric& metric = config.count_metric(i);
|
||||
if (!metric.has_what()) {
|
||||
ALOGW("cannot find \"what\" in CountMetric \"%s\"", metric.name().c_str());
|
||||
ALOGW("cannot find \"what\" in CountMetric \"%lld\"", (long long)metric.id());
|
||||
return false;
|
||||
}
|
||||
|
||||
int metricIndex = allMetricProducers.size();
|
||||
metricMap.insert({metric.name(), metricIndex});
|
||||
metricMap.insert({metric.id(), metricIndex});
|
||||
int trackerIndex;
|
||||
if (!handleMetricWithLogTrackers(metric.what(), metricIndex, metric.has_dimensions(),
|
||||
allAtomMatchers, logTrackerMap, trackerToMetricMap,
|
||||
@@ -256,7 +257,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
for (int i = 0; i < config.duration_metric_size(); i++) {
|
||||
int metricIndex = allMetricProducers.size();
|
||||
const DurationMetric& metric = config.duration_metric(i);
|
||||
metricMap.insert({metric.name(), metricIndex});
|
||||
metricMap.insert({metric.id(), metricIndex});
|
||||
|
||||
auto what_it = conditionTrackerMap.find(metric.what());
|
||||
if (what_it == conditionTrackerMap.end()) {
|
||||
@@ -327,8 +328,8 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
for (int i = 0; i < config.event_metric_size(); i++) {
|
||||
int metricIndex = allMetricProducers.size();
|
||||
const EventMetric& metric = config.event_metric(i);
|
||||
metricMap.insert({metric.name(), metricIndex});
|
||||
if (!metric.has_name() || !metric.has_what()) {
|
||||
metricMap.insert({metric.id(), metricIndex});
|
||||
if (!metric.has_id() || !metric.has_what()) {
|
||||
ALOGW("cannot find the metric name or what in config");
|
||||
return false;
|
||||
}
|
||||
@@ -363,12 +364,12 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
for (int i = 0; i < config.value_metric_size(); i++) {
|
||||
const ValueMetric& metric = config.value_metric(i);
|
||||
if (!metric.has_what()) {
|
||||
ALOGW("cannot find \"what\" in ValueMetric \"%s\"", metric.name().c_str());
|
||||
ALOGW("cannot find \"what\" in ValueMetric \"%lld\"", (long long)metric.id());
|
||||
return false;
|
||||
}
|
||||
|
||||
int metricIndex = allMetricProducers.size();
|
||||
metricMap.insert({metric.name(), metricIndex});
|
||||
metricMap.insert({metric.id(), metricIndex});
|
||||
int trackerIndex;
|
||||
if (!handleMetricWithLogTrackers(metric.what(), metricIndex, metric.has_dimensions(),
|
||||
allAtomMatchers, logTrackerMap, trackerToMetricMap,
|
||||
@@ -408,25 +409,25 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
for (int i = 0; i < config.gauge_metric_size(); i++) {
|
||||
const GaugeMetric& metric = config.gauge_metric(i);
|
||||
if (!metric.has_what()) {
|
||||
ALOGW("cannot find \"what\" in GaugeMetric \"%s\"", metric.name().c_str());
|
||||
ALOGW("cannot find \"what\" in GaugeMetric \"%lld\"", (long long)metric.id());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((!metric.gauge_fields_filter().has_include_all() ||
|
||||
(metric.gauge_fields_filter().include_all() == false)) &&
|
||||
!hasLeafNode(metric.gauge_fields_filter().fields())) {
|
||||
ALOGW("Incorrect field filter setting in GaugeMetric %s", metric.name().c_str());
|
||||
ALOGW("Incorrect field filter setting in GaugeMetric %lld", (long long)metric.id());
|
||||
return false;
|
||||
}
|
||||
if ((metric.gauge_fields_filter().has_include_all() &&
|
||||
metric.gauge_fields_filter().include_all() == true) &&
|
||||
hasLeafNode(metric.gauge_fields_filter().fields())) {
|
||||
ALOGW("Incorrect field filter setting in GaugeMetric %s", metric.name().c_str());
|
||||
ALOGW("Incorrect field filter setting in GaugeMetric %lld", (long long)metric.id());
|
||||
return false;
|
||||
}
|
||||
|
||||
int metricIndex = allMetricProducers.size();
|
||||
metricMap.insert({metric.name(), metricIndex});
|
||||
metricMap.insert({metric.id(), metricIndex});
|
||||
int trackerIndex;
|
||||
if (!handleMetricWithLogTrackers(metric.what(), metricIndex, metric.has_dimensions(),
|
||||
allAtomMatchers, logTrackerMap, trackerToMetricMap,
|
||||
@@ -461,19 +462,28 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const long ti
|
||||
key, metric, conditionIndex, wizard, pullTagId, atomTagId, startTimeNs);
|
||||
allMetricProducers.push_back(gaugeProducer);
|
||||
}
|
||||
for (int i = 0; i < config.no_report_metric_size(); ++i) {
|
||||
const auto no_report_metric = config.no_report_metric(i);
|
||||
if (metricMap.find(no_report_metric) == metricMap.end()) {
|
||||
ALOGW("no_report_metric %lld not exist", no_report_metric);
|
||||
return false;
|
||||
}
|
||||
noReportMetricIds.insert(no_report_metric);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initAlerts(const StatsdConfig& config,
|
||||
const unordered_map<string, int>& metricProducerMap,
|
||||
const unordered_map<int64_t, int>& metricProducerMap,
|
||||
vector<sp<MetricProducer>>& allMetricProducers,
|
||||
vector<sp<AnomalyTracker>>& allAnomalyTrackers) {
|
||||
unordered_map<int64_t, int> anomalyTrackerMap;
|
||||
for (int i = 0; i < config.alert_size(); i++) {
|
||||
const Alert& alert = config.alert(i);
|
||||
const auto& itr = metricProducerMap.find(alert.metric_name());
|
||||
const auto& itr = metricProducerMap.find(alert.metric_id());
|
||||
if (itr == metricProducerMap.end()) {
|
||||
ALOGW("alert \"%s\" has unknown metric name: \"%s\"", alert.name().c_str(),
|
||||
alert.metric_name().c_str());
|
||||
ALOGW("alert \"%lld\" has unknown metric id: \"%lld\"", (long long)alert.id(),
|
||||
(long long)alert.metric_id());
|
||||
return false;
|
||||
}
|
||||
if (alert.trigger_if_sum_gt() < 0 || alert.number_of_buckets() <= 0) {
|
||||
@@ -485,25 +495,44 @@ bool initAlerts(const StatsdConfig& config,
|
||||
sp<MetricProducer> metric = allMetricProducers[metricIndex];
|
||||
sp<AnomalyTracker> anomalyTracker = metric->addAnomalyTracker(alert);
|
||||
if (anomalyTracker != nullptr) {
|
||||
anomalyTrackerMap.insert(std::make_pair(alert.id(), allAnomalyTrackers.size()));
|
||||
allAnomalyTrackers.push_back(anomalyTracker);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < config.subscription_size(); ++i) {
|
||||
const Subscription& subscription = config.subscription(i);
|
||||
if (subscription.subscriber_information_case() ==
|
||||
Subscription::SubscriberInformationCase::SUBSCRIBER_INFORMATION_NOT_SET) {
|
||||
ALOGW("subscription \"%lld\" has no subscriber info.\"",
|
||||
(long long)subscription.id());
|
||||
return false;
|
||||
}
|
||||
const auto& itr = anomalyTrackerMap.find(subscription.rule_id());
|
||||
if (itr == anomalyTrackerMap.end()) {
|
||||
ALOGW("subscription \"%lld\" has unknown rule id: \"%lld\"",
|
||||
(long long)subscription.id(), (long long)subscription.rule_id());
|
||||
return false;
|
||||
}
|
||||
const int anomalyTrackerIndex = itr->second;
|
||||
allAnomalyTrackers[anomalyTrackerIndex]->addSubscription(subscription);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config,
|
||||
const UidMap& uidMap,
|
||||
const long timeBaseSec, set<int>& allTagIds,
|
||||
const UidMap& uidMap,
|
||||
const long timeBaseSec, set<int>& allTagIds,
|
||||
vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
vector<sp<MetricProducer>>& allMetricProducers,
|
||||
vector<sp<AnomalyTracker>>& allAnomalyTrackers,
|
||||
unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
||||
unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||
unordered_map<int, std::vector<int>>& trackerToConditionMap) {
|
||||
unordered_map<string, int> logTrackerMap;
|
||||
unordered_map<string, int> conditionTrackerMap;
|
||||
unordered_map<string, int> metricProducerMap;
|
||||
unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
||||
std::set<int64_t> &noReportMetricIds) {
|
||||
unordered_map<int64_t, int> logTrackerMap;
|
||||
unordered_map<int64_t, int> conditionTrackerMap;
|
||||
unordered_map<int64_t, int> metricProducerMap;
|
||||
|
||||
if (!initLogTrackers(config, uidMap, logTrackerMap, allAtomMatchers, allTagIds)) {
|
||||
ALOGE("initLogMatchingTrackers failed");
|
||||
@@ -519,7 +548,7 @@ bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config,
|
||||
|
||||
if (!initMetrics(key, config, timeBaseSec, logTrackerMap, conditionTrackerMap, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, conditionToMetricMap,
|
||||
trackerToMetricMap, metricProducerMap)) {
|
||||
trackerToMetricMap, metricProducerMap, noReportMetricIds)) {
|
||||
ALOGE("initMetricProducers failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ namespace statsd {
|
||||
// [allAtomMatchers]: should store the sp to all the LogMatchingTracker
|
||||
// [allTagIds]: contains the set of all interesting tag ids to this config.
|
||||
bool initLogTrackers(const StatsdConfig& config,
|
||||
const UidMap& uidMap,
|
||||
std::unordered_map<std::string, int>& logTrackerMap,
|
||||
const UidMap& uidMap,
|
||||
std::unordered_map<int64_t, int>& logTrackerMap,
|
||||
std::vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
std::set<int>& allTagIds);
|
||||
|
||||
@@ -59,8 +59,8 @@ bool initLogTrackers(const StatsdConfig& config,
|
||||
// [trackerToConditionMap]: contain the mapping from index of
|
||||
// log tracker to condition trackers that use the log tracker
|
||||
bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
const std::unordered_map<std::string, int>& logTrackerMap,
|
||||
std::unordered_map<std::string, int>& conditionTrackerMap,
|
||||
const std::unordered_map<int64_t, int>& logTrackerMap,
|
||||
std::unordered_map<int64_t, int>& conditionTrackerMap,
|
||||
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
||||
std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks);
|
||||
@@ -79,28 +79,29 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
// [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
|
||||
bool initMetrics(
|
||||
const ConfigKey& key, const StatsdConfig& config, const long timeBaseSec,
|
||||
const std::unordered_map<std::string, int>& logTrackerMap,
|
||||
const std::unordered_map<std::string, int>& conditionTrackerMap,
|
||||
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,
|
||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::vector<sp<MetricProducer>>& allMetricProducers,
|
||||
std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
||||
std::unordered_map<int, std::vector<int>>& trackerToMetricMap);
|
||||
std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||
std::set<int64_t> &noReportMetricIds);
|
||||
|
||||
// Initialize MetricsManager from StatsdConfig.
|
||||
// Parameters are the members of MetricsManager. See MetricsManager for declaration.
|
||||
bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config,
|
||||
|
||||
const UidMap& uidMap,
|
||||
const long timeBaseSec, std::set<int>& allTagIds,
|
||||
const UidMap& uidMap,
|
||||
const long timeBaseSec, std::set<int>& allTagIds,
|
||||
std::vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::vector<sp<MetricProducer>>& allMetricProducers,
|
||||
vector<sp<AnomalyTracker>>& allAnomalyTrackers,
|
||||
std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
|
||||
std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
|
||||
std::unordered_map<int, std::vector<int>>& trackerToConditionMap);
|
||||
std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
||||
std::set<int64_t> &noReportMetricIds);
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
|
||||
@@ -137,7 +137,7 @@ message UidMapping {
|
||||
}
|
||||
|
||||
message StatsLogReport {
|
||||
optional string metric_name = 1;
|
||||
optional int64 metric_id = 1;
|
||||
|
||||
optional int64 start_report_nanos = 2;
|
||||
|
||||
@@ -178,7 +178,7 @@ message ConfigMetricsReport {
|
||||
message ConfigMetricsReportList {
|
||||
message ConfigKey {
|
||||
optional int32 uid = 1;
|
||||
optional string name = 2;
|
||||
optional int64 id = 2;
|
||||
}
|
||||
optional ConfigKey config_key = 1;
|
||||
|
||||
@@ -191,28 +191,28 @@ message StatsdStatsReport {
|
||||
optional int32 stats_end_time_sec = 2;
|
||||
|
||||
message MatcherStats {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
optional int32 matched_times = 2;
|
||||
}
|
||||
|
||||
message ConditionStats {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
optional int32 max_tuple_counts = 2;
|
||||
}
|
||||
|
||||
message MetricStats {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
optional int32 max_tuple_counts = 2;
|
||||
}
|
||||
|
||||
message AlertStats {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
optional int32 alerted_times = 2;
|
||||
}
|
||||
|
||||
message ConfigStats {
|
||||
optional int32 uid = 1;
|
||||
optional string name = 2;
|
||||
optional int64 id = 2;
|
||||
optional int32 creation_time_sec = 3;
|
||||
optional int32 deletion_time_sec = 4;
|
||||
optional int32 metric_count = 5;
|
||||
|
||||
@@ -32,7 +32,7 @@ const HashableDimensionKey DEFAULT_DIMENSION_KEY = HashableDimensionKey();
|
||||
// Minimum bucket size in seconds
|
||||
const long kMinBucketSizeSec = 5 * 60;
|
||||
|
||||
typedef std::map<std::string, std::vector<HashableDimensionKey>> ConditionKey;
|
||||
typedef std::map<int64_t, std::vector<HashableDimensionKey>> ConditionKey;
|
||||
|
||||
typedef std::unordered_map<HashableDimensionKey, int64_t> DimToValMap;
|
||||
|
||||
|
||||
@@ -84,12 +84,12 @@ message SimpleAtomMatcher {
|
||||
}
|
||||
|
||||
message AtomMatcher {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
message Combination {
|
||||
optional LogicalOperation operation = 1;
|
||||
|
||||
repeated string matcher = 2;
|
||||
repeated int64 matcher = 2;
|
||||
}
|
||||
oneof contents {
|
||||
SimpleAtomMatcher simple_atom_matcher = 2;
|
||||
@@ -98,13 +98,13 @@ message AtomMatcher {
|
||||
}
|
||||
|
||||
message SimplePredicate {
|
||||
optional string start = 1;
|
||||
optional int64 start = 1;
|
||||
|
||||
optional string stop = 2;
|
||||
optional int64 stop = 2;
|
||||
|
||||
optional bool count_nesting = 3 [default = true];
|
||||
|
||||
optional string stop_all = 4;
|
||||
optional int64 stop_all = 4;
|
||||
|
||||
enum InitialValue {
|
||||
UNKNOWN = 0;
|
||||
@@ -116,12 +116,12 @@ message SimplePredicate {
|
||||
}
|
||||
|
||||
message Predicate {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
message Combination {
|
||||
optional LogicalOperation operation = 1;
|
||||
|
||||
repeated string predicate = 2;
|
||||
repeated int64 predicate = 2;
|
||||
}
|
||||
|
||||
oneof contents {
|
||||
@@ -135,7 +135,7 @@ message Bucket {
|
||||
}
|
||||
|
||||
message MetricConditionLink {
|
||||
optional string condition = 1;
|
||||
optional int64 condition = 1;
|
||||
|
||||
optional FieldMatcher dimensions_in_what = 2;
|
||||
|
||||
@@ -148,21 +148,21 @@ message FieldFilter {
|
||||
}
|
||||
|
||||
message EventMetric {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string what = 2;
|
||||
optional int64 what = 2;
|
||||
|
||||
optional string condition = 3;
|
||||
optional int64 condition = 3;
|
||||
|
||||
repeated MetricConditionLink links = 4;
|
||||
}
|
||||
|
||||
message CountMetric {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string what = 2;
|
||||
optional int64 what = 2;
|
||||
|
||||
optional string condition = 3;
|
||||
optional int64 condition = 3;
|
||||
|
||||
optional FieldMatcher dimensions = 4;
|
||||
|
||||
@@ -172,11 +172,11 @@ message CountMetric {
|
||||
}
|
||||
|
||||
message DurationMetric {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string what = 2;
|
||||
optional int64 what = 2;
|
||||
|
||||
optional string condition = 3;
|
||||
optional int64 condition = 3;
|
||||
|
||||
repeated MetricConditionLink links = 4;
|
||||
|
||||
@@ -193,13 +193,13 @@ message DurationMetric {
|
||||
}
|
||||
|
||||
message GaugeMetric {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string what = 2;
|
||||
optional int64 what = 2;
|
||||
|
||||
optional FieldFilter gauge_fields_filter = 3;
|
||||
|
||||
optional string condition = 4;
|
||||
optional int64 condition = 4;
|
||||
|
||||
optional FieldMatcher dimensions = 5;
|
||||
|
||||
@@ -209,13 +209,13 @@ message GaugeMetric {
|
||||
}
|
||||
|
||||
message ValueMetric {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string what = 2;
|
||||
optional int64 what = 2;
|
||||
|
||||
optional int32 value_field = 3;
|
||||
|
||||
optional string condition = 4;
|
||||
optional int64 condition = 4;
|
||||
|
||||
optional FieldMatcher dimensions = 5;
|
||||
|
||||
@@ -228,20 +228,15 @@ message ValueMetric {
|
||||
}
|
||||
|
||||
message Alert {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
optional string metric_name = 2;
|
||||
optional int64 metric_id = 2;
|
||||
|
||||
message IncidentdDetails {
|
||||
repeated int32 section = 1;
|
||||
}
|
||||
optional IncidentdDetails incidentd_details = 3;
|
||||
optional int32 number_of_buckets = 3;
|
||||
|
||||
optional int32 number_of_buckets = 4;
|
||||
optional int32 refractory_period_secs = 4;
|
||||
|
||||
optional int32 refractory_period_secs = 5;
|
||||
|
||||
optional int64 trigger_if_sum_gt = 6;
|
||||
optional int64 trigger_if_sum_gt = 5;
|
||||
}
|
||||
|
||||
message AllowedLogSource {
|
||||
@@ -249,8 +244,40 @@ message AllowedLogSource {
|
||||
repeated string package = 2;
|
||||
}
|
||||
|
||||
message Alarm {
|
||||
optional int64 id = 1;
|
||||
optional int64 offset_millis = 2;
|
||||
optional int64 period_millis = 3;
|
||||
}
|
||||
|
||||
message IncidentdDetails {
|
||||
repeated int32 section = 1;
|
||||
}
|
||||
|
||||
message PerfettoDetails {
|
||||
optional int32 perfetto_stuff = 1;
|
||||
}
|
||||
|
||||
message Subscription {
|
||||
optional int64 id = 1;
|
||||
|
||||
enum RuleType {
|
||||
RULE_TYPE_UNSPECIFIED = 0;
|
||||
ALARM = 1;
|
||||
ALERT = 2;
|
||||
}
|
||||
optional RuleType rule_type = 2;
|
||||
|
||||
optional int64 rule_id = 3;
|
||||
|
||||
oneof subscriber_information {
|
||||
IncidentdDetails incidentd_details = 4;
|
||||
PerfettoDetails perfetto_details = 5;
|
||||
}
|
||||
}
|
||||
|
||||
message StatsdConfig {
|
||||
optional string name = 1;
|
||||
optional int64 id = 1;
|
||||
|
||||
repeated EventMetric event_metric = 2;
|
||||
|
||||
@@ -268,5 +295,11 @@ message StatsdConfig {
|
||||
|
||||
repeated Alert alert = 9;
|
||||
|
||||
optional AllowedLogSource log_source = 10;
|
||||
repeated Alarm alarm = 10;
|
||||
|
||||
repeated Subscription subscription = 11;
|
||||
|
||||
optional AllowedLogSource log_source = 12;
|
||||
|
||||
repeated int64 no_report_metric = 13;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ void StorageManager::sendBroadcast(const char* path,
|
||||
}
|
||||
if (index < 2) continue;
|
||||
|
||||
sendBroadcast(ConfigKey(uid, configName));
|
||||
sendBroadcast(ConfigKey(uid, StrToInt64(configName)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +198,7 @@ void StorageManager::readConfigFromDisk(map<ConfigKey, StatsdConfig>& configsMap
|
||||
index++;
|
||||
}
|
||||
if (index < 2) continue;
|
||||
|
||||
string file_name = StringPrintf("%s/%s", STATS_SERVICE_DIR, name);
|
||||
VLOG("full file %s", file_name.c_str());
|
||||
int fd = open(file_name.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
@@ -206,7 +207,7 @@ void StorageManager::readConfigFromDisk(map<ConfigKey, StatsdConfig>& configsMap
|
||||
if (android::base::ReadFdToString(fd, &content)) {
|
||||
StatsdConfig config;
|
||||
if (config.ParseFromString(content)) {
|
||||
configsMap[ConfigKey(uid, configName)] = config;
|
||||
configsMap[ConfigKey(uid, StrToInt64(configName))] = config;
|
||||
VLOG("map key uid=%d|name=%s", uid, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "src/config/ConfigManager.h"
|
||||
#include "src/metrics/MetricsManager.h"
|
||||
#include "statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -31,7 +32,7 @@ namespace os {
|
||||
namespace statsd {
|
||||
|
||||
static ostream& operator<<(ostream& os, const StatsdConfig& config) {
|
||||
return os << "StatsdConfig{name=" << config.name().c_str() << "}";
|
||||
return os << "StatsdConfig{id=" << config.id() << "}";
|
||||
}
|
||||
|
||||
} // namespace statsd
|
||||
@@ -50,19 +51,21 @@ public:
|
||||
/**
|
||||
* Validate that the ConfigKey is the one we wanted.
|
||||
*/
|
||||
MATCHER_P2(ConfigKeyEq, uid, name, "") {
|
||||
return arg.GetUid() == uid && arg.GetName() == name;
|
||||
MATCHER_P2(ConfigKeyEq, uid, id, "") {
|
||||
return arg.GetUid() == uid && (long long)arg.GetId() == (long long)id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the StatsdConfig is the one we wanted.
|
||||
*/
|
||||
MATCHER_P(StatsdConfigEq, name, "") {
|
||||
return arg.name() == name;
|
||||
MATCHER_P(StatsdConfigEq, id, 0) {
|
||||
return (long long)arg.id() == (long long)id;
|
||||
}
|
||||
|
||||
const int64_t testConfigId = 12345;
|
||||
|
||||
TEST(ConfigManagerTest, TestFakeConfig) {
|
||||
auto metricsManager = std::make_unique<MetricsManager>(ConfigKey(0, "test"),
|
||||
auto metricsManager = std::make_unique<MetricsManager>(ConfigKey(0, testConfigId),
|
||||
build_fake_config(), 1000, new UidMap());
|
||||
EXPECT_TRUE(metricsManager->isConfigValid());
|
||||
}
|
||||
@@ -77,13 +80,13 @@ TEST(ConfigManagerTest, TestAddUpdateRemove) {
|
||||
manager->AddListener(listener);
|
||||
|
||||
StatsdConfig config91;
|
||||
config91.set_name("91");
|
||||
config91.set_id(91);
|
||||
StatsdConfig config92;
|
||||
config92.set_name("92");
|
||||
config92.set_id(92);
|
||||
StatsdConfig config93;
|
||||
config93.set_name("93");
|
||||
config93.set_id(93);
|
||||
StatsdConfig config94;
|
||||
config94.set_name("94");
|
||||
config94.set_id(94);
|
||||
|
||||
{
|
||||
InSequence s;
|
||||
@@ -91,42 +94,46 @@ TEST(ConfigManagerTest, TestAddUpdateRemove) {
|
||||
manager->Startup();
|
||||
|
||||
// Add another one
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, "zzz"), StatsdConfigEq("91")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, StringToId("zzz")),
|
||||
StatsdConfigEq(91)))
|
||||
.RetiresOnSaturation();
|
||||
manager->UpdateConfig(ConfigKey(1, "zzz"), config91);
|
||||
manager->UpdateConfig(ConfigKey(1, StringToId("zzz")), config91);
|
||||
|
||||
// Update It
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, "zzz"), StatsdConfigEq("92")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, StringToId("zzz")),
|
||||
StatsdConfigEq(92)))
|
||||
.RetiresOnSaturation();
|
||||
manager->UpdateConfig(ConfigKey(1, "zzz"), config92);
|
||||
manager->UpdateConfig(ConfigKey(1, StringToId("zzz")), config92);
|
||||
|
||||
// Add one with the same uid but a different name
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, "yyy"), StatsdConfigEq("93")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(1, StringToId("yyy")),
|
||||
StatsdConfigEq(93)))
|
||||
.RetiresOnSaturation();
|
||||
manager->UpdateConfig(ConfigKey(1, "yyy"), config93);
|
||||
manager->UpdateConfig(ConfigKey(1, StringToId("yyy")), config93);
|
||||
|
||||
// Add one with the same name but a different uid
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(2, "zzz"), StatsdConfigEq("94")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(ConfigKeyEq(2, StringToId("zzz")),
|
||||
StatsdConfigEq(94)))
|
||||
.RetiresOnSaturation();
|
||||
manager->UpdateConfig(ConfigKey(2, "zzz"), config94);
|
||||
manager->UpdateConfig(ConfigKey(2, StringToId("zzz")), config94);
|
||||
|
||||
// Remove (1,yyy)
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(1, "yyy")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(1, StringToId("yyy"))))
|
||||
.RetiresOnSaturation();
|
||||
manager->RemoveConfig(ConfigKey(1, "yyy"));
|
||||
manager->RemoveConfig(ConfigKey(1, StringToId("yyy")));
|
||||
|
||||
// Remove (2,zzz)
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, "zzz")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, StringToId("zzz"))))
|
||||
.RetiresOnSaturation();
|
||||
manager->RemoveConfig(ConfigKey(2, "zzz"));
|
||||
manager->RemoveConfig(ConfigKey(2, StringToId("zzz")));
|
||||
|
||||
// Remove (1,zzz)
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(1, "zzz")))
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(1, StringToId("zzz"))))
|
||||
.RetiresOnSaturation();
|
||||
manager->RemoveConfig(ConfigKey(1, "zzz"));
|
||||
manager->RemoveConfig(ConfigKey(1, StringToId("zzz")));
|
||||
|
||||
// Remove (2,zzz) again and we shouldn't get the callback
|
||||
manager->RemoveConfig(ConfigKey(2, "zzz"));
|
||||
manager->RemoveConfig(ConfigKey(2, StringToId("zzz")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,16 +149,16 @@ TEST(ConfigManagerTest, TestRemoveUid) {
|
||||
StatsdConfig config;
|
||||
|
||||
EXPECT_CALL(*(listener.get()), OnConfigUpdated(_, _)).Times(5);
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, "xxx")));
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, "yyy")));
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, "zzz")));
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, StringToId("xxx"))));
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, StringToId("yyy"))));
|
||||
EXPECT_CALL(*(listener.get()), OnConfigRemoved(ConfigKeyEq(2, StringToId("zzz"))));
|
||||
|
||||
manager->Startup();
|
||||
manager->UpdateConfig(ConfigKey(1, "aaa"), config);
|
||||
manager->UpdateConfig(ConfigKey(2, "xxx"), config);
|
||||
manager->UpdateConfig(ConfigKey(2, "yyy"), config);
|
||||
manager->UpdateConfig(ConfigKey(2, "zzz"), config);
|
||||
manager->UpdateConfig(ConfigKey(3, "bbb"), config);
|
||||
manager->UpdateConfig(ConfigKey(1, StringToId("aaa")), config);
|
||||
manager->UpdateConfig(ConfigKey(2, StringToId("xxx")), config);
|
||||
manager->UpdateConfig(ConfigKey(2, StringToId("yyy")), config);
|
||||
manager->UpdateConfig(ConfigKey(2, StringToId("zzz")), config);
|
||||
manager->UpdateConfig(ConfigKey(3, StringToId("bbb")), config);
|
||||
|
||||
manager->RemoveConfigs(2);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "src/metrics/MetricProducer.h"
|
||||
#include "src/metrics/ValueMetricProducer.h"
|
||||
#include "src/metrics/metrics_manager_util.h"
|
||||
#include "statsd_test_util.h"
|
||||
|
||||
#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
|
||||
|
||||
@@ -40,16 +41,16 @@ using android::os::statsd::Predicate;
|
||||
|
||||
// TODO: ADD MORE TEST CASES.
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
const long timeBaseSec = 1000;
|
||||
|
||||
StatsdConfig buildGoodConfig() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_ON");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
|
||||
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -59,7 +60,7 @@ StatsdConfig buildGoodConfig() {
|
||||
2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_OFF");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_OFF"));
|
||||
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -69,23 +70,25 @@ StatsdConfig buildGoodConfig() {
|
||||
1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_ON_OR_OFF");
|
||||
eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
|
||||
|
||||
AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
|
||||
combination->set_operation(LogicalOperation::OR);
|
||||
combination->add_matcher("SCREEN_IS_ON");
|
||||
combination->add_matcher("SCREEN_IS_OFF");
|
||||
combination->add_matcher(StringToId("SCREEN_IS_ON"));
|
||||
combination->add_matcher(StringToId("SCREEN_IS_OFF"));
|
||||
|
||||
CountMetric* metric = config.add_count_metric();
|
||||
metric->set_name("3");
|
||||
metric->set_what("SCREEN_IS_ON");
|
||||
metric->set_id(3);
|
||||
metric->set_what(StringToId("SCREEN_IS_ON"));
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
metric->mutable_dimensions()->set_field(2 /*SCREEN_STATE_CHANGE*/);
|
||||
metric->mutable_dimensions()->add_child()->set_field(1);
|
||||
|
||||
config.add_no_report_metric(3);
|
||||
|
||||
auto alert = config.add_alert();
|
||||
alert->set_name("3");
|
||||
alert->set_metric_name("3");
|
||||
alert->set_id(3);
|
||||
alert->set_metric_id(3);
|
||||
alert->set_number_of_buckets(10);
|
||||
alert->set_refractory_period_secs(100);
|
||||
alert->set_trigger_if_sum_gt(100);
|
||||
@@ -94,10 +97,10 @@ StatsdConfig buildGoodConfig() {
|
||||
|
||||
StatsdConfig buildCircleMatchers() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_ON");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
|
||||
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -107,34 +110,34 @@ StatsdConfig buildCircleMatchers() {
|
||||
2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_ON_OR_OFF");
|
||||
eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
|
||||
|
||||
AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
|
||||
combination->set_operation(LogicalOperation::OR);
|
||||
combination->add_matcher("SCREEN_IS_ON");
|
||||
combination->add_matcher(StringToId("SCREEN_IS_ON"));
|
||||
// Circle dependency
|
||||
combination->add_matcher("SCREEN_ON_OR_OFF");
|
||||
combination->add_matcher(StringToId("SCREEN_ON_OR_OFF"));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
StatsdConfig buildAlertWithUnknownMetric() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_ON");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
|
||||
|
||||
CountMetric* metric = config.add_count_metric();
|
||||
metric->set_name("3");
|
||||
metric->set_what("SCREEN_IS_ON");
|
||||
metric->set_id(3);
|
||||
metric->set_what(StringToId("SCREEN_IS_ON"));
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
metric->mutable_dimensions()->set_field(2 /*SCREEN_STATE_CHANGE*/);
|
||||
metric->mutable_dimensions()->add_child()->set_field(1);
|
||||
|
||||
auto alert = config.add_alert();
|
||||
alert->set_name("3");
|
||||
alert->set_metric_name("2");
|
||||
alert->set_id(3);
|
||||
alert->set_metric_id(2);
|
||||
alert->set_number_of_buckets(10);
|
||||
alert->set_refractory_period_secs(100);
|
||||
alert->set_trigger_if_sum_gt(100);
|
||||
@@ -143,10 +146,10 @@ StatsdConfig buildAlertWithUnknownMetric() {
|
||||
|
||||
StatsdConfig buildMissingMatchers() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_ON");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
|
||||
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -156,29 +159,29 @@ StatsdConfig buildMissingMatchers() {
|
||||
2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_ON_OR_OFF");
|
||||
eventMatcher->set_id(StringToId("SCREEN_ON_OR_OFF"));
|
||||
|
||||
AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
|
||||
combination->set_operation(LogicalOperation::OR);
|
||||
combination->add_matcher("SCREEN_IS_ON");
|
||||
combination->add_matcher(StringToId("SCREEN_IS_ON"));
|
||||
// undefined matcher
|
||||
combination->add_matcher("ABC");
|
||||
combination->add_matcher(StringToId("ABC"));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
StatsdConfig buildMissingPredicate() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
CountMetric* metric = config.add_count_metric();
|
||||
metric->set_name("3");
|
||||
metric->set_what("SCREEN_EVENT");
|
||||
metric->set_id(3);
|
||||
metric->set_what(StringToId("SCREEN_EVENT"));
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
metric->set_condition("SOME_CONDITION");
|
||||
metric->set_condition(StringToId("SOME_CONDITION"));
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_EVENT");
|
||||
eventMatcher->set_id(StringToId("SCREEN_EVENT"));
|
||||
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2);
|
||||
@@ -188,37 +191,37 @@ StatsdConfig buildMissingPredicate() {
|
||||
|
||||
StatsdConfig buildDimensionMetricsWithMultiTags() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("BATTERY_VERY_LOW");
|
||||
eventMatcher->set_id(StringToId("BATTERY_VERY_LOW"));
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("BATTERY_VERY_VERY_LOW");
|
||||
eventMatcher->set_id(StringToId("BATTERY_VERY_VERY_LOW"));
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(3);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("BATTERY_LOW");
|
||||
eventMatcher->set_id(StringToId("BATTERY_LOW"));
|
||||
|
||||
AtomMatcher_Combination* combination = eventMatcher->mutable_combination();
|
||||
combination->set_operation(LogicalOperation::OR);
|
||||
combination->add_matcher("BATTERY_VERY_LOW");
|
||||
combination->add_matcher("BATTERY_VERY_VERY_LOW");
|
||||
combination->add_matcher(StringToId("BATTERY_VERY_LOW"));
|
||||
combination->add_matcher(StringToId("BATTERY_VERY_VERY_LOW"));
|
||||
|
||||
// Count process state changes, slice by uid, while SCREEN_IS_OFF
|
||||
CountMetric* metric = config.add_count_metric();
|
||||
metric->set_name("3");
|
||||
metric->set_what("BATTERY_LOW");
|
||||
metric->set_id(3);
|
||||
metric->set_what(StringToId("BATTERY_LOW"));
|
||||
metric->mutable_bucket()->set_bucket_size_millis(30 * 1000L);
|
||||
// This case is interesting. We want to dimension across two atoms.
|
||||
metric->mutable_dimensions()->add_child()->set_field(1);
|
||||
|
||||
auto alert = config.add_alert();
|
||||
alert->set_name("3");
|
||||
alert->set_metric_name("3");
|
||||
alert->set_id(103);
|
||||
alert->set_metric_id(3);
|
||||
alert->set_number_of_buckets(10);
|
||||
alert->set_refractory_period_secs(100);
|
||||
alert->set_trigger_if_sum_gt(100);
|
||||
@@ -227,10 +230,10 @@ StatsdConfig buildDimensionMetricsWithMultiTags() {
|
||||
|
||||
StatsdConfig buildCirclePredicates() {
|
||||
StatsdConfig config;
|
||||
config.set_name("12345");
|
||||
config.set_id(12345);
|
||||
|
||||
AtomMatcher* eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_ON");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_ON"));
|
||||
|
||||
SimpleAtomMatcher* simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -240,7 +243,7 @@ StatsdConfig buildCirclePredicates() {
|
||||
2 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON*/);
|
||||
|
||||
eventMatcher = config.add_atom_matcher();
|
||||
eventMatcher->set_name("SCREEN_IS_OFF");
|
||||
eventMatcher->set_id(StringToId("SCREEN_IS_OFF"));
|
||||
|
||||
simpleAtomMatcher = eventMatcher->mutable_simple_atom_matcher();
|
||||
simpleAtomMatcher->set_atom_id(2 /*SCREEN_STATE_CHANGE*/);
|
||||
@@ -250,18 +253,18 @@ StatsdConfig buildCirclePredicates() {
|
||||
1 /*SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF*/);
|
||||
|
||||
auto condition = config.add_predicate();
|
||||
condition->set_name("SCREEN_IS_ON");
|
||||
condition->set_id(StringToId("SCREEN_IS_ON"));
|
||||
SimplePredicate* simplePredicate = condition->mutable_simple_predicate();
|
||||
simplePredicate->set_start("SCREEN_IS_ON");
|
||||
simplePredicate->set_stop("SCREEN_IS_OFF");
|
||||
simplePredicate->set_start(StringToId("SCREEN_IS_ON"));
|
||||
simplePredicate->set_stop(StringToId("SCREEN_IS_OFF"));
|
||||
|
||||
condition = config.add_predicate();
|
||||
condition->set_name("SCREEN_IS_EITHER_ON_OFF");
|
||||
condition->set_id(StringToId("SCREEN_IS_EITHER_ON_OFF"));
|
||||
|
||||
Predicate_Combination* combination = condition->mutable_combination();
|
||||
combination->set_operation(LogicalOperation::OR);
|
||||
combination->add_predicate("SCREEN_IS_ON");
|
||||
combination->add_predicate("SCREEN_IS_EITHER_ON_OFF");
|
||||
combination->add_predicate(StringToId("SCREEN_IS_ON"));
|
||||
combination->add_predicate(StringToId("SCREEN_IS_EITHER_ON_OFF"));
|
||||
|
||||
return config;
|
||||
}
|
||||
@@ -277,12 +280,15 @@ TEST(MetricsManagerTest, TestGoodConfig) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
unordered_map<int, std::vector<int>> trackerToMetricMap;
|
||||
unordered_map<int, std::vector<int>> trackerToConditionMap;
|
||||
std::set<int64_t> noReportMetricIds;
|
||||
|
||||
EXPECT_TRUE(initStatsdConfig(kConfigKey, config, uidMap, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
EXPECT_EQ(1u, allMetricProducers.size());
|
||||
EXPECT_EQ(1u, allAnomalyTrackers.size());
|
||||
EXPECT_EQ(1u, noReportMetricIds.size());
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) {
|
||||
@@ -296,10 +302,12 @@ TEST(MetricsManagerTest, TestDimensionMetricsWithMultiTags) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestCircleLogMatcherDependency) {
|
||||
@@ -313,10 +321,12 @@ TEST(MetricsManagerTest, TestCircleLogMatcherDependency) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestMissingMatchers) {
|
||||
@@ -330,9 +340,11 @@ TEST(MetricsManagerTest, TestMissingMatchers) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestMissingPredicate) {
|
||||
@@ -346,9 +358,11 @@ TEST(MetricsManagerTest, TestMissingPredicate) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, TestCirclePredicateDependency) {
|
||||
@@ -362,10 +376,12 @@ TEST(MetricsManagerTest, TestCirclePredicateDependency) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
TEST(MetricsManagerTest, testAlertWithUnknownMetric) {
|
||||
@@ -379,10 +395,12 @@ TEST(MetricsManagerTest, testAlertWithUnknownMetric) {
|
||||
unordered_map<int, std::vector<int>> conditionToMetricMap;
|
||||
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, timeBaseSec, allTagIds, allAtomMatchers,
|
||||
allConditionTrackers, allMetricProducers, allAnomalyTrackers,
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap));
|
||||
conditionToMetricMap, trackerToMetricMap, trackerToConditionMap,
|
||||
noReportMetricIds));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -41,7 +41,7 @@ using android::util::ProtoOutputStream;
|
||||
*/
|
||||
class MockMetricsManager : public MetricsManager {
|
||||
public:
|
||||
MockMetricsManager() : MetricsManager(ConfigKey(1, "key"), StatsdConfig(), 1000, new UidMap()) {
|
||||
MockMetricsManager() : MetricsManager(ConfigKey(1, 12345), StatsdConfig(), 1000, new UidMap()) {
|
||||
}
|
||||
|
||||
MOCK_METHOD0(byteSize, size_t());
|
||||
@@ -56,7 +56,7 @@ TEST(StatsLogProcessorTest, TestRateLimitByteSize) {
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
ConfigKey key(100, "key");
|
||||
ConfigKey key(100, 12345);
|
||||
// Expect only the first flush to trigger a check for byte size since the last two are
|
||||
// rate-limited.
|
||||
EXPECT_CALL(mockMetricsManager, byteSize()).Times(1);
|
||||
@@ -74,7 +74,7 @@ TEST(StatsLogProcessorTest, TestRateLimitBroadcast) {
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
ConfigKey key(100, "key");
|
||||
ConfigKey key(100, 12345);
|
||||
EXPECT_CALL(mockMetricsManager, byteSize())
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(int(StatsdStats::kMaxMetricsBytesPerConfig * .95)));
|
||||
@@ -98,7 +98,7 @@ TEST(StatsLogProcessorTest, TestDropWhenByteSizeTooLarge) {
|
||||
|
||||
MockMetricsManager mockMetricsManager;
|
||||
|
||||
ConfigKey key(100, "key");
|
||||
ConfigKey key(100, 12345);
|
||||
EXPECT_CALL(mockMetricsManager, byteSize())
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(int(StatsdStats::kMaxMetricsBytesPerConfig * 1.2)));
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "guardrail/StatsdStats.h"
|
||||
#include "logd/LogEvent.h"
|
||||
#include "statslog.h"
|
||||
#include "statsd_test_util.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -156,8 +157,8 @@ TEST(UidMapTest, TestUpdateApp) {
|
||||
TEST(UidMapTest, TestClearingOutput) {
|
||||
UidMap m;
|
||||
|
||||
ConfigKey config1(1, "config1");
|
||||
ConfigKey config2(1, "config2");
|
||||
ConfigKey config1(1, StringToId("config1"));
|
||||
ConfigKey config2(1, StringToId("config2"));
|
||||
|
||||
m.OnConfigUpdated(config1);
|
||||
|
||||
@@ -211,7 +212,7 @@ TEST(UidMapTest, TestClearingOutput) {
|
||||
TEST(UidMapTest, TestMemoryComputed) {
|
||||
UidMap m;
|
||||
|
||||
ConfigKey config1(1, "config1");
|
||||
ConfigKey config1(1, StringToId("config1"));
|
||||
m.OnConfigUpdated(config1);
|
||||
|
||||
size_t startBytes = m.mBytesUsed;
|
||||
@@ -241,7 +242,7 @@ TEST(UidMapTest, TestMemoryGuardrail) {
|
||||
UidMap m;
|
||||
string buf;
|
||||
|
||||
ConfigKey config1(1, "config1");
|
||||
ConfigKey config1(1, StringToId("config1"));
|
||||
m.OnConfigUpdated(config1);
|
||||
|
||||
size_t startBytes = m.mBytesUsed;
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
HashableDimensionKey getMockDimensionKey(int key, string value) {
|
||||
DimensionsValue dimensionsValue;
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
// 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.
|
||||
|
||||
#include "src/condition/SimpleConditionTracker.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -29,7 +31,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
const int ATTRIBUTION_NODE_FIELD_ID = 1;
|
||||
const int ATTRIBUTION_UID_FIELD_ID = 1;
|
||||
@@ -38,9 +40,9 @@ const int TAG_ID = 1;
|
||||
SimplePredicate getWakeLockHeldCondition(bool countNesting, bool defaultFalse,
|
||||
bool outputSlicedUid, Position position) {
|
||||
SimplePredicate simplePredicate;
|
||||
simplePredicate.set_start("WAKE_LOCK_ACQUIRE");
|
||||
simplePredicate.set_stop("WAKE_LOCK_RELEASE");
|
||||
simplePredicate.set_stop_all("RELEASE_ALL");
|
||||
simplePredicate.set_start(StringToId("WAKE_LOCK_ACQUIRE"));
|
||||
simplePredicate.set_stop(StringToId("WAKE_LOCK_RELEASE"));
|
||||
simplePredicate.set_stop_all(StringToId("RELEASE_ALL"));
|
||||
if (outputSlicedUid) {
|
||||
simplePredicate.mutable_dimensions()->set_field(TAG_ID);
|
||||
simplePredicate.mutable_dimensions()->add_child()->set_field(ATTRIBUTION_NODE_FIELD_ID);
|
||||
@@ -73,10 +75,10 @@ void makeWakeLockEvent(
|
||||
event->init();
|
||||
}
|
||||
|
||||
std::map<string, std::vector<HashableDimensionKey>> getWakeLockQueryKey(
|
||||
std::map<int64_t, std::vector<HashableDimensionKey>> getWakeLockQueryKey(
|
||||
const Position position,
|
||||
const std::vector<int> &uids, const string& conditionName) {
|
||||
std::map<string, std::vector<HashableDimensionKey>> outputKeyMap;
|
||||
std::map<int64_t, std::vector<HashableDimensionKey>> outputKeyMap;
|
||||
std::vector<int> uid_indexes;
|
||||
switch(position) {
|
||||
case Position::FIRST:
|
||||
@@ -96,28 +98,29 @@ std::map<string, std::vector<HashableDimensionKey>> getWakeLockQueryKey(
|
||||
for (const int idx : uid_indexes) {
|
||||
DimensionsValue dimensionsValue;
|
||||
dimensionsValue.set_field(TAG_ID);
|
||||
dimensionsValue.mutable_value_tuple()->add_dimensions_value()->set_field(ATTRIBUTION_NODE_FIELD_ID);
|
||||
dimensionsValue.mutable_value_tuple()->add_dimensions_value()->set_field(
|
||||
ATTRIBUTION_NODE_FIELD_ID);
|
||||
dimensionsValue.mutable_value_tuple()->mutable_dimensions_value(0)
|
||||
->mutable_value_tuple()->add_dimensions_value()->set_field(ATTRIBUTION_NODE_FIELD_ID);
|
||||
dimensionsValue.mutable_value_tuple()->mutable_dimensions_value(0)
|
||||
->mutable_value_tuple()->mutable_dimensions_value(0)->set_value_int(uids[idx]);
|
||||
outputKeyMap[conditionName].push_back(HashableDimensionKey(dimensionsValue));
|
||||
outputKeyMap[StringToId(conditionName)].push_back(HashableDimensionKey(dimensionsValue));
|
||||
}
|
||||
return outputKeyMap;
|
||||
}
|
||||
|
||||
TEST(SimpleConditionTrackerTest, TestNonSlicedCondition) {
|
||||
SimplePredicate simplePredicate;
|
||||
simplePredicate.set_start("SCREEN_TURNED_ON");
|
||||
simplePredicate.set_stop("SCREEN_TURNED_OFF");
|
||||
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
|
||||
simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF"));
|
||||
simplePredicate.set_count_nesting(false);
|
||||
simplePredicate.set_initial_value(SimplePredicate_InitialValue_UNKNOWN);
|
||||
|
||||
unordered_map<string, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap["SCREEN_TURNED_ON"] = 0;
|
||||
trackerNameIndexMap["SCREEN_TURNED_OFF"] = 1;
|
||||
unordered_map<int64_t, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0;
|
||||
trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1;
|
||||
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, "SCREEN_IS_ON", 0 /*tracker index*/,
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"), 0 /*tracker index*/,
|
||||
simplePredicate, trackerNameIndexMap);
|
||||
|
||||
LogEvent event(1 /*tagId*/, 0 /*timestamp*/);
|
||||
@@ -191,15 +194,15 @@ TEST(SimpleConditionTrackerTest, TestNonSlicedCondition) {
|
||||
|
||||
TEST(SimpleConditionTrackerTest, TestNonSlicedConditionNestCounting) {
|
||||
SimplePredicate simplePredicate;
|
||||
simplePredicate.set_start("SCREEN_TURNED_ON");
|
||||
simplePredicate.set_stop("SCREEN_TURNED_OFF");
|
||||
simplePredicate.set_start(StringToId("SCREEN_TURNED_ON"));
|
||||
simplePredicate.set_stop(StringToId("SCREEN_TURNED_OFF"));
|
||||
simplePredicate.set_count_nesting(true);
|
||||
|
||||
unordered_map<string, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap["SCREEN_TURNED_ON"] = 0;
|
||||
trackerNameIndexMap["SCREEN_TURNED_OFF"] = 1;
|
||||
unordered_map<int64_t, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap[StringToId("SCREEN_TURNED_ON")] = 0;
|
||||
trackerNameIndexMap[StringToId("SCREEN_TURNED_OFF")] = 1;
|
||||
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, "SCREEN_IS_ON",
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, StringToId("SCREEN_IS_ON"),
|
||||
0 /*condition tracker index*/, simplePredicate,
|
||||
trackerNameIndexMap);
|
||||
|
||||
@@ -267,12 +270,12 @@ TEST(SimpleConditionTrackerTest, TestSlicedCondition) {
|
||||
position);
|
||||
string conditionName = "WL_HELD_BY_UID2";
|
||||
|
||||
unordered_map<string, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap["WAKE_LOCK_ACQUIRE"] = 0;
|
||||
trackerNameIndexMap["WAKE_LOCK_RELEASE"] = 1;
|
||||
trackerNameIndexMap["RELEASE_ALL"] = 2;
|
||||
unordered_map<int64_t, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_ACQUIRE")] = 0;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_RELEASE")] = 1;
|
||||
trackerNameIndexMap[StringToId("RELEASE_ALL")] = 2;
|
||||
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, conditionName,
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, StringToId(conditionName),
|
||||
0 /*condition tracker index*/, simplePredicate,
|
||||
trackerNameIndexMap);
|
||||
std::vector<int> uids = {111, 222, 333};
|
||||
@@ -371,12 +374,12 @@ TEST(SimpleConditionTrackerTest, TestSlicedWithNoOutputDim) {
|
||||
Position::ANY /* position */);
|
||||
string conditionName = "WL_HELD";
|
||||
|
||||
unordered_map<string, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap["WAKE_LOCK_ACQUIRE"] = 0;
|
||||
trackerNameIndexMap["WAKE_LOCK_RELEASE"] = 1;
|
||||
trackerNameIndexMap["RELEASE_ALL"] = 2;
|
||||
unordered_map<int64_t, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_ACQUIRE")] = 0;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_RELEASE")] = 1;
|
||||
trackerNameIndexMap[StringToId("RELEASE_ALL")] = 2;
|
||||
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, conditionName,
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, StringToId(conditionName),
|
||||
0 /*condition tracker index*/, simplePredicate,
|
||||
trackerNameIndexMap);
|
||||
|
||||
@@ -461,12 +464,12 @@ TEST(SimpleConditionTrackerTest, TestStopAll) {
|
||||
position);
|
||||
string conditionName = "WL_HELD_BY_UID3";
|
||||
|
||||
unordered_map<string, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap["WAKE_LOCK_ACQUIRE"] = 0;
|
||||
trackerNameIndexMap["WAKE_LOCK_RELEASE"] = 1;
|
||||
trackerNameIndexMap["RELEASE_ALL"] = 2;
|
||||
unordered_map<int64_t, int> trackerNameIndexMap;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_ACQUIRE")] = 0;
|
||||
trackerNameIndexMap[StringToId("WAKE_LOCK_RELEASE")] = 1;
|
||||
trackerNameIndexMap[StringToId("RELEASE_ALL")] = 2;
|
||||
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, conditionName,
|
||||
SimpleConditionTracker conditionTracker(kConfigKey, StringToId(conditionName),
|
||||
0 /*condition tracker index*/, simplePredicate,
|
||||
trackerNameIndexMap);
|
||||
|
||||
|
||||
@@ -55,16 +55,16 @@ StatsdConfig CreateStatsdConfig() {
|
||||
*config.add_predicate() = isInBackgroundPredicate;
|
||||
|
||||
auto combinationPredicate = config.add_predicate();
|
||||
combinationPredicate->set_name("combinationPredicate");
|
||||
combinationPredicate->set_id(StringToId("combinationPredicate"));
|
||||
combinationPredicate->mutable_combination()->set_operation(LogicalOperation::AND);
|
||||
addPredicateToPredicateCombination(screenIsOffPredicate, combinationPredicate);
|
||||
addPredicateToPredicateCombination(isSyncingPredicate, combinationPredicate);
|
||||
addPredicateToPredicateCombination(isInBackgroundPredicate, combinationPredicate);
|
||||
|
||||
auto countMetric = config.add_count_metric();
|
||||
countMetric->set_name("AppCrashes");
|
||||
countMetric->set_what(appCrashMatcher.name());
|
||||
countMetric->set_condition(combinationPredicate->name());
|
||||
countMetric->set_id(StringToId("AppCrashes"));
|
||||
countMetric->set_what(appCrashMatcher.id());
|
||||
countMetric->set_condition(combinationPredicate->id());
|
||||
// The metric is dimensioning by uid only.
|
||||
*countMetric->mutable_dimensions() =
|
||||
CreateDimensions(android::util::PROCESS_LIFE_CYCLE_STATE_CHANGED, {1});
|
||||
@@ -72,7 +72,7 @@ StatsdConfig CreateStatsdConfig() {
|
||||
|
||||
// Links between crash atom and condition of app is in syncing.
|
||||
auto links = countMetric->add_links();
|
||||
links->set_condition(isSyncingPredicate.name());
|
||||
links->set_condition(isSyncingPredicate.id());
|
||||
auto dimensionWhat = links->mutable_dimensions_in_what();
|
||||
dimensionWhat->set_field(android::util::PROCESS_LIFE_CYCLE_STATE_CHANGED);
|
||||
dimensionWhat->add_child()->set_field(1); // uid field.
|
||||
@@ -82,7 +82,7 @@ StatsdConfig CreateStatsdConfig() {
|
||||
|
||||
// Links between crash atom and condition of app is in background.
|
||||
links = countMetric->add_links();
|
||||
links->set_condition(isInBackgroundPredicate.name());
|
||||
links->set_condition(isInBackgroundPredicate.id());
|
||||
dimensionWhat = links->mutable_dimensions_in_what();
|
||||
dimensionWhat->set_field(android::util::PROCESS_LIFE_CYCLE_STATE_CHANGED);
|
||||
dimensionWhat->add_child()->set_field(1); // uid field.
|
||||
|
||||
@@ -43,9 +43,9 @@ StatsdConfig CreateStatsdConfig(DurationMetric::AggregationType aggregationType)
|
||||
*config.add_predicate() = holdingWakelockPredicate;
|
||||
|
||||
auto durationMetric = config.add_duration_metric();
|
||||
durationMetric->set_name("WakelockDuration");
|
||||
durationMetric->set_what(holdingWakelockPredicate.name());
|
||||
durationMetric->set_condition(screenIsOffPredicate.name());
|
||||
durationMetric->set_id(StringToId("WakelockDuration"));
|
||||
durationMetric->set_what(holdingWakelockPredicate.id());
|
||||
durationMetric->set_condition(screenIsOffPredicate.id());
|
||||
durationMetric->set_aggregation_type(aggregationType);
|
||||
// The metric is dimensioning by first attribution node and only by uid.
|
||||
*durationMetric->mutable_dimensions() =
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "src/guardrail/StatsdStats.h"
|
||||
#include "statslog.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
@@ -28,8 +29,7 @@ using std::vector;
|
||||
|
||||
TEST(StatsdStatsTest, TestValidConfigAdd) {
|
||||
StatsdStats stats;
|
||||
string name = "StatsdTest";
|
||||
ConfigKey key(0, name);
|
||||
ConfigKey key(0, 12345);
|
||||
const int metricsCount = 10;
|
||||
const int conditionsCount = 20;
|
||||
const int matchersCount = 30;
|
||||
@@ -45,7 +45,7 @@ TEST(StatsdStatsTest, TestValidConfigAdd) {
|
||||
EXPECT_EQ(1, report.config_stats_size());
|
||||
const auto& configReport = report.config_stats(0);
|
||||
EXPECT_EQ(0, configReport.uid());
|
||||
EXPECT_EQ(name, configReport.name());
|
||||
EXPECT_EQ(12345, configReport.id());
|
||||
EXPECT_EQ(metricsCount, configReport.metric_count());
|
||||
EXPECT_EQ(conditionsCount, configReport.condition_count());
|
||||
EXPECT_EQ(matchersCount, configReport.matcher_count());
|
||||
@@ -56,8 +56,7 @@ TEST(StatsdStatsTest, TestValidConfigAdd) {
|
||||
|
||||
TEST(StatsdStatsTest, TestInvalidConfigAdd) {
|
||||
StatsdStats stats;
|
||||
string name = "StatsdTest";
|
||||
ConfigKey key(0, name);
|
||||
ConfigKey key(0, 12345);
|
||||
const int metricsCount = 10;
|
||||
const int conditionsCount = 20;
|
||||
const int matchersCount = 30;
|
||||
@@ -78,8 +77,7 @@ TEST(StatsdStatsTest, TestInvalidConfigAdd) {
|
||||
|
||||
TEST(StatsdStatsTest, TestConfigRemove) {
|
||||
StatsdStats stats;
|
||||
string name = "StatsdTest";
|
||||
ConfigKey key(0, name);
|
||||
ConfigKey key(0, 12345);
|
||||
const int metricsCount = 10;
|
||||
const int conditionsCount = 20;
|
||||
const int matchersCount = 30;
|
||||
@@ -105,22 +103,22 @@ TEST(StatsdStatsTest, TestConfigRemove) {
|
||||
|
||||
TEST(StatsdStatsTest, TestSubStats) {
|
||||
StatsdStats stats;
|
||||
ConfigKey key(0, "test");
|
||||
ConfigKey key(0, 12345);
|
||||
stats.noteConfigReceived(key, 2, 3, 4, 5, true);
|
||||
|
||||
stats.noteMatcherMatched(key, "matcher1");
|
||||
stats.noteMatcherMatched(key, "matcher1");
|
||||
stats.noteMatcherMatched(key, "matcher2");
|
||||
stats.noteMatcherMatched(key, StringToId("matcher1"));
|
||||
stats.noteMatcherMatched(key, StringToId("matcher1"));
|
||||
stats.noteMatcherMatched(key, StringToId("matcher2"));
|
||||
|
||||
stats.noteConditionDimensionSize(key, "condition1", 250);
|
||||
stats.noteConditionDimensionSize(key, "condition1", 240);
|
||||
stats.noteConditionDimensionSize(key, StringToId("condition1"), 250);
|
||||
stats.noteConditionDimensionSize(key, StringToId("condition1"), 240);
|
||||
|
||||
stats.noteMetricDimensionSize(key, "metric1", 201);
|
||||
stats.noteMetricDimensionSize(key, "metric1", 202);
|
||||
stats.noteMetricDimensionSize(key, StringToId("metric1"), 201);
|
||||
stats.noteMetricDimensionSize(key, StringToId("metric1"), 202);
|
||||
|
||||
stats.noteAnomalyDeclared(key, "alert1");
|
||||
stats.noteAnomalyDeclared(key, "alert1");
|
||||
stats.noteAnomalyDeclared(key, "alert2");
|
||||
stats.noteAnomalyDeclared(key, StringToId("alert1"));
|
||||
stats.noteAnomalyDeclared(key, StringToId("alert1"));
|
||||
stats.noteAnomalyDeclared(key, StringToId("alert2"));
|
||||
|
||||
// broadcast-> 2
|
||||
stats.noteBroadcastSent(key);
|
||||
@@ -147,39 +145,39 @@ TEST(StatsdStatsTest, TestSubStats) {
|
||||
|
||||
EXPECT_EQ(2, configReport.matcher_stats_size());
|
||||
// matcher1 is the first in the list
|
||||
if (!configReport.matcher_stats(0).name().compare("matcher1")) {
|
||||
if (configReport.matcher_stats(0).id() == StringToId("matcher1")) {
|
||||
EXPECT_EQ(2, configReport.matcher_stats(0).matched_times());
|
||||
EXPECT_EQ(1, configReport.matcher_stats(1).matched_times());
|
||||
EXPECT_EQ("matcher2", configReport.matcher_stats(1).name());
|
||||
EXPECT_EQ(StringToId("matcher2"), configReport.matcher_stats(1).id());
|
||||
} else {
|
||||
// matcher1 is the second in the list.
|
||||
EXPECT_EQ(1, configReport.matcher_stats(0).matched_times());
|
||||
EXPECT_EQ("matcher2", configReport.matcher_stats(0).name());
|
||||
EXPECT_EQ(StringToId("matcher2"), configReport.matcher_stats(0).id());
|
||||
|
||||
EXPECT_EQ(2, configReport.matcher_stats(1).matched_times());
|
||||
EXPECT_EQ("matcher1", configReport.matcher_stats(1).name());
|
||||
EXPECT_EQ(StringToId("matcher1"), configReport.matcher_stats(1).id());
|
||||
}
|
||||
|
||||
EXPECT_EQ(2, configReport.alert_stats_size());
|
||||
bool alert1first = !configReport.alert_stats(0).name().compare("alert1");
|
||||
EXPECT_EQ("alert1", configReport.alert_stats(alert1first ? 0 : 1).name());
|
||||
bool alert1first = configReport.alert_stats(0).id() == StringToId("alert1");
|
||||
EXPECT_EQ(StringToId("alert1"), configReport.alert_stats(alert1first ? 0 : 1).id());
|
||||
EXPECT_EQ(2, configReport.alert_stats(alert1first ? 0 : 1).alerted_times());
|
||||
EXPECT_EQ("alert2", configReport.alert_stats(alert1first ? 1 : 0).name());
|
||||
EXPECT_EQ(StringToId("alert2"), configReport.alert_stats(alert1first ? 1 : 0).id());
|
||||
EXPECT_EQ(1, configReport.alert_stats(alert1first ? 1 : 0).alerted_times());
|
||||
|
||||
EXPECT_EQ(1, configReport.condition_stats_size());
|
||||
EXPECT_EQ("condition1", configReport.condition_stats(0).name());
|
||||
EXPECT_EQ(StringToId("condition1"), configReport.condition_stats(0).id());
|
||||
EXPECT_EQ(250, configReport.condition_stats(0).max_tuple_counts());
|
||||
|
||||
EXPECT_EQ(1, configReport.metric_stats_size());
|
||||
EXPECT_EQ("metric1", configReport.metric_stats(0).name());
|
||||
EXPECT_EQ(StringToId("metric1"), configReport.metric_stats(0).id());
|
||||
EXPECT_EQ(202, configReport.metric_stats(0).max_tuple_counts());
|
||||
|
||||
// after resetting the stats, some new events come
|
||||
stats.noteMatcherMatched(key, "matcher99");
|
||||
stats.noteConditionDimensionSize(key, "condition99", 300);
|
||||
stats.noteMetricDimensionSize(key, "metric99", 270);
|
||||
stats.noteAnomalyDeclared(key, "alert99");
|
||||
stats.noteMatcherMatched(key, StringToId("matcher99"));
|
||||
stats.noteConditionDimensionSize(key, StringToId("condition99"), 300);
|
||||
stats.noteMetricDimensionSize(key, StringToId("metric99tion99"), 270);
|
||||
stats.noteAnomalyDeclared(key, StringToId("alert99"));
|
||||
|
||||
// now the config stats should only contain the stats about the new event.
|
||||
stats.dumpStats(&output, false);
|
||||
@@ -188,19 +186,19 @@ TEST(StatsdStatsTest, TestSubStats) {
|
||||
EXPECT_EQ(1, report.config_stats_size());
|
||||
const auto& configReport2 = report.config_stats(0);
|
||||
EXPECT_EQ(1, configReport2.matcher_stats_size());
|
||||
EXPECT_EQ("matcher99", configReport2.matcher_stats(0).name());
|
||||
EXPECT_EQ(StringToId("matcher99"), configReport2.matcher_stats(0).id());
|
||||
EXPECT_EQ(1, configReport2.matcher_stats(0).matched_times());
|
||||
|
||||
EXPECT_EQ(1, configReport2.condition_stats_size());
|
||||
EXPECT_EQ("condition99", configReport2.condition_stats(0).name());
|
||||
EXPECT_EQ(StringToId("condition99"), configReport2.condition_stats(0).id());
|
||||
EXPECT_EQ(300, configReport2.condition_stats(0).max_tuple_counts());
|
||||
|
||||
EXPECT_EQ(1, configReport2.metric_stats_size());
|
||||
EXPECT_EQ("metric99", configReport2.metric_stats(0).name());
|
||||
EXPECT_EQ(StringToId("metric99tion99"), configReport2.metric_stats(0).id());
|
||||
EXPECT_EQ(270, configReport2.metric_stats(0).max_tuple_counts());
|
||||
|
||||
EXPECT_EQ(1, configReport2.alert_stats_size());
|
||||
EXPECT_EQ("alert99", configReport2.alert_stats(0).name());
|
||||
EXPECT_EQ(StringToId("alert99"), configReport2.alert_stats(0).id());
|
||||
EXPECT_EQ(1, configReport2.alert_stats(0).alerted_times());
|
||||
}
|
||||
|
||||
@@ -260,7 +258,7 @@ TEST(StatsdStatsTest, TestTimestampThreshold) {
|
||||
for (int i = 0; i < StatsdStats::kMaxTimestampCount; i++) {
|
||||
timestamps.push_back(i);
|
||||
}
|
||||
ConfigKey key(0, "test");
|
||||
ConfigKey key(0, 12345);
|
||||
stats.noteConfigReceived(key, 2, 3, 4, 5, true);
|
||||
|
||||
for (int i = 0; i < StatsdStats::kMaxTimestampCount; i++) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "src/metrics/CountMetricProducer.h"
|
||||
#include "src/dimension.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -33,7 +34,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
TEST(CountMetricProducerTest, TestNonDimensionalEvents) {
|
||||
int64_t bucketStartTimeNs = 10000000000;
|
||||
@@ -43,7 +44,7 @@ TEST(CountMetricProducerTest, TestNonDimensionalEvents) {
|
||||
int tagId = 1;
|
||||
|
||||
CountMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
|
||||
LogEvent event1(tagId, bucketStartTimeNs + 1);
|
||||
@@ -100,9 +101,9 @@ TEST(CountMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
||||
int64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
CountMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_condition("SCREEN_ON");
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
LogEvent event1(1, bucketStartTimeNs + 1);
|
||||
LogEvent event2(1, bucketStartTimeNs + 10);
|
||||
@@ -142,11 +143,11 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
int conditionTagId = 2;
|
||||
|
||||
CountMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_condition("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON");
|
||||
metric.set_condition(StringToId("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON"));
|
||||
MetricConditionLink* link = metric.add_links();
|
||||
link->set_condition("APP_IN_BACKGROUND_PER_UID");
|
||||
link->set_condition(StringToId("APP_IN_BACKGROUND_PER_UID"));
|
||||
*link->mutable_dimensions_in_what() = buildSimpleAtomFieldMatcher(tagId, 1);
|
||||
*link->mutable_dimensions_in_condition() = buildSimpleAtomFieldMatcher(conditionTagId, 2);
|
||||
|
||||
@@ -154,13 +155,15 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
event1.write("111"); // uid
|
||||
event1.init();
|
||||
ConditionKey key1;
|
||||
key1["APP_IN_BACKGROUND_PER_UID"] = {getMockedDimensionKey(conditionTagId, 2, "111")};
|
||||
key1[StringToId("APP_IN_BACKGROUND_PER_UID")] =
|
||||
{getMockedDimensionKey(conditionTagId, 2, "111")};
|
||||
|
||||
LogEvent event2(tagId, bucketStartTimeNs + 10);
|
||||
event2.write("222"); // uid
|
||||
event2.init();
|
||||
ConditionKey key2;
|
||||
key2["APP_IN_BACKGROUND_PER_UID"] = {getMockedDimensionKey(conditionTagId, 2, "222")};
|
||||
key2[StringToId("APP_IN_BACKGROUND_PER_UID")] =
|
||||
{getMockedDimensionKey(conditionTagId, 2, "222")};
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
EXPECT_CALL(*wizard, query(_, key1)).WillOnce(Return(ConditionState::kFalse));
|
||||
@@ -189,8 +192,8 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
|
||||
TEST(CountMetricProducerTest, TestAnomalyDetection) {
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name("1");
|
||||
alert.set_id(11);
|
||||
alert.set_metric_id(1);
|
||||
alert.set_trigger_if_sum_gt(2);
|
||||
alert.set_number_of_buckets(2);
|
||||
alert.set_refractory_period_secs(1);
|
||||
@@ -201,7 +204,7 @@ TEST(CountMetricProducerTest, TestAnomalyDetection) {
|
||||
int64_t bucket3StartTimeNs = bucketStartTimeNs + 2 * bucketSizeNs;
|
||||
|
||||
CountMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
TEST(DurationMetricTrackerTest, TestNoCondition) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
@@ -44,7 +44,7 @@ TEST(DurationMetricTrackerTest, TestNoCondition) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
DurationMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||
|
||||
@@ -79,7 +79,7 @@ TEST(DurationMetricTrackerTest, TestNonSlicedCondition) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
DurationMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_aggregation_type(DurationMetric_AggregationType_SUM);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "src/metrics/EventMetricProducer.h"
|
||||
#include "src/dimension.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -33,7 +34,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
TEST(EventMetricProducerTest, TestNoCondition) {
|
||||
uint64_t bucketStartTimeNs = 10000000000;
|
||||
@@ -41,7 +42,7 @@ TEST(EventMetricProducerTest, TestNoCondition) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
EventMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_id(1);
|
||||
|
||||
LogEvent event1(1 /*tag id*/, bucketStartTimeNs + 1);
|
||||
LogEvent event2(1 /*tag id*/, bucketStartTimeNs + 2);
|
||||
@@ -64,8 +65,8 @@ TEST(EventMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
EventMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_condition("SCREEN_ON");
|
||||
metric.set_id(1);
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
LogEvent event1(1, bucketStartTimeNs + 1);
|
||||
LogEvent event2(1, bucketStartTimeNs + 10);
|
||||
@@ -93,10 +94,10 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
int conditionTagId = 2;
|
||||
|
||||
EventMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_condition("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON");
|
||||
metric.set_id(1);
|
||||
metric.set_condition(StringToId("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON"));
|
||||
MetricConditionLink* link = metric.add_links();
|
||||
link->set_condition("APP_IN_BACKGROUND_PER_UID");
|
||||
link->set_condition(StringToId("APP_IN_BACKGROUND_PER_UID"));
|
||||
*link->mutable_dimensions_in_what() = buildSimpleAtomFieldMatcher(tagId, 1);
|
||||
*link->mutable_dimensions_in_condition() = buildSimpleAtomFieldMatcher(conditionTagId, 2);
|
||||
|
||||
@@ -104,13 +105,13 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
EXPECT_TRUE(event1.write("111"));
|
||||
event1.init();
|
||||
ConditionKey key1;
|
||||
key1["APP_IN_BACKGROUND_PER_UID"] = {getMockedDimensionKey(conditionTagId, 2, "111")};
|
||||
key1[StringToId("APP_IN_BACKGROUND_PER_UID")] = {getMockedDimensionKey(conditionTagId, 2, "111")};
|
||||
|
||||
LogEvent event2(tagId, bucketStartTimeNs + 10);
|
||||
EXPECT_TRUE(event2.write("222"));
|
||||
event2.init();
|
||||
ConditionKey key2;
|
||||
key2["APP_IN_BACKGROUND_PER_UID"] = {getMockedDimensionKey(conditionTagId, 2, "222")};
|
||||
key2[StringToId("APP_IN_BACKGROUND_PER_UID")] = {getMockedDimensionKey(conditionTagId, 2, "222")};
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
EXPECT_CALL(*wizard, query(_, key1)).WillOnce(Return(ConditionState::kFalse));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "src/metrics/GaugeMetricProducer.h"
|
||||
#include "logd/LogEvent.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -34,9 +35,9 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
const int tagId = 1;
|
||||
const string metricName = "test_metric";
|
||||
const int64_t metricId = 123;
|
||||
const int64_t bucketStartTimeNs = 10000000000;
|
||||
const int64_t bucketSizeNs = 60 * 1000 * 1000 * 1000LL;
|
||||
const int64_t bucket2StartTimeNs = bucketStartTimeNs + bucketSizeNs;
|
||||
@@ -45,7 +46,7 @@ const int64_t bucket4StartTimeNs = bucketStartTimeNs + 3 * bucketSizeNs;
|
||||
|
||||
TEST(GaugeMetricProducerTest, TestNoCondition) {
|
||||
GaugeMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.mutable_gauge_fields_filter()->set_include_all(false);
|
||||
auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields();
|
||||
@@ -119,12 +120,12 @@ TEST(GaugeMetricProducerTest, TestNoCondition) {
|
||||
|
||||
TEST(GaugeMetricProducerTest, TestWithCondition) {
|
||||
GaugeMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields();
|
||||
gaugeFieldMatcher->set_field(tagId);
|
||||
gaugeFieldMatcher->add_child()->set_field(2);
|
||||
metric.set_condition("SCREEN_ON");
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
@@ -186,7 +187,7 @@ TEST(GaugeMetricProducerTest, TestAnomalyDetection) {
|
||||
EXPECT_CALL(*pullerManager, UnRegisterReceiver(tagId, _)).WillOnce(Return());
|
||||
|
||||
GaugeMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
auto gaugeFieldMatcher = metric.mutable_gauge_fields_filter()->mutable_fields();
|
||||
gaugeFieldMatcher->set_field(tagId);
|
||||
@@ -195,8 +196,8 @@ TEST(GaugeMetricProducerTest, TestAnomalyDetection) {
|
||||
tagId, tagId, bucketStartTimeNs, pullerManager);
|
||||
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name(metricName);
|
||||
alert.set_id(101);
|
||||
alert.set_metric_id(metricId);
|
||||
alert.set_trigger_if_sum_gt(25);
|
||||
alert.set_number_of_buckets(2);
|
||||
sp<AnomalyTracker> anomalyTracker = gaugeProducer.addAnomalyTracker(alert);
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/metrics/duration_helper/MaxDurationTracker.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "src/condition/ConditionWizard.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -36,7 +37,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
|
||||
const int TagId = 1;
|
||||
|
||||
@@ -50,12 +51,13 @@ TEST(MaxDurationTrackerTest, TestSimpleMaxDuration) {
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
ConditionKey conditionKey1;
|
||||
conditionKey1["condition"] = conditionKey;
|
||||
conditionKey1[StringToId("condition")] = conditionKey;
|
||||
|
||||
uint64_t bucketStartTimeNs = 10000000000;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
int64_t metricId = 1;
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(key1, true, bucketStartTimeNs, conditionKey1);
|
||||
@@ -79,12 +81,13 @@ TEST(MaxDurationTrackerTest, TestStopAll) {
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
ConditionKey conditionKey1;
|
||||
conditionKey1["condition"] = conditionKey;
|
||||
conditionKey1[StringToId("condition")] = conditionKey;
|
||||
|
||||
uint64_t bucketStartTimeNs = 10000000000;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
int64_t metricId = 1;
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(key1, true, bucketStartTimeNs + 1, conditionKey1);
|
||||
@@ -110,12 +113,13 @@ TEST(MaxDurationTrackerTest, TestCrossBucketBoundary) {
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
ConditionKey conditionKey1;
|
||||
conditionKey1["condition"] = conditionKey;
|
||||
conditionKey1[StringToId("condition")] = conditionKey;
|
||||
|
||||
uint64_t bucketStartTimeNs = 10000000000;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
int64_t metricId = 1;
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, -1, false, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
// The event starts.
|
||||
@@ -141,12 +145,13 @@ TEST(MaxDurationTrackerTest, TestCrossBucketBoundary_nested) {
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
ConditionKey conditionKey1;
|
||||
conditionKey1["condition"] = conditionKey;
|
||||
conditionKey1[StringToId("condition")] = conditionKey;
|
||||
|
||||
uint64_t bucketStartTimeNs = 10000000000;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, -1, true, bucketStartTimeNs,
|
||||
int64_t metricId = 1;
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, -1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
// 2 starts
|
||||
@@ -177,7 +182,7 @@ TEST(MaxDurationTrackerTest, TestMaxDurationWithCondition) {
|
||||
|
||||
ConditionKey conditionKey1;
|
||||
HashableDimensionKey eventKey = getMockedDimensionKey(TagId, 2, "maps");
|
||||
conditionKey1["APP_BACKGROUND"] = conditionKey;
|
||||
conditionKey1[StringToId("APP_BACKGROUND")] = conditionKey;
|
||||
|
||||
EXPECT_CALL(*wizard, query(_, conditionKey1)) // #4
|
||||
.WillOnce(Return(ConditionState::kFalse));
|
||||
@@ -189,7 +194,8 @@ TEST(MaxDurationTrackerTest, TestMaxDurationWithCondition) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
int64_t durationTimeNs = 2 * 1000;
|
||||
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, false, bucketStartTimeNs,
|
||||
int64_t metricId = 1;
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, false, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
EXPECT_TRUE(tracker.mAnomalyTrackers.empty());
|
||||
|
||||
@@ -206,9 +212,10 @@ TEST(MaxDurationTrackerTest, TestMaxDurationWithCondition) {
|
||||
}
|
||||
|
||||
TEST(MaxDurationTrackerTest, TestAnomalyDetection) {
|
||||
int64_t metricId = 1;
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name("metric");
|
||||
alert.set_id(101);
|
||||
alert.set_metric_id(metricId);
|
||||
alert.set_trigger_if_sum_gt(32 * NS_PER_SEC);
|
||||
alert.set_number_of_buckets(2);
|
||||
alert.set_refractory_period_secs(1);
|
||||
@@ -216,13 +223,13 @@ TEST(MaxDurationTrackerTest, TestAnomalyDetection) {
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
ConditionKey conditionKey1;
|
||||
conditionKey1["APP_BACKGROUND"] = conditionKey;
|
||||
conditionKey1[StringToId("APP_BACKGROUND")] = conditionKey;
|
||||
uint64_t bucketStartTimeNs = 10 * NS_PER_SEC;
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + NS_PER_SEC + 1;
|
||||
uint64_t bucketSizeNs = 30 * NS_PER_SEC;
|
||||
|
||||
sp<DurationAnomalyTracker> anomalyTracker = new DurationAnomalyTracker(alert, kConfigKey);
|
||||
MaxDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, -1, true, bucketStartTimeNs,
|
||||
MaxDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, -1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {anomalyTracker});
|
||||
|
||||
tracker.noteStart(key1, true, eventStartTimeNs, conditionKey1);
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/metrics/duration_helper/OringDurationTracker.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "src/condition/ConditionWizard.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -34,8 +35,9 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
const int TagId = 1;
|
||||
const int64_t metricId = 123;
|
||||
const HashableDimensionKey eventKey = getMockedDimensionKey(TagId, 0, "event");
|
||||
|
||||
const std::vector<HashableDimensionKey> kConditionKey1 = {getMockedDimensionKey(TagId, 1, "maps")};
|
||||
@@ -46,7 +48,7 @@ TEST(OringDurationTrackerTest, TestDurationOverlap) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
|
||||
@@ -55,7 +57,7 @@ TEST(OringDurationTrackerTest, TestDurationOverlap) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
uint64_t durationTimeNs = 2 * 1000;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, false,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, false,
|
||||
bucketStartTimeNs, bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -75,7 +77,7 @@ TEST(OringDurationTrackerTest, TestDurationNested) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
|
||||
@@ -83,7 +85,7 @@ TEST(OringDurationTrackerTest, TestDurationNested) {
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + 1;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -102,7 +104,7 @@ TEST(OringDurationTrackerTest, TestStopAll) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
|
||||
@@ -110,7 +112,7 @@ TEST(OringDurationTrackerTest, TestStopAll) {
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + 1;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -128,7 +130,7 @@ TEST(OringDurationTrackerTest, TestCrossBucketBoundary) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
|
||||
@@ -137,7 +139,7 @@ TEST(OringDurationTrackerTest, TestCrossBucketBoundary) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
uint64_t durationTimeNs = 2 * 1000;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -163,7 +165,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChange) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
EXPECT_CALL(*wizard, query(_, key1)) // #4
|
||||
.WillOnce(Return(ConditionState::kFalse));
|
||||
@@ -175,7 +177,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChange) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
uint64_t durationTimeNs = 2 * 1000;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, false,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, false,
|
||||
bucketStartTimeNs, bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -194,7 +196,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChange2) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
EXPECT_CALL(*wizard, query(_, key1))
|
||||
.Times(2)
|
||||
@@ -208,7 +210,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChange2) {
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
uint64_t durationTimeNs = 2 * 1000;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, false,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, false,
|
||||
bucketStartTimeNs, bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -229,7 +231,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChangeNested) {
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
|
||||
EXPECT_CALL(*wizard, query(_, key1)) // #4
|
||||
.WillOnce(Return(ConditionState::kFalse));
|
||||
@@ -240,7 +242,7 @@ TEST(OringDurationTrackerTest, TestDurationConditionChangeNested) {
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + 1;
|
||||
uint64_t bucketSizeNs = 30 * 1000 * 1000 * 1000LL;
|
||||
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {});
|
||||
|
||||
tracker.noteStart(kEventKey1, true, eventStartTimeNs, key1);
|
||||
@@ -260,8 +262,8 @@ TEST(OringDurationTrackerTest, TestDurationConditionChangeNested) {
|
||||
|
||||
TEST(OringDurationTrackerTest, TestPredictAnomalyTimestamp) {
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name("1");
|
||||
alert.set_id(101);
|
||||
alert.set_metric_id(1);
|
||||
alert.set_trigger_if_sum_gt(40 * NS_PER_SEC);
|
||||
alert.set_number_of_buckets(2);
|
||||
alert.set_refractory_period_secs(1);
|
||||
@@ -269,13 +271,13 @@ TEST(OringDurationTrackerTest, TestPredictAnomalyTimestamp) {
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
uint64_t bucketStartTimeNs = 10 * NS_PER_SEC;
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + NS_PER_SEC + 1;
|
||||
uint64_t bucketSizeNs = 30 * NS_PER_SEC;
|
||||
|
||||
sp<DurationAnomalyTracker> anomalyTracker = new DurationAnomalyTracker(alert, kConfigKey);
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true, bucketStartTimeNs,
|
||||
bucketSizeNs, {anomalyTracker});
|
||||
|
||||
// Nothing in the past bucket.
|
||||
@@ -322,8 +324,8 @@ TEST(OringDurationTrackerTest, TestPredictAnomalyTimestamp) {
|
||||
|
||||
TEST(OringDurationTrackerTest, TestAnomalyDetection) {
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name("1");
|
||||
alert.set_id(101);
|
||||
alert.set_metric_id(1);
|
||||
alert.set_trigger_if_sum_gt(40 * NS_PER_SEC);
|
||||
alert.set_number_of_buckets(2);
|
||||
alert.set_refractory_period_secs(1);
|
||||
@@ -331,13 +333,13 @@ TEST(OringDurationTrackerTest, TestAnomalyDetection) {
|
||||
unordered_map<HashableDimensionKey, vector<DurationBucket>> buckets;
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
ConditionKey key1;
|
||||
key1["APP_BACKGROUND"] = kConditionKey1;
|
||||
key1[StringToId("APP_BACKGROUND")] = kConditionKey1;
|
||||
uint64_t bucketStartTimeNs = 10 * NS_PER_SEC;
|
||||
uint64_t eventStartTimeNs = bucketStartTimeNs + NS_PER_SEC + 1;
|
||||
uint64_t bucketSizeNs = 30 * NS_PER_SEC;
|
||||
|
||||
sp<DurationAnomalyTracker> anomalyTracker = new DurationAnomalyTracker(alert, kConfigKey);
|
||||
OringDurationTracker tracker(kConfigKey, "metric", eventKey, wizard, 1, true /*nesting*/,
|
||||
OringDurationTracker tracker(kConfigKey, metricId, eventKey, wizard, 1, true /*nesting*/,
|
||||
bucketStartTimeNs, bucketSizeNs, {anomalyTracker});
|
||||
|
||||
tracker.noteStart(DEFAULT_DIMENSION_KEY, true, eventStartTimeNs, key1);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "src/metrics/ValueMetricProducer.h"
|
||||
#include "metrics_test_helper.h"
|
||||
#include "tests/statsd_test_util.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -34,9 +35,9 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
const ConfigKey kConfigKey(0, "test");
|
||||
const ConfigKey kConfigKey(0, 12345);
|
||||
const int tagId = 1;
|
||||
const string metricName = "test_metric";
|
||||
const int64_t metricId = 123;
|
||||
const int64_t bucketStartTimeNs = 10000000000;
|
||||
const int64_t bucketSizeNs = 60 * 1000 * 1000 * 1000LL;
|
||||
const int64_t bucket2StartTimeNs = bucketStartTimeNs + bucketSizeNs;
|
||||
@@ -48,7 +49,7 @@ const int64_t bucket4StartTimeNs = bucketStartTimeNs + 3 * bucketSizeNs;
|
||||
*/
|
||||
TEST(ValueMetricProducerTest, TestNonDimensionalEvents) {
|
||||
ValueMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_value_field(2);
|
||||
|
||||
@@ -124,10 +125,10 @@ TEST(ValueMetricProducerTest, TestNonDimensionalEvents) {
|
||||
*/
|
||||
TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
||||
ValueMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_value_field(2);
|
||||
metric.set_condition("SCREEN_ON");
|
||||
metric.set_condition(StringToId("SCREEN_ON"));
|
||||
|
||||
sp<MockConditionWizard> wizard = new NaggyMock<MockConditionWizard>();
|
||||
shared_ptr<MockStatsPullerManager> pullerManager =
|
||||
@@ -200,7 +201,7 @@ TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition) {
|
||||
|
||||
TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
||||
ValueMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_value_field(2);
|
||||
|
||||
@@ -240,14 +241,14 @@ TEST(ValueMetricProducerTest, TestPushedEventsWithoutCondition) {
|
||||
|
||||
TEST(ValueMetricProducerTest, TestAnomalyDetection) {
|
||||
Alert alert;
|
||||
alert.set_name("alert");
|
||||
alert.set_metric_name(metricName);
|
||||
alert.set_id(101);
|
||||
alert.set_metric_id(metricId);
|
||||
alert.set_trigger_if_sum_gt(130);
|
||||
alert.set_number_of_buckets(2);
|
||||
alert.set_refractory_period_secs(3);
|
||||
|
||||
ValueMetric metric;
|
||||
metric.set_name(metricName);
|
||||
metric.set_id(metricId);
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_value_field(2);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace statsd {
|
||||
AtomMatcher CreateWakelockStateChangedAtomMatcher(const string& name,
|
||||
WakelockStateChanged::State state) {
|
||||
AtomMatcher atom_matcher;
|
||||
atom_matcher.set_name(name);
|
||||
atom_matcher.set_id(StringToId(name));
|
||||
auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
|
||||
simple_atom_matcher->set_atom_id(android::util::WAKELOCK_STATE_CHANGED);
|
||||
auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
|
||||
@@ -42,7 +42,7 @@ AtomMatcher CreateReleaseWakelockAtomMatcher() {
|
||||
AtomMatcher CreateScreenStateChangedAtomMatcher(
|
||||
const string& name, ScreenStateChanged::State state) {
|
||||
AtomMatcher atom_matcher;
|
||||
atom_matcher.set_name(name);
|
||||
atom_matcher.set_id(StringToId(name));
|
||||
auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
|
||||
simple_atom_matcher->set_atom_id(android::util::SCREEN_STATE_CHANGED);
|
||||
auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
|
||||
@@ -62,7 +62,7 @@ AtomMatcher CreateScreenTurnedOffAtomMatcher() {
|
||||
AtomMatcher CreateSyncStateChangedAtomMatcher(
|
||||
const string& name, SyncStateChanged::State state) {
|
||||
AtomMatcher atom_matcher;
|
||||
atom_matcher.set_name(name);
|
||||
atom_matcher.set_id(StringToId(name));
|
||||
auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
|
||||
simple_atom_matcher->set_atom_id(android::util::SYNC_STATE_CHANGED);
|
||||
auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
|
||||
@@ -82,7 +82,7 @@ AtomMatcher CreateSyncEndAtomMatcher() {
|
||||
AtomMatcher CreateActivityForegroundStateChangedAtomMatcher(
|
||||
const string& name, ActivityForegroundStateChanged::Activity activity) {
|
||||
AtomMatcher atom_matcher;
|
||||
atom_matcher.set_name(name);
|
||||
atom_matcher.set_id(StringToId(name));
|
||||
auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
|
||||
simple_atom_matcher->set_atom_id(android::util::ACTIVITY_FOREGROUND_STATE_CHANGED);
|
||||
auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
|
||||
@@ -104,7 +104,7 @@ AtomMatcher CreateMoveToForegroundAtomMatcher() {
|
||||
AtomMatcher CreateProcessLifeCycleStateChangedAtomMatcher(
|
||||
const string& name, ProcessLifeCycleStateChanged::Event event) {
|
||||
AtomMatcher atom_matcher;
|
||||
atom_matcher.set_name(name);
|
||||
atom_matcher.set_id(StringToId(name));
|
||||
auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
|
||||
simple_atom_matcher->set_atom_id(android::util::PROCESS_LIFE_CYCLE_STATE_CHANGED);
|
||||
auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
|
||||
@@ -121,47 +121,47 @@ AtomMatcher CreateProcessCrashAtomMatcher() {
|
||||
|
||||
Predicate CreateScreenIsOnPredicate() {
|
||||
Predicate predicate;
|
||||
predicate.set_name("ScreenIsOn");
|
||||
predicate.mutable_simple_predicate()->set_start("ScreenTurnedOn");
|
||||
predicate.mutable_simple_predicate()->set_stop("ScreenTurnedOff");
|
||||
predicate.set_id(StringToId("ScreenIsOn"));
|
||||
predicate.mutable_simple_predicate()->set_start(StringToId("ScreenTurnedOn"));
|
||||
predicate.mutable_simple_predicate()->set_stop(StringToId("ScreenTurnedOff"));
|
||||
return predicate;
|
||||
}
|
||||
|
||||
Predicate CreateScreenIsOffPredicate() {
|
||||
Predicate predicate;
|
||||
predicate.set_name("ScreenIsOff");
|
||||
predicate.mutable_simple_predicate()->set_start("ScreenTurnedOff");
|
||||
predicate.mutable_simple_predicate()->set_stop("ScreenTurnedOn");
|
||||
predicate.set_id(StringToId("ScreenIsOff"));
|
||||
predicate.mutable_simple_predicate()->set_start(StringToId("ScreenTurnedOff"));
|
||||
predicate.mutable_simple_predicate()->set_stop(StringToId("ScreenTurnedOn"));
|
||||
return predicate;
|
||||
}
|
||||
|
||||
Predicate CreateHoldingWakelockPredicate() {
|
||||
Predicate predicate;
|
||||
predicate.set_name("HoldingWakelock");
|
||||
predicate.mutable_simple_predicate()->set_start("AcquireWakelock");
|
||||
predicate.mutable_simple_predicate()->set_stop("ReleaseWakelock");
|
||||
predicate.set_id(StringToId("HoldingWakelock"));
|
||||
predicate.mutable_simple_predicate()->set_start(StringToId("AcquireWakelock"));
|
||||
predicate.mutable_simple_predicate()->set_stop(StringToId("ReleaseWakelock"));
|
||||
return predicate;
|
||||
}
|
||||
|
||||
Predicate CreateIsSyncingPredicate() {
|
||||
Predicate predicate;
|
||||
predicate.set_name("IsSyncing");
|
||||
predicate.mutable_simple_predicate()->set_start("SyncStart");
|
||||
predicate.mutable_simple_predicate()->set_stop("SyncEnd");
|
||||
predicate.set_id(StringToId("IsSyncing"));
|
||||
predicate.mutable_simple_predicate()->set_start(StringToId("SyncStart"));
|
||||
predicate.mutable_simple_predicate()->set_stop(StringToId("SyncEnd"));
|
||||
return predicate;
|
||||
}
|
||||
|
||||
Predicate CreateIsInBackgroundPredicate() {
|
||||
Predicate predicate;
|
||||
predicate.set_name("IsInBackground");
|
||||
predicate.mutable_simple_predicate()->set_start("MoveToBackground");
|
||||
predicate.mutable_simple_predicate()->set_stop("MoveToForeground");
|
||||
predicate.set_id(StringToId("IsInBackground"));
|
||||
predicate.mutable_simple_predicate()->set_start(StringToId("MoveToBackground"));
|
||||
predicate.mutable_simple_predicate()->set_stop(StringToId("MoveToForeground"));
|
||||
return predicate;
|
||||
}
|
||||
|
||||
void addPredicateToPredicateCombination(const Predicate& predicate,
|
||||
Predicate* combinationPredicate) {
|
||||
combinationPredicate->mutable_combination()->add_predicate(predicate.name());
|
||||
combinationPredicate->mutable_combination()->add_predicate(predicate.id());
|
||||
}
|
||||
|
||||
FieldMatcher CreateAttributionUidDimensions(const int atomId,
|
||||
@@ -316,6 +316,9 @@ void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events) {
|
||||
});
|
||||
}
|
||||
|
||||
int64_t StringToId(const string& str) {
|
||||
return static_cast<int64_t>(std::hash<std::string>()(str));
|
||||
}
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
@@ -121,6 +121,8 @@ sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const Stat
|
||||
// Util function to sort the log events by timestamp.
|
||||
void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events);
|
||||
|
||||
int64_t StringToId(const string& str);
|
||||
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
@@ -26,7 +26,7 @@ public class DisplayProtoUtils {
|
||||
sb.append("ConfigKey: ");
|
||||
if (reports.hasConfigKey()) {
|
||||
com.android.os.StatsLog.ConfigMetricsReportList.ConfigKey key = reports.getConfigKey();
|
||||
sb.append("\tuid: ").append(key.getUid()).append(" name: ").append(key.getName())
|
||||
sb.append("\tuid: ").append(key.getUid()).append(" name: ").append(key.getId())
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DisplayProtoUtils {
|
||||
sb.append("StatsLogReport size: ").append(report.getMetricsCount()).append("\n");
|
||||
for (StatsLog.StatsLogReport log : report.getMetricsList()) {
|
||||
sb.append("\n\n");
|
||||
sb.append("metric id: ").append(log.getMetricName()).append("\n");
|
||||
sb.append("metric id: ").append(log.getMetricId()).append("\n");
|
||||
sb.append("start time:").append(getDateStr(log.getStartReportNanos())).append("\n");
|
||||
sb.append("end time:").append(getDateStr(log.getEndReportNanos())).append("\n");
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import static com.android.statsd.dogfood.DisplayProtoUtils.displayLogReport;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private final static String TAG = "StatsdDogfood";
|
||||
private final static long CONFIG_ID = 987654321;
|
||||
|
||||
|
||||
final int[] mUids = {11111111, 2222222};
|
||||
StatsManager mStatsManager;
|
||||
@@ -163,7 +165,7 @@ public class MainActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
if (mStatsManager != null) {
|
||||
byte[] data = mStatsManager.getData("fake");
|
||||
byte[] data = mStatsManager.getData(CONFIG_ID);
|
||||
if (data != null) {
|
||||
displayData(data);
|
||||
} else {
|
||||
@@ -186,7 +188,7 @@ public class MainActivity extends Activity {
|
||||
byte[] config = new byte[inputStream.available()];
|
||||
inputStream.read(config);
|
||||
if (mStatsManager != null) {
|
||||
if (mStatsManager.addConfiguration("fake",
|
||||
if (mStatsManager.addConfiguration(CONFIG_ID,
|
||||
config, getPackageName(), MainActivity.this.getClass().getName())) {
|
||||
Toast.makeText(
|
||||
MainActivity.this, "Config pushed", Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
* Creates StatsdConfig protos for loadtesting.
|
||||
*/
|
||||
public class ConfigFactory {
|
||||
public static final String CONFIG_NAME = "LOADTEST";
|
||||
public static final long CONFIG_ID = 123456789;
|
||||
|
||||
private static final String TAG = "loadtest.ConfigFactory";
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ConfigFactory {
|
||||
boolean includeDuration, boolean includeEvent, boolean includeValue,
|
||||
boolean includeGauge) {
|
||||
StatsdConfig.Builder config = StatsdConfig.newBuilder()
|
||||
.setName(CONFIG_NAME);
|
||||
.setId(CONFIG_ID);
|
||||
if (placebo) {
|
||||
replication = 0; // Config will be empty, aside from a name.
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class ConfigFactory {
|
||||
*/
|
||||
private void addEventMetric(EventMetric template, int suffix, StatsdConfig.Builder config) {
|
||||
EventMetric.Builder metric = template.toBuilder()
|
||||
.setName(template.getName() + suffix)
|
||||
.setId(template.getId() + suffix)
|
||||
.setWhat(template.getWhat() + suffix);
|
||||
if (template.hasCondition()) {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
@@ -186,7 +186,7 @@ public class ConfigFactory {
|
||||
private void addCountMetric(CountMetric template, int suffix, long bucketMillis,
|
||||
StatsdConfig.Builder config) {
|
||||
CountMetric.Builder metric = template.toBuilder()
|
||||
.setName(template.getName() + suffix)
|
||||
.setId(template.getId() + suffix)
|
||||
.setWhat(template.getWhat() + suffix);
|
||||
if (template.hasCondition()) {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
@@ -207,7 +207,7 @@ public class ConfigFactory {
|
||||
private void addDurationMetric(DurationMetric template, int suffix, long bucketMillis,
|
||||
StatsdConfig.Builder config) {
|
||||
DurationMetric.Builder metric = template.toBuilder()
|
||||
.setName(template.getName() + suffix)
|
||||
.setId(template.getId() + suffix)
|
||||
.setWhat(template.getWhat() + suffix);
|
||||
if (template.hasCondition()) {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
@@ -228,7 +228,7 @@ public class ConfigFactory {
|
||||
private void addGaugeMetric(GaugeMetric template, int suffix, long bucketMillis,
|
||||
StatsdConfig.Builder config) {
|
||||
GaugeMetric.Builder metric = template.toBuilder()
|
||||
.setName(template.getName() + suffix)
|
||||
.setId(template.getId() + suffix)
|
||||
.setWhat(template.getWhat() + suffix);
|
||||
if (template.hasCondition()) {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
@@ -249,7 +249,7 @@ public class ConfigFactory {
|
||||
private void addValueMetric(ValueMetric template, int suffix, long bucketMillis,
|
||||
StatsdConfig.Builder config) {
|
||||
ValueMetric.Builder metric = template.toBuilder()
|
||||
.setName(template.getName() + suffix)
|
||||
.setId(template.getId() + suffix)
|
||||
.setWhat(template.getWhat() + suffix);
|
||||
if (template.hasCondition()) {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
@@ -269,11 +269,11 @@ public class ConfigFactory {
|
||||
*/
|
||||
private void addPredicate(Predicate template, int suffix, StatsdConfig.Builder config) {
|
||||
Predicate.Builder predicate = template.toBuilder()
|
||||
.setName(template.getName() + suffix);
|
||||
.setId(template.getId() + suffix);
|
||||
if (template.hasCombination()) {
|
||||
Predicate.Combination.Builder cb = template.getCombination().toBuilder()
|
||||
.clearPredicate();
|
||||
for (String child : template.getCombination().getPredicateList()) {
|
||||
for (long child : template.getCombination().getPredicateList()) {
|
||||
cb.addPredicate(child + suffix);
|
||||
}
|
||||
predicate.setCombination(cb.build());
|
||||
@@ -296,11 +296,11 @@ public class ConfigFactory {
|
||||
*/
|
||||
private void addMatcher(AtomMatcher template, int suffix, StatsdConfig.Builder config) {
|
||||
AtomMatcher.Builder matcher = template.toBuilder()
|
||||
.setName(template.getName() + suffix);
|
||||
.setId(template.getId() + suffix);
|
||||
if (template.hasCombination()) {
|
||||
AtomMatcher.Combination.Builder cb = template.getCombination().toBuilder()
|
||||
.clearMatcher();
|
||||
for (String child : template.getCombination().getMatcherList()) {
|
||||
for (long child : template.getCombination().getMatcherList()) {
|
||||
cb.addMatcher(child + suffix);
|
||||
}
|
||||
matcher.setCombination(cb);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DisplayProtoUtils {
|
||||
sb.append("ConfigKey: ");
|
||||
if (reports.hasConfigKey()) {
|
||||
com.android.os.StatsLog.ConfigMetricsReportList.ConfigKey key = reports.getConfigKey();
|
||||
sb.append("\tuid: ").append(key.getUid()).append(" name: ").append(key.getName())
|
||||
sb.append("\tuid: ").append(key.getUid()).append(" id: ").append(key.getId())
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DisplayProtoUtils {
|
||||
sb.append("StatsLogReport size: ").append(report.getMetricsCount()).append("\n");
|
||||
for (StatsLog.StatsLogReport log : report.getMetricsList()) {
|
||||
sb.append("\n\n");
|
||||
sb.append("metric id: ").append(log.getMetricName()).append("\n");
|
||||
sb.append("metric id: ").append(log.getMetricId()).append("\n");
|
||||
sb.append("start time:").append(getDateStr(log.getStartReportNanos())).append("\n");
|
||||
sb.append("end time:").append(getDateStr(log.getEndReportNanos())).append("\n");
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ public class LoadtestActivity extends Activity {
|
||||
return null;
|
||||
}
|
||||
if (mStatsManager != null) {
|
||||
byte[] data = mStatsManager.getData(ConfigFactory.CONFIG_NAME);
|
||||
byte[] data = mStatsManager.getData(ConfigFactory.CONFIG_ID);
|
||||
if (data != null) {
|
||||
ConfigMetricsReportList reports = null;
|
||||
try {
|
||||
@@ -453,7 +453,7 @@ public class LoadtestActivity extends Activity {
|
||||
// TODO: Clear all configs instead of specific ones.
|
||||
if (mStatsManager != null) {
|
||||
if (mStarted) {
|
||||
if (!mStatsManager.removeConfiguration(ConfigFactory.CONFIG_NAME)) {
|
||||
if (!mStatsManager.removeConfiguration(ConfigFactory.CONFIG_ID)) {
|
||||
Log.d(TAG, "Removed loadtest statsd configs.");
|
||||
} else {
|
||||
Log.d(TAG, "Failed to remove loadtest configs.");
|
||||
@@ -464,7 +464,7 @@ public class LoadtestActivity extends Activity {
|
||||
|
||||
private boolean setConfig(byte[] config) {
|
||||
if (mStatsManager != null) {
|
||||
if (mStatsManager.addConfiguration(ConfigFactory.CONFIG_NAME,
|
||||
if (mStatsManager.addConfiguration(ConfigFactory.CONFIG_ID,
|
||||
config, getPackageName(), LoadtestActivity.this.getClass().getName())) {
|
||||
Log.d(TAG, "Config pushed to statsd");
|
||||
return true;
|
||||
|
||||
@@ -59,18 +59,8 @@ public class ValidationRecorder extends PerfDataRecorder {
|
||||
Log.d(TAG, "GOT DATA");
|
||||
for (ConfigMetricsReport report : reports) {
|
||||
for (StatsLogReport logReport : report.getMetricsList()) {
|
||||
if (!logReport.hasMetricName()) {
|
||||
if (!logReport.hasMetricId()) {
|
||||
Log.e(TAG, "Metric missing name.");
|
||||
continue;
|
||||
}
|
||||
String metricName = logReport.getMetricName();
|
||||
if (metricName.startsWith("EVENT_BATTERY_LEVEL_CHANGES_WHILE_SCREEN_IS_ON_")) {
|
||||
validateEventBatteryLevelChangesWhileScreenIsOn(logReport);
|
||||
continue;
|
||||
}
|
||||
if (metricName.startsWith("EVENT_BATTERY_LEVEL_CHANGES_")) {
|
||||
validateEventBatteryLevelChanges(logReport);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +68,7 @@ public class ValidationRecorder extends PerfDataRecorder {
|
||||
}
|
||||
|
||||
private void validateEventBatteryLevelChanges(StatsLogReport logReport) {
|
||||
Log.d(TAG, "Validating " + logReport.getMetricName());
|
||||
Log.d(TAG, "Validating " + logReport.getMetricId());
|
||||
if (logReport.hasEventMetrics()) {
|
||||
Log.d(TAG, "Num events captured: " + logReport.getEventMetrics().getDataCount());
|
||||
for (EventMetricData data : logReport.getEventMetrics().getDataList()) {
|
||||
@@ -90,6 +80,6 @@ public class ValidationRecorder extends PerfDataRecorder {
|
||||
}
|
||||
|
||||
private void validateEventBatteryLevelChangesWhileScreenIsOn(StatsLogReport logReport) {
|
||||
Log.d(TAG, "Validating " + logReport.getMetricName());
|
||||
Log.d(TAG, "Validating " + logReport.getMetricId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ interface IStatsManager {
|
||||
* Fetches data for the specified configuration key. Returns a byte array representing proto
|
||||
* wire-encoded of ConfigMetricsReportList.
|
||||
*/
|
||||
byte[] getData(in String key);
|
||||
byte[] getData(in long key);
|
||||
|
||||
/**
|
||||
* Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
|
||||
@@ -86,7 +86,7 @@ interface IStatsManager {
|
||||
*
|
||||
* Returns if this configuration was correctly registered.
|
||||
*/
|
||||
boolean addConfiguration(in String configKey, in byte[] config, in String pkg, in String cls);
|
||||
boolean addConfiguration(in long configKey, in byte[] config, in String pkg, in String cls);
|
||||
|
||||
/**
|
||||
* Removes the configuration with the matching config key. No-op if this config key does not
|
||||
@@ -94,5 +94,5 @@ interface IStatsManager {
|
||||
*
|
||||
* Returns if this configuration key was removed.
|
||||
*/
|
||||
boolean removeConfiguration(in String configKey);
|
||||
boolean removeConfiguration(in long configKey);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class StatsManager {
|
||||
* @return true if successful
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.DUMP)
|
||||
public boolean addConfiguration(String configKey, byte[] config, String pkg, String cls) {
|
||||
public boolean addConfiguration(long configKey, byte[] config, String pkg, String cls) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
IStatsManager service = getIStatsManagerLocked();
|
||||
@@ -76,7 +76,7 @@ public final class StatsManager {
|
||||
* @return true if successful
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.DUMP)
|
||||
public boolean removeConfiguration(String configKey) {
|
||||
public boolean removeConfiguration(long configKey) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
IStatsManager service = getIStatsManagerLocked();
|
||||
@@ -100,7 +100,7 @@ public final class StatsManager {
|
||||
* @return Serialized ConfigMetricsReportList proto. Returns null on failure.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.DUMP)
|
||||
public byte[] getData(String configKey) {
|
||||
public byte[] getData(long configKey) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
IStatsManager service = getIStatsManagerLocked();
|
||||
|
||||
Reference in New Issue
Block a user