Rename EventConditionLink as MetricConditionLink in statsd_config.proto.
Test: Ran statsd_test and cts tests. Change-Id: Ia9a38892854443aa4f17d800a075860fcf874652
This commit is contained in:
@@ -24,7 +24,7 @@ namespace android {
|
||||
namespace os {
|
||||
namespace statsd {
|
||||
|
||||
// Held by MetricProducer, to query a condition state with input defined in EventConditionLink.
|
||||
// Held by MetricProducer, to query a condition state with input defined in MetricConditionLink.
|
||||
class ConditionWizard : public virtual android::RefBase {
|
||||
public:
|
||||
ConditionWizard(){}; // for testing
|
||||
|
||||
@@ -94,17 +94,17 @@ ConditionState evaluateCombinationCondition(const std::vector<int>& children,
|
||||
}
|
||||
|
||||
HashableDimensionKey getDimensionKeyForCondition(const LogEvent& event,
|
||||
const EventConditionLink& link) {
|
||||
const MetricConditionLink& link) {
|
||||
vector<KeyMatcher> eventKey;
|
||||
eventKey.reserve(link.key_in_main().size());
|
||||
eventKey.reserve(link.key_in_what().size());
|
||||
|
||||
for (const auto& key : link.key_in_main()) {
|
||||
for (const auto& key : link.key_in_what()) {
|
||||
eventKey.push_back(key);
|
||||
}
|
||||
|
||||
vector<KeyValuePair> dimensionKey = getDimensionKey(event, eventKey);
|
||||
|
||||
for (int i = 0; i < link.key_in_main_size(); i++) {
|
||||
for (int i = 0; i < link.key_in_what_size(); i++) {
|
||||
auto& kv = dimensionKey[i];
|
||||
kv.set_key(link.key_in_condition(i).key());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ ConditionState evaluateCombinationCondition(const std::vector<int>& children,
|
||||
const std::vector<ConditionState>& conditionCache);
|
||||
|
||||
HashableDimensionKey getDimensionKeyForCondition(const LogEvent& event,
|
||||
const EventConditionLink& link);
|
||||
const MetricConditionLink& link);
|
||||
} // namespace statsd
|
||||
} // namespace os
|
||||
} // namespace android
|
||||
|
||||
@@ -272,9 +272,9 @@ StatsdConfig build_fake_config() {
|
||||
keyMatcher = metric->add_dimension();
|
||||
keyMatcher->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
metric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
EventConditionLink* link = metric->add_links();
|
||||
MetricConditionLink* link = metric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_what()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
|
||||
|
||||
// Duration of an app holding any wl, while screen on and app in background, slice by uid
|
||||
@@ -288,7 +288,7 @@ StatsdConfig build_fake_config() {
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_what()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
|
||||
|
||||
// max Duration of an app holding any wl, while screen on and app in background, slice by uid
|
||||
@@ -302,7 +302,7 @@ StatsdConfig build_fake_config() {
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_what()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
|
||||
|
||||
// Duration of an app holding any wl, while screen on and app in background
|
||||
@@ -314,7 +314,7 @@ StatsdConfig build_fake_config() {
|
||||
durationMetric->set_condition("APP_IS_BACKGROUND_AND_SCREEN_ON");
|
||||
link = durationMetric->add_links();
|
||||
link->set_condition("APP_IS_BACKGROUND");
|
||||
link->add_key_in_main()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_what()->set_key(WAKE_LOCK_UID_KEY_ID);
|
||||
link->add_key_in_condition()->set_key(APP_USAGE_UID_KEY_ID);
|
||||
|
||||
// Duration of screen on time.
|
||||
|
||||
@@ -137,7 +137,7 @@ protected:
|
||||
// that StatsLogReport wants.
|
||||
std::unordered_map<HashableDimensionKey, std::vector<KeyValuePair>> mDimensionKeyMap;
|
||||
|
||||
std::vector<EventConditionLink> mConditionLinks;
|
||||
std::vector<MetricConditionLink> mConditionLinks;
|
||||
|
||||
std::vector<sp<AnomalyTracker>> mAnomalyTrackers;
|
||||
|
||||
@@ -149,7 +149,7 @@ protected:
|
||||
* [eventKey]: the extracted dimension key for the final output. if the metric doesn't have
|
||||
* dimensions, it will be DEFAULT_DIMENSION_KEY
|
||||
* [conditionKey]: the keys of conditions which should be used to query the condition for this
|
||||
* target event (from EventConditionLink). This is passed to individual metrics
|
||||
* target event (from MetricConditionLink). This is passed to individual metrics
|
||||
* because DurationMetric needs it to be cached.
|
||||
* [condition]: whether condition is met. If condition is sliced, this is the result coming from
|
||||
* query with ConditionWizard; If condition is not sliced, this is the
|
||||
|
||||
@@ -64,7 +64,7 @@ bool handleMetricWithLogTrackers(const string what, const int metricIndex,
|
||||
bool handleMetricWithConditions(
|
||||
const string condition, const int metricIndex,
|
||||
const unordered_map<string, int>& conditionTrackerMap,
|
||||
const ::google::protobuf::RepeatedPtrField<::android::os::statsd::EventConditionLink>&
|
||||
const ::google::protobuf::RepeatedPtrField<::android::os::statsd::MetricConditionLink>&
|
||||
links,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers, int& conditionIndex,
|
||||
unordered_map<int, std::vector<int>>& conditionToMetricMap) {
|
||||
@@ -232,7 +232,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
} else {
|
||||
if (metric.links_size() > 0) {
|
||||
ALOGW("metrics has a EventConditionLink but doesn't have a condition");
|
||||
ALOGW("metrics has a MetricConditionLink but doesn't have a condition");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
} else {
|
||||
if (metric.links_size() > 0) {
|
||||
ALOGW("metrics has a EventConditionLink but doesn't have a condition");
|
||||
ALOGW("metrics has a MetricConditionLink but doesn't have a condition");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -340,7 +340,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
} else {
|
||||
if (metric.links_size() > 0) {
|
||||
ALOGW("metrics has a EventConditionLink but doesn't have a condition");
|
||||
ALOGW("metrics has a MetricConditionLink but doesn't have a condition");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -390,7 +390,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
} else {
|
||||
if (metric.links_size() > 0) {
|
||||
ALOGW("metrics has a EventConditionLink but doesn't have a condition");
|
||||
ALOGW("metrics has a MetricConditionLink but doesn't have a condition");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -439,7 +439,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
|
||||
}
|
||||
} else {
|
||||
if (metric.links_size() > 0) {
|
||||
ALOGW("metrics has a EventConditionLink but doesn't have a condition");
|
||||
ALOGW("metrics has a MetricConditionLink but doesn't have a condition");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ bool initConditions(const ConfigKey& key, const StatsdConfig& config,
|
||||
std::unordered_map<std::string, int>& conditionTrackerMap,
|
||||
std::vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
|
||||
std::unordered_map<int, std::vector<EventConditionLink>>& eventConditionLinks);
|
||||
std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks);
|
||||
|
||||
// Initialize MetricProducers.
|
||||
// input:
|
||||
@@ -79,7 +79,7 @@ bool initMetrics(
|
||||
const ConfigKey& key, const StatsdConfig& config,
|
||||
const std::unordered_map<std::string, int>& logTrackerMap,
|
||||
const std::unordered_map<std::string, int>& conditionTrackerMap,
|
||||
const std::unordered_map<int, std::vector<EventConditionLink>>& eventConditionLinks,
|
||||
const std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks,
|
||||
const vector<sp<LogMatchingTracker>>& allAtomMatchers,
|
||||
vector<sp<ConditionTracker>>& allConditionTrackers,
|
||||
std::vector<sp<MetricProducer>>& allMetricProducers,
|
||||
|
||||
@@ -112,10 +112,10 @@ message Bucket {
|
||||
optional int64 bucket_size_millis = 1;
|
||||
}
|
||||
|
||||
message EventConditionLink {
|
||||
message MetricConditionLink {
|
||||
optional string condition = 1;
|
||||
|
||||
repeated KeyMatcher key_in_main = 2;
|
||||
repeated KeyMatcher key_in_what = 2;
|
||||
|
||||
repeated KeyMatcher key_in_condition = 3;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ message EventMetric {
|
||||
|
||||
optional string condition = 3;
|
||||
|
||||
repeated EventConditionLink links = 4;
|
||||
repeated MetricConditionLink links = 4;
|
||||
}
|
||||
|
||||
message CountMetric {
|
||||
@@ -141,7 +141,7 @@ message CountMetric {
|
||||
|
||||
optional Bucket bucket = 5;
|
||||
|
||||
repeated EventConditionLink links = 6;
|
||||
repeated MetricConditionLink links = 6;
|
||||
}
|
||||
|
||||
message DurationMetric {
|
||||
@@ -151,7 +151,7 @@ message DurationMetric {
|
||||
|
||||
optional string condition = 3;
|
||||
|
||||
repeated EventConditionLink links = 4;
|
||||
repeated MetricConditionLink links = 4;
|
||||
|
||||
enum AggregationType {
|
||||
SUM = 1;
|
||||
@@ -178,7 +178,7 @@ message GaugeMetric {
|
||||
|
||||
optional Bucket bucket = 6;
|
||||
|
||||
repeated EventConditionLink links = 7;
|
||||
repeated MetricConditionLink links = 7;
|
||||
}
|
||||
|
||||
message ValueMetric {
|
||||
@@ -194,7 +194,7 @@ message ValueMetric {
|
||||
|
||||
optional Bucket bucket = 6;
|
||||
|
||||
repeated EventConditionLink links = 7;
|
||||
repeated MetricConditionLink links = 7;
|
||||
|
||||
enum AggregationType { SUM = 1; }
|
||||
optional AggregationType aggregation_type = 8 [default = SUM];
|
||||
|
||||
@@ -141,9 +141,9 @@ TEST(CountMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
metric.set_name("1");
|
||||
metric.mutable_bucket()->set_bucket_size_millis(bucketSizeNs / 1000000);
|
||||
metric.set_condition("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON");
|
||||
EventConditionLink* link = metric.add_links();
|
||||
MetricConditionLink* link = metric.add_links();
|
||||
link->set_condition("APP_IN_BACKGROUND_PER_UID");
|
||||
link->add_key_in_main()->set_key(1);
|
||||
link->add_key_in_what()->set_key(1);
|
||||
link->add_key_in_condition()->set_key(2);
|
||||
|
||||
LogEvent event1(1, bucketStartTimeNs + 1);
|
||||
|
||||
@@ -91,9 +91,9 @@ TEST(EventMetricProducerTest, TestEventsWithSlicedCondition) {
|
||||
EventMetric metric;
|
||||
metric.set_name("1");
|
||||
metric.set_condition("APP_IN_BACKGROUND_PER_UID_AND_SCREEN_ON");
|
||||
EventConditionLink* link = metric.add_links();
|
||||
MetricConditionLink* link = metric.add_links();
|
||||
link->set_condition("APP_IN_BACKGROUND_PER_UID");
|
||||
link->add_key_in_main()->set_key(1);
|
||||
link->add_key_in_what()->set_key(1);
|
||||
link->add_key_in_condition()->set_key(2);
|
||||
|
||||
LogEvent event1(1, bucketStartTimeNs + 1);
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.android.internal.os.StatsdConfigProto.Bucket;
|
||||
import com.android.internal.os.StatsdConfigProto.Predicate;
|
||||
import com.android.internal.os.StatsdConfigProto.CountMetric;
|
||||
import com.android.internal.os.StatsdConfigProto.DurationMetric;
|
||||
import com.android.internal.os.StatsdConfigProto.EventConditionLink;
|
||||
import com.android.internal.os.StatsdConfigProto.MetricConditionLink;
|
||||
import com.android.internal.os.StatsdConfigProto.EventMetric;
|
||||
import com.android.internal.os.StatsdConfigProto.GaugeMetric;
|
||||
import com.android.internal.os.StatsdConfigProto.ValueMetric;
|
||||
@@ -130,13 +130,13 @@ public class ConfigFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link EventConditionLink}s that are identical to the one passed to this method,
|
||||
* Creates {@link MetricConditionLink}s that are identical to the one passed to this method,
|
||||
* except that the names are appended with the provided suffix.
|
||||
*/
|
||||
private List<EventConditionLink> getLinks(
|
||||
List<EventConditionLink> links, int suffix) {
|
||||
List<EventConditionLink> newLinks = new ArrayList();
|
||||
for (EventConditionLink link : links) {
|
||||
private List<MetricConditionLink> getLinks(
|
||||
List<MetricConditionLink> links, int suffix) {
|
||||
List<MetricConditionLink> newLinks = new ArrayList();
|
||||
for (MetricConditionLink link : links) {
|
||||
newLinks.add(link.toBuilder()
|
||||
.setCondition(link.getCondition() + suffix)
|
||||
.build());
|
||||
@@ -156,7 +156,7 @@ public class ConfigFactory {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
}
|
||||
if (template.getLinksCount() > 0) {
|
||||
List<EventConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
List<MetricConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
metric.clearLinks();
|
||||
metric.addAllLinks(links);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class ConfigFactory {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
}
|
||||
if (template.getLinksCount() > 0) {
|
||||
List<EventConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
List<MetricConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
metric.clearLinks();
|
||||
metric.addAllLinks(links);
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class ConfigFactory {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
}
|
||||
if (template.getLinksCount() > 0) {
|
||||
List<EventConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
List<MetricConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
metric.clearLinks();
|
||||
metric.addAllLinks(links);
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public class ConfigFactory {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
}
|
||||
if (template.getLinksCount() > 0) {
|
||||
List<EventConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
List<MetricConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
metric.clearLinks();
|
||||
metric.addAllLinks(links);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ public class ConfigFactory {
|
||||
metric.setCondition(template.getCondition() + suffix);
|
||||
}
|
||||
if (template.getLinksCount() > 0) {
|
||||
List<EventConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
List<MetricConditionLink> links = getLinks(template.getLinksList(), suffix);
|
||||
metric.clearLinks();
|
||||
metric.addAllLinks(links);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user