Loading cmds/statsd/src/FieldValue.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "FieldValue.h" #include "HashableDimensionKey.h" #include "math.h" #include "statslog.h" namespace android { namespace os { Loading Loading @@ -122,6 +123,24 @@ bool isAttributionUidField(const FieldValue& value) { return false; } int32_t getUidIfExists(const FieldValue& value) { bool isUid = false; // the field is uid field if the field is the uid field in attribution node or marked as // is_uid in atoms.proto if (isAttributionUidField(value)) { isUid = true; } else { auto it = android::util::AtomsInfo::kAtomsWithUidField.find(value.mField.getTag()); if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) { int uidField = it->second; // uidField is the field number in proto isUid = value.mField.getDepth() == 0 && value.mField.getPosAtDepth(0) == uidField && value.mValue.getType() == INT; } } return isUid ? value.mValue.int_value : -1; } bool isAttributionUidField(const Field& field, const Value& value) { int f = field.getField() & 0xff007f; if (f == 0x10001 && value.getType() == INT) { Loading cmds/statsd/src/FieldValue.h +3 −0 Original line number Diff line number Diff line Loading @@ -386,6 +386,9 @@ bool HasPositionALL(const FieldMatcher& matcher); bool isAttributionUidField(const FieldValue& value); /* returns uid if the field is uid field, or -1 if the field is not a uid field */ int getUidIfExists(const FieldValue& value); void translateFieldMatcher(const FieldMatcher& matcher, std::vector<Matcher>* output); bool isAttributionUidField(const Field& field, const Value& value); Loading cmds/statsd/src/StatsService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ StatsService::StatsService(const sp<Looper>& handlerLooper) } })) { mUidMap = new UidMap(); mUidMap = UidMap::getInstance(); mPullerManager = new StatsPullerManager(); StatsPuller::SetUidMap(mUidMap); mConfigManager = new ConfigManager(); Loading cmds/statsd/src/anomaly/AlarmTracker.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -78,8 +78,8 @@ void AlarmTracker::informAlarmsFired( } if (!mSubscriptions.empty()) { VLOG("AlarmTracker triggers the subscribers."); triggerSubscribers(mAlarmConfig.id(), DEFAULT_METRIC_DIMENSION_KEY, mConfigKey, mSubscriptions); triggerSubscribers(mAlarmConfig.id(), 0 /*metricId N/A*/, DEFAULT_METRIC_DIMENSION_KEY, 0 /* metricValue N/A */, mConfigKey, mSubscriptions); } firedAlarms.erase(mInternalAlarm); mAlarmSec = findNextAlarmSec((timestampNs-1) / NS_PER_SEC + 1); // round up Loading cmds/statsd/src/anomaly/AnomalyTracker.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -207,7 +207,8 @@ bool AnomalyTracker::detectAnomaly(const int64_t& currentBucketNum, getSumOverPastBuckets(key) + currentBucketValue > mAlert.trigger_if_sum_gt(); } void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDimensionKey& key) { void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, int64_t metricId, const MetricDimensionKey& key, int64_t metricValue) { // TODO(b/110563466): Why receive timestamp? RefractoryPeriod should always be based on // real time right now. if (isInRefractoryPeriod(timestampNs, key)) { Loading @@ -225,7 +226,7 @@ void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDime if (!mSubscriptions.empty()) { ALOGI("An anomaly (%lld) %s has occurred! Informing subscribers.", mAlert.id(), key.toString().c_str()); informSubscribers(key); informSubscribers(key, metricId, metricValue); } else { ALOGI("An anomaly has occurred! (But no subscriber for that alert.)"); } Loading @@ -238,11 +239,11 @@ void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDime } void AnomalyTracker::detectAndDeclareAnomaly(const int64_t& timestampNs, const int64_t& currBucketNum, const int64_t& currBucketNum, int64_t metricId, const MetricDimensionKey& key, const int64_t& currentBucketValue) { if (detectAnomaly(currBucketNum, key, currentBucketValue)) { declareAnomaly(timestampNs, key); declareAnomaly(timestampNs, metricId, key, currentBucketValue); } } Loading @@ -255,8 +256,9 @@ bool AnomalyTracker::isInRefractoryPeriod(const int64_t& timestampNs, return false; } void AnomalyTracker::informSubscribers(const MetricDimensionKey& key) { triggerSubscribers(mAlert.id(), key, mConfigKey, mSubscriptions); void AnomalyTracker::informSubscribers(const MetricDimensionKey& key, int64_t metric_id, int64_t metricValue) { triggerSubscribers(mAlert.id(), metric_id, key, metricValue, mConfigKey, mSubscriptions); } } // namespace statsd Loading Loading
cmds/statsd/src/FieldValue.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "FieldValue.h" #include "HashableDimensionKey.h" #include "math.h" #include "statslog.h" namespace android { namespace os { Loading Loading @@ -122,6 +123,24 @@ bool isAttributionUidField(const FieldValue& value) { return false; } int32_t getUidIfExists(const FieldValue& value) { bool isUid = false; // the field is uid field if the field is the uid field in attribution node or marked as // is_uid in atoms.proto if (isAttributionUidField(value)) { isUid = true; } else { auto it = android::util::AtomsInfo::kAtomsWithUidField.find(value.mField.getTag()); if (it != android::util::AtomsInfo::kAtomsWithUidField.end()) { int uidField = it->second; // uidField is the field number in proto isUid = value.mField.getDepth() == 0 && value.mField.getPosAtDepth(0) == uidField && value.mValue.getType() == INT; } } return isUid ? value.mValue.int_value : -1; } bool isAttributionUidField(const Field& field, const Value& value) { int f = field.getField() & 0xff007f; if (f == 0x10001 && value.getType() == INT) { Loading
cmds/statsd/src/FieldValue.h +3 −0 Original line number Diff line number Diff line Loading @@ -386,6 +386,9 @@ bool HasPositionALL(const FieldMatcher& matcher); bool isAttributionUidField(const FieldValue& value); /* returns uid if the field is uid field, or -1 if the field is not a uid field */ int getUidIfExists(const FieldValue& value); void translateFieldMatcher(const FieldMatcher& matcher, std::vector<Matcher>* output); bool isAttributionUidField(const Field& field, const Value& value); Loading
cmds/statsd/src/StatsService.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ StatsService::StatsService(const sp<Looper>& handlerLooper) } })) { mUidMap = new UidMap(); mUidMap = UidMap::getInstance(); mPullerManager = new StatsPullerManager(); StatsPuller::SetUidMap(mUidMap); mConfigManager = new ConfigManager(); Loading
cmds/statsd/src/anomaly/AlarmTracker.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -78,8 +78,8 @@ void AlarmTracker::informAlarmsFired( } if (!mSubscriptions.empty()) { VLOG("AlarmTracker triggers the subscribers."); triggerSubscribers(mAlarmConfig.id(), DEFAULT_METRIC_DIMENSION_KEY, mConfigKey, mSubscriptions); triggerSubscribers(mAlarmConfig.id(), 0 /*metricId N/A*/, DEFAULT_METRIC_DIMENSION_KEY, 0 /* metricValue N/A */, mConfigKey, mSubscriptions); } firedAlarms.erase(mInternalAlarm); mAlarmSec = findNextAlarmSec((timestampNs-1) / NS_PER_SEC + 1); // round up Loading
cmds/statsd/src/anomaly/AnomalyTracker.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -207,7 +207,8 @@ bool AnomalyTracker::detectAnomaly(const int64_t& currentBucketNum, getSumOverPastBuckets(key) + currentBucketValue > mAlert.trigger_if_sum_gt(); } void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDimensionKey& key) { void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, int64_t metricId, const MetricDimensionKey& key, int64_t metricValue) { // TODO(b/110563466): Why receive timestamp? RefractoryPeriod should always be based on // real time right now. if (isInRefractoryPeriod(timestampNs, key)) { Loading @@ -225,7 +226,7 @@ void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDime if (!mSubscriptions.empty()) { ALOGI("An anomaly (%lld) %s has occurred! Informing subscribers.", mAlert.id(), key.toString().c_str()); informSubscribers(key); informSubscribers(key, metricId, metricValue); } else { ALOGI("An anomaly has occurred! (But no subscriber for that alert.)"); } Loading @@ -238,11 +239,11 @@ void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, const MetricDime } void AnomalyTracker::detectAndDeclareAnomaly(const int64_t& timestampNs, const int64_t& currBucketNum, const int64_t& currBucketNum, int64_t metricId, const MetricDimensionKey& key, const int64_t& currentBucketValue) { if (detectAnomaly(currBucketNum, key, currentBucketValue)) { declareAnomaly(timestampNs, key); declareAnomaly(timestampNs, metricId, key, currentBucketValue); } } Loading @@ -255,8 +256,9 @@ bool AnomalyTracker::isInRefractoryPeriod(const int64_t& timestampNs, return false; } void AnomalyTracker::informSubscribers(const MetricDimensionKey& key) { triggerSubscribers(mAlert.id(), key, mConfigKey, mSubscriptions); void AnomalyTracker::informSubscribers(const MetricDimensionKey& key, int64_t metric_id, int64_t metricValue) { triggerSubscribers(mAlert.id(), metric_id, key, metricValue, mConfigKey, mSubscriptions); } } // namespace statsd Loading