summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stefan Lafon <stlafon@google.com> 2017-09-27 20:24:15 -0700
committer Yao Chen <yaochen@google.com> 2017-09-28 14:38:31 -0700
commitcdb1a0ed959818b0c3822e114c0456833769bade (patch)
tree53db2ce680fd3a466afafbeae14714b70a1cdb3a
parent353a02a5af566e528c49dc18600d63b764d899eb (diff)
Check in new protos and constants.
Test: Started statsd and verified it outputs data. Also ran statsd tests. Change-Id: I2a438b2ddfcb1576e21acb6159bea607fed7caaa
-rw-r--r--cmds/statsd/Android.mk2
-rw-r--r--cmds/statsd/src/DropboxReader.cpp12
-rw-r--r--cmds/statsd/src/StatsLogProcessor.h3
-rw-r--r--cmds/statsd/src/parse_util.cpp44
-rw-r--r--cmds/statsd/src/stats_events.proto57
-rw-r--r--cmds/statsd/src/stats_log.proto22
-rw-r--r--cmds/statsd/src/statsd_config.proto29
-rw-r--r--cmds/statsd/tests/LogEntryMatcher_test.cpp195
-rw-r--r--core/java/android/util/StatsLogKey.java48
-rw-r--r--core/java/android/util/StatsLogTag.java (renamed from cmds/statsd/src/stats_constants.proto)29
-rw-r--r--core/java/android/util/StatsLogValue.java54
11 files changed, 330 insertions, 165 deletions
diff --git a/cmds/statsd/Android.mk b/cmds/statsd/Android.mk
index 3f120166d974..7cf5246b6830 100644
--- a/cmds/statsd/Android.mk
+++ b/cmds/statsd/Android.mk
@@ -52,7 +52,6 @@ LOCAL_SRC_FILES := \
src/StatsLogProcessor.cpp \
src/stats_log.proto \
src/statsd_config.proto \
- src/stats_constants.proto \
src/DropboxReader.cpp \
src/matchers/LogEntryMatcherManager.cpp \
@@ -122,7 +121,6 @@ LOCAL_CFLAGS += \
LOCAL_SRC_FILES := \
src/stats_log.proto \
src/statsd_config.proto \
- src/stats_constants.proto \
../../core/java/android/os/IStatsCompanionService.aidl \
../../core/java/android/os/IStatsManager.aidl \
src/StatsService.cpp \
diff --git a/cmds/statsd/src/DropboxReader.cpp b/cmds/statsd/src/DropboxReader.cpp
index 27a01c8c1a5f..430e7afc7b9b 100644
--- a/cmds/statsd/src/DropboxReader.cpp
+++ b/cmds/statsd/src/DropboxReader.cpp
@@ -105,16 +105,12 @@ bool DropboxReader::parseFromFile(const unique_fd& fd, StatsLogReport& logReport
}
void DropboxReader::printLog(FILE* out, const StatsLogReport& logReport) {
- fprintf(out, "start_time_msec=%lld, end_time_msec=%lld, ", logReport.start_report_millis(),
- logReport.end_report_millis());
+ fprintf(out, "start_time_ns=%lld, end_time_ns=%lld, ", logReport.start_report_nanos(),
+ logReport.end_report_nanos());
for (int i = 0; i < logReport.event_metrics().data_size(); i++) {
EventMetricData eventMetricData = logReport.event_metrics().data(i);
- for (int j = 0; j < eventMetricData.key_value_pair_size(); j++) {
- fprintf(out, "key=%d, ", eventMetricData.key_value_pair(j).key());
- fprintf(out, "value_str=%s ", eventMetricData.key_value_pair(j).value_str().c_str());
- fprintf(out, "value_int=%lld ", eventMetricData.key_value_pair(j).value_int());
- fprintf(out, "value_float=%f ", eventMetricData.key_value_pair(j).value_float());
- }
+ // TODO: Pretty-print the proto.
+ // fprintf(out, "EventMetricData=%s", eventMetricData.SerializeAsString().c_str());
}
fprintf(out, "\n");
}
diff --git a/cmds/statsd/src/StatsLogProcessor.h b/cmds/statsd/src/StatsLogProcessor.h
index 1e525c07216c..4546d33fa2a1 100644
--- a/cmds/statsd/src/StatsLogProcessor.h
+++ b/cmds/statsd/src/StatsLogProcessor.h
@@ -16,6 +16,7 @@
#ifndef STATS_LOG_PROCESSOR_H
#define STATS_LOG_PROCESSOR_H
+#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
#include "parse_util.h"
#include <unordered_map>
@@ -47,7 +48,7 @@ private:
DropboxWriter m_dropbox_writer;
/**
- * Configs that have been specified, keyed by the source. This allows us to over-ride the config
+ * Configs that have been specified, keyed by the source. This allows us to override the config
* from a source later.
*/
std::unordered_map<int, StatsdConfig> m_configs;
diff --git a/cmds/statsd/src/parse_util.cpp b/cmds/statsd/src/parse_util.cpp
index 6464ee166dc9..408a65c77ed2 100644
--- a/cmds/statsd/src/parse_util.cpp
+++ b/cmds/statsd/src/parse_util.cpp
@@ -17,13 +17,8 @@
#include <log/log_event_list.h>
#include <parse_util.h>
-using android::os::statsd::EVENT_TIMESTAMP;
using android::os::statsd::EventMetricData;
-using android::os::statsd::KeyId;
-using android::os::statsd::KeyId_IsValid;
using android::os::statsd::KeyValuePair;
-using android::os::statsd::TagId;
-using android::os::statsd::TagId_IsValid;
static inline uint32_t get4LE(const char* src) {
return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
@@ -38,16 +33,11 @@ EventMetricData parse(log_msg msg)
// set tag.
char* eventData = msg.msg();
uint32_t tag = get4LE(eventData);
- if (!TagId_IsValid(tag)) {
- // return when an invalid tag is found.
- return eventMetricData;
- }
- eventMetricData.set_tag(static_cast<TagId>(tag));
+ // TODO: Replace the following line when we can serialize on the fly.
+ //eventMetricData.set_tag(tag);
// set timestamp of the event.
- KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
- keyValuePair->set_key(EVENT_TIMESTAMP);
- keyValuePair->set_value_int(msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec);
+ eventMetricData.set_timestamp_nanos(msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec);
// start iterating k,v pairs.
android_log_context context =
@@ -66,38 +56,50 @@ EventMetricData parse(log_msg msg)
case EVENT_TYPE_INT:
if (index % 2 == 0) {
key = elem.data.int32;
- } else if (KeyId_IsValid(key)) {
+ } else {
+ // TODO: Fix the following lines when we can serialize on the fly.
+ /*
int32_t val = elem.data.int32;
KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
- keyValuePair->set_key(static_cast<KeyId>(key));
+ keyValuePair->set_key(key);
keyValuePair->set_value_int(val);
+ */
}
index++;
break;
case EVENT_TYPE_FLOAT:
- if (index % 2 == 1 && KeyId_IsValid(key)) {
+ if (index % 2 == 1) {
+ // TODO: Fix the following lines when we can serialize on the fly.
+ /*
float val = elem.data.float32;
KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
- keyValuePair->set_key(static_cast<KeyId>(key));
+ keyValuePair->set_key(key);
keyValuePair->set_value_float(val);
+ */
}
index++;
break;
case EVENT_TYPE_STRING:
- if (index % 2 == 1 && KeyId_IsValid(key)) {
+ if (index % 2 == 1) {
+ // TODO: Fix the following lines when we can serialize on the fly.
+ /*
char* val = elem.data.string;
KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
- keyValuePair->set_key(static_cast<KeyId>(key));
+ keyValuePair->set_key(key);
keyValuePair->set_value_str(val);
+ */
}
index++;
break;
case EVENT_TYPE_LONG:
- if (index % 2 == 1 && KeyId_IsValid(key)) {
+ if (index % 2 == 1) {
+ // TODO: Fix the following lines when we can serialize on the fly.
+ /*
int64_t val = elem.data.int64;
KeyValuePair* keyValuePair = eventMetricData.add_key_value_pair();
- keyValuePair->set_key(static_cast<KeyId>(key));
+ keyValuePair->set_key(key);
keyValuePair->set_value_int(val);
+ */
}
index++;
break;
diff --git a/cmds/statsd/src/stats_events.proto b/cmds/statsd/src/stats_events.proto
new file mode 100644
index 000000000000..dffc68e21bda
--- /dev/null
+++ b/cmds/statsd/src/stats_events.proto
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
+
+package android.os.statsd;
+
+option java_package = "com.android.os";
+option java_outer_classname = "StatsEventProto";
+
+message StatsEvent {
+ oneof log_entry_event {
+ ScreenStateChange screen_state_change = 2;
+ ProcessStateChange process_state_change = 1112;
+ }
+}
+
+message ScreenStateChange {
+ enum State {
+ STATE_UNKNOWN = 0;
+ STATE_OFF = 1;
+ STATE_ON = 2;
+ STATE_DOZE = 3;
+ STATE_DOZE_SUSPEND = 4;
+ STATE_VR = 5;
+ }
+ optional State display_state = 1;
+}
+
+message ProcessStateChange {
+ enum State {
+ START = 1;
+ CRASH = 2;
+ }
+ optional State state = 1;
+
+ optional int32 uid = 2;
+
+ optional string package_name = 1002;
+
+ optional int32 package_version = 3;
+ optional string package_version_string = 4;
+}
diff --git a/cmds/statsd/src/stats_log.proto b/cmds/statsd/src/stats_log.proto
index 2c66ded0c7ed..2dc0cc7b4a6b 100644
--- a/cmds/statsd/src/stats_log.proto
+++ b/cmds/statsd/src/stats_log.proto
@@ -13,20 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
package android.os.statsd;
-option optimize_for = LITE_RUNTIME;
-
option java_package = "com.android.os";
option java_outer_classname = "StatsLog";
-import "frameworks/base/cmds/statsd/src/statsd_config.proto";
-import "frameworks/base/cmds/statsd/src/stats_constants.proto";
+import "frameworks/base/cmds/statsd/src/stats_events.proto";
message KeyValuePair {
- optional KeyId key = 1;
+ optional int32 key = 1;
oneof value {
string value_str = 2;
@@ -37,15 +36,15 @@ message KeyValuePair {
}
message EventMetricData {
- optional TagId tag = 1;
+ optional int64 timestamp_nanos = 1;
- repeated KeyValuePair key_value_pair = 2;
+ optional StatsEvent stats_events = 2;
}
message CountBucketInfo {
- optional int64 start_bucket_millis = 1;
+ optional int64 start_bucket_nanos = 1;
- optional int64 end_bucket_millis = 2;
+ optional int64 end_bucket_nanos = 2;
optional int64 count = 3;
}
@@ -59,9 +58,9 @@ message CountMetricData {
message StatsLogReport {
optional int32 metric_id = 1;
- optional int64 start_report_millis = 2;
+ optional int64 start_report_nanos = 2;
- optional int64 end_report_millis = 3;
+ optional int64 end_report_nanos = 3;
message EventMetricDataWrapper {
repeated EventMetricData data = 1;
@@ -69,7 +68,6 @@ message StatsLogReport {
message CountMetricDataWrapper {
repeated CountMetricData data = 1;
}
-
oneof data {
EventMetricDataWrapper event_metrics = 4;
CountMetricDataWrapper count_metrics = 5;
diff --git a/cmds/statsd/src/statsd_config.proto b/cmds/statsd/src/statsd_config.proto
index c7f030559cd3..3e4ebaf06268 100644
--- a/cmds/statsd/src/statsd_config.proto
+++ b/cmds/statsd/src/statsd_config.proto
@@ -1,15 +1,30 @@
-syntax = "proto2";
-package android.os.statsd;
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto2";
option optimize_for = LITE_RUNTIME;
+package android.os.statsd;
+
option java_package = "com.android.internal.os";
option java_outer_classname = "StatsdConfigProto";
-import "frameworks/base/cmds/statsd/src/stats_constants.proto";
-
message KeyMatcher {
- optional KeyId key = 1;
+ optional int32 key = 1;
+
optional bool as_package_name = 2 [ default = false ];
}
@@ -21,13 +36,11 @@ message KeyValueMatcher {
string eq_string = 3;
int32 eq_int = 4;
- // Numeric comparisons. Lt means strictly less than.
int64 lt_int = 5;
int64 gt_int = 6;
float lt_float = 7;
float gt_float = 8;
- // Numeric comparisons with equality. Lte means less than or equal.
int64 lte_int = 9;
int64 gte_int = 10;
}
@@ -42,7 +55,7 @@ enum LogicalOperation {
}
message SimpleLogEntryMatcher {
- repeated TagId tag = 1;
+ repeated int32 tag = 1;
repeated KeyValueMatcher key_value_matcher = 2;
}
diff --git a/cmds/statsd/tests/LogEntryMatcher_test.cpp b/cmds/statsd/tests/LogEntryMatcher_test.cpp
index eb807cad9085..81d93b62eb56 100644
--- a/cmds/statsd/tests/LogEntryMatcher_test.cpp
+++ b/cmds/statsd/tests/LogEntryMatcher_test.cpp
@@ -27,28 +27,32 @@
using namespace android::os::statsd;
using std::unordered_map;
+const int kTagIdWakelock = 123;
+const int kKeyIdState = 45;
+const int kKeyIdPackageVersion = 67;
+
#ifdef __ANDROID__
TEST(LogEntryMatcherTest, TestSimpleMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
unordered_map<int, float> floatMap;
unordered_map<int, bool> boolMap;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap, boolMap));
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap, boolMap));
}
TEST(LogEntryMatcherTest, TestBoolMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
auto keyValue = simpleMatcher->add_key_value_matcher();
- keyValue->mutable_key_matcher()->set_key(KeyId::STATE);
+ keyValue->mutable_key_matcher()->set_key(kKeyIdState);
unordered_map<int, long> intMap;
@@ -57,16 +61,16 @@ TEST(LogEntryMatcherTest, TestBoolMatcher) {
unordered_map<int, bool> boolMap;
keyValue->set_eq_bool(true);
- boolMap[KeyId::STATE] = true;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ boolMap[kKeyIdState] = true;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
keyValue->set_eq_bool(false);
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- boolMap[TagId::WAKELOCK] = false;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ boolMap[kKeyIdState] = false;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
@@ -74,9 +78,9 @@ TEST(LogEntryMatcherTest, TestStringMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
auto keyValue = simpleMatcher->add_key_value_matcher();
- keyValue->mutable_key_matcher()->set_key(KeyId::STATE);
+ keyValue->mutable_key_matcher()->set_key(kKeyIdState);
keyValue->set_eq_string("wakelock_name");
unordered_map<int, long> intMap;
@@ -84,18 +88,18 @@ TEST(LogEntryMatcherTest, TestStringMatcher) {
unordered_map<int, float> floatMap;
unordered_map<int, bool> boolMap;
- strMap[KeyId::STATE] = "wakelock_name";
+ strMap[kKeyIdState] = "wakelock_name";
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap, boolMap));
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap, boolMap));
}
TEST(LogEntryMatcherTest, TestIntComparisonMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
auto keyValue = simpleMatcher->add_key_value_matcher();
- keyValue->mutable_key_matcher()->set_key(KeyId::STATE);
+ keyValue->mutable_key_matcher()->set_key(kKeyIdState);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -103,25 +107,25 @@ TEST(LogEntryMatcherTest, TestIntComparisonMatcher) {
unordered_map<int, bool> boolMap;
keyValue->set_lt_int(10);
- intMap[KeyId::STATE] = 11;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 11;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 10;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 10;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 9;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 9;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
keyValue->set_gt_int(10);
- intMap[KeyId::STATE] = 11;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 11;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 10;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 10;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 9;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 9;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
}
@@ -129,9 +133,9 @@ TEST(LogEntryMatcherTest, TestIntWithEqualityComparisonMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
auto keyValue = simpleMatcher->add_key_value_matcher();
- keyValue->mutable_key_matcher()->set_key(KeyId::STATE);
+ keyValue->mutable_key_matcher()->set_key(kKeyIdState);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -139,25 +143,25 @@ TEST(LogEntryMatcherTest, TestIntWithEqualityComparisonMatcher) {
unordered_map<int, bool> boolMap;
keyValue->set_lte_int(10);
- intMap[KeyId::STATE] = 11;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 11;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 10;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 10;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 9;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 9;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
keyValue->set_gte_int(10);
- intMap[KeyId::STATE] = 11;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 11;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 10;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 10;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- intMap[KeyId::STATE] = 9;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ intMap[kKeyIdState] = 9;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
}
@@ -165,9 +169,9 @@ TEST(LogEntryMatcherTest, TestFloatComparisonMatcher) {
// Set up the matcher
LogEntryMatcher matcher;
auto simpleMatcher = matcher.mutable_simple_log_entry_matcher();
- simpleMatcher->add_tag(TagId::WAKELOCK);
+ simpleMatcher->add_tag(kTagIdWakelock);
auto keyValue = simpleMatcher->add_key_value_matcher();
- keyValue->mutable_key_matcher()->set_key(KeyId::STATE);
+ keyValue->mutable_key_matcher()->set_key(kKeyIdState);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -175,24 +179,24 @@ TEST(LogEntryMatcherTest, TestFloatComparisonMatcher) {
unordered_map<int, bool> boolMap;
keyValue->set_lt_float(10.0);
- floatMap[KeyId::STATE] = 10.1;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ floatMap[kKeyIdState] = 10.1;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- floatMap[KeyId::STATE] = 9.9;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ floatMap[kKeyIdState] = 9.9;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
keyValue->set_gt_float(10.0);
- floatMap[KeyId::STATE] = 10.1;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ floatMap[kKeyIdState] = 10.1;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
- floatMap[KeyId::STATE] = 9.9;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap,
+ floatMap[kKeyIdState] = 9.9;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap,
floatMap, boolMap));
}
// Helper for the composite matchers.
-void addSimpleMatcher(SimpleLogEntryMatcher* simpleMatcher, TagId tag, KeyId key, int val) {
+void addSimpleMatcher(SimpleLogEntryMatcher* simpleMatcher, int tag, int key, int val) {
simpleMatcher->add_tag(tag);
auto keyValue = simpleMatcher->add_key_value_matcher();
keyValue->mutable_key_matcher()->set_key(key);
@@ -205,23 +209,23 @@ TEST(LogEntryMatcherTest, TestAndMatcher) {
auto combination = matcher.mutable_combination();
combination->set_operation(LogicalOperation::AND);
- addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(), TagId::WAKELOCK, KeyId::STATE, 3);
- addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(), TagId::WAKELOCK, KeyId::PACKAGE_VERSION, 4);
+ addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(), kTagIdWakelock, kKeyIdState, 3);
+ addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(), kTagIdWakelock, kKeyIdPackageVersion, 4);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
unordered_map<int, float> floatMap;
unordered_map<int, bool> boolMap;
- intMap[1003] = 4;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap, boolMap));
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap, boolMap));
intMap.clear();
- intMap[1] = 3;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap, boolMap));
+ intMap[kKeyIdState] = 3;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap, boolMap));
intMap.clear();
- intMap[1] = 3;
- intMap[1003] = 4;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap, boolMap));
+ intMap[kKeyIdState] = 3;
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap, boolMap));
}
TEST(LogEntryMatcherTest, TestOrMatcher) {
@@ -231,9 +235,9 @@ TEST(LogEntryMatcherTest, TestOrMatcher) {
combination->set_operation(LogicalOperation::OR);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::STATE, 3);
+ kTagIdWakelock, kKeyIdState, 3);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::PACKAGE_VERSION, 4);
+ kTagIdWakelock, kKeyIdPackageVersion, 4);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -241,19 +245,19 @@ TEST(LogEntryMatcherTest, TestOrMatcher) {
unordered_map<int, bool> boolMap;
// Don't set any key-value pairs.
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[1003] = 4;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
intMap.clear();
- intMap[1] = 3;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
intMap.clear();
- intMap[1] = 3;
- intMap[1003] = 4;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
@@ -265,7 +269,7 @@ TEST(LogEntryMatcherTest, TestNotMatcher) {
// Define first simpleMatcher
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::STATE, 3);
+ kTagIdWakelock, kKeyIdState, 3);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -273,8 +277,8 @@ TEST(LogEntryMatcherTest, TestNotMatcher) {
unordered_map<int, bool> boolMap;
// Don't set any key-value pairs.
- intMap[KeyId::STATE] = 3;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
@@ -285,9 +289,9 @@ TEST(LogEntryMatcherTest, TestNANDMatcher) {
combination->set_operation(LogicalOperation::NAND);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::STATE, 3);
+ kTagIdWakelock, kKeyIdState, 3);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::PACKAGE_VERSION, 4);
+ kTagIdWakelock, kKeyIdPackageVersion, 4);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -295,13 +299,13 @@ TEST(LogEntryMatcherTest, TestNANDMatcher) {
unordered_map<int, bool> boolMap;
// Don't set any key-value pairs.
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::STATE] = 3;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::PACKAGE_VERSION] = 4;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
@@ -312,9 +316,9 @@ TEST(LogEntryMatcherTest, TestNORMatcher) {
combination->set_operation(LogicalOperation::NOR);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::STATE, 3);
+ kTagIdWakelock, kKeyIdState, 3);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::PACKAGE_VERSION, 4);
+ kTagIdWakelock, kKeyIdPackageVersion, 4);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -322,13 +326,13 @@ TEST(LogEntryMatcherTest, TestNORMatcher) {
unordered_map<int, bool> boolMap;
// Don't set any key-value pairs.
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::STATE] = 3;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::PACKAGE_VERSION] = 4;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
@@ -342,9 +346,9 @@ TEST(LogEntryMatcherTest, TestMultipleLayerMatcher) {
auto combination = not_combination->add_matcher()->mutable_combination();
combination->set_operation(LogicalOperation::AND);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::STATE, 3);
+ kTagIdWakelock, kKeyIdState, 3);
addSimpleMatcher(combination->add_matcher()->mutable_simple_log_entry_matcher(),
- TagId::WAKELOCK, KeyId::PACKAGE_VERSION, 4);
+ kTagIdWakelock, kKeyIdPackageVersion, 4);
unordered_map<int, long> intMap;
unordered_map<int, string> strMap;
@@ -352,15 +356,16 @@ TEST(LogEntryMatcherTest, TestMultipleLayerMatcher) {
unordered_map<int, bool> boolMap;
// Don't set any key-value pairs.
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::STATE] = 3;
- EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdState] = 3;
+ EXPECT_TRUE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
- intMap[KeyId::PACKAGE_VERSION] = 4;
- EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, TagId::WAKELOCK, intMap, strMap, floatMap,
+ intMap[kKeyIdPackageVersion] = 4;
+ EXPECT_FALSE(LogEntryMatcherManager::matches(matcher, kTagIdWakelock, intMap, strMap, floatMap,
boolMap));
}
+
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
diff --git a/core/java/android/util/StatsLogKey.java b/core/java/android/util/StatsLogKey.java
new file mode 100644
index 000000000000..9ad0a23d00d6
--- /dev/null
+++ b/core/java/android/util/StatsLogKey.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// THIS FILE IS AUTO-GENERATED.
+// DO NOT MODIFY.
+
+package android.util;
+
+/** @hide */
+public class StatsLogKey {
+ private StatsLogKey() {}
+
+ /** Constants for android.os.statsd.ScreenStateChange. */
+
+ /** display_state */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE = 1;
+
+ /** Constants for android.os.statsd.ProcessStateChange. */
+
+ /** state */
+ public static final int PROCESS_STATE_CHANGE__STATE = 1;
+
+ /** uid */
+ public static final int PROCESS_STATE_CHANGE__UID = 2;
+
+ /** package_name */
+ public static final int PROCESS_STATE_CHANGE__PACKAGE_NAME = 1002;
+
+ /** package_version */
+ public static final int PROCESS_STATE_CHANGE__PACKAGE_VERSION = 3;
+
+ /** package_version_string */
+ public static final int PROCESS_STATE_CHANGE__PACKAGE_VERSION_STRING = 4;
+
+}
diff --git a/cmds/statsd/src/stats_constants.proto b/core/java/android/util/StatsLogTag.java
index 9758a2e0cb89..5e5a82870aa0 100644
--- a/cmds/statsd/src/stats_constants.proto
+++ b/core/java/android/util/StatsLogTag.java
@@ -13,27 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-syntax = "proto2";
-package android.os.statsd;
+// THIS FILE IS AUTO-GENERATED.
+// DO NOT MODIFY.
-option optimize_for = LITE_RUNTIME;
+package android.util;
-option java_package = "com.android.internal.logging";
-option java_outer_classname = "StatsConstantsProto";
+/** @hide */
+public class StatsLogTag {
+ private StatsLogTag() {}
-enum TagId {
- WAKELOCK = 1;
- SCREEN = 2;
- PROCESS = 1112; // TODO: Temporary usage only for testing.
-}
+ /** android.os.statsd.ScreenStateChange. */
+ public static final int SCREEN_STATE_CHANGE = 2;
+
+ /** android.os.statsd.ProcessStateChange. */
+ public static final int PROCESS_STATE_CHANGE = 1112;
-enum KeyId {
- STATE = 1;
- ANOTHER_STATE = 2;
- EVENT_TIMESTAMP = 1001;
- PACKAGE_NAME = 1002;
- PACKAGE_VERSION = 1003;
- PACKAGE_VERSION_STRING = 1004;
- ATTRIBUTION_CHAIN = 1005;
}
diff --git a/core/java/android/util/StatsLogValue.java b/core/java/android/util/StatsLogValue.java
new file mode 100644
index 000000000000..05b9d9333bef
--- /dev/null
+++ b/core/java/android/util/StatsLogValue.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// THIS FILE IS AUTO-GENERATED.
+// DO NOT MODIFY.
+
+package android.util;
+
+/** @hide */
+public class StatsLogValue {
+ private StatsLogValue() {}
+
+ /** Constants for android.os.statsd.ScreenStateChange. */
+
+ /** display_state: STATE_UNKNOWN */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_UNKNOWN = 0;
+
+ /** display_state: STATE_OFF */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_OFF = 1;
+
+ /** display_state: STATE_ON */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_ON = 2;
+
+ /** display_state: STATE_DOZE */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_DOZE = 3;
+
+ /** display_state: STATE_DOZE_SUSPEND */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_DOZE_SUSPEND = 4;
+
+ /** display_state: STATE_VR */
+ public static final int SCREEN_STATE_CHANGE__DISPLAY_STATE__STATE_VR = 5;
+
+ /** Constants for android.os.statsd.ProcessStateChange. */
+
+ /** state: START */
+ public static final int PROCESS_STATE_CHANGE__STATE__START = 1;
+
+ /** state: CRASH */
+ public static final int PROCESS_STATE_CHANGE__STATE__CRASH = 2;
+
+}