Fix how we build the statsd protos.

This lets us include frameworks protos, and use the constants
and messages from them.

Change-Id: I609d6e524f780e6a5beea543a68561bede47813e
Test: make
This commit is contained in:
Joe Onorato 2017-11-18 20:32:56 -08:00
parent 37e9278c77
commit 62c220b20b
20 changed files with 146 additions and 1246 deletions

View File

@ -677,35 +677,23 @@ cc_library {
"-Werror",
"-Wno-unused-parameter",
],
srcs: [
"core/proto/**/*.proto",
"libs/incident/**/*.proto",
"tools/streaming_proto/stream.proto",
],
target: {
host: {
proto: {
type: "full",
},
srcs: [
"core/proto/**/*.proto",
"libs/incident/**/*.proto",
"tools/streaming_proto/stream.proto",
],
},
android: {
proto: {
type: "lite",
},
// We only build the protos that are optimized for the lite
// runtime, as well as the only protos that are actually
// needed by the device.
srcs: [
"core/proto/android/os/cpufreq.proto",
"core/proto/android/os/cpuinfo.proto",
"core/proto/android/os/kernelwake.proto",
"core/proto/android/os/pagetypeinfo.proto",
"core/proto/android/os/procrank.proto",
"core/proto/android/os/system_properties.proto",
"core/proto/android/service/graphicsstats.proto",
"libs/incident/proto/android/privacy.proto",
"tools/streaming_proto/stream.proto",
],
shared: {
enabled: false,
},

View File

@ -1008,7 +1008,7 @@ include $(BUILD_HOST_JAVA_LIBRARY)
# ==== java proto device library (for test only) ==============================
include $(CLEAR_VARS)
LOCAL_MODULE := platformprotosnano
LOCAL_MODULE_TAGS := tests optional
LOCAL_MODULE_TAGS := tests
LOCAL_PROTOC_OPTIMIZE_TYPE := nano
LOCAL_PROTOC_FLAGS := \
-Iexternal/protobuf/src
@ -1020,6 +1020,17 @@ LOCAL_SRC_FILES := \
include $(BUILD_STATIC_JAVA_LIBRARY)
# ==== java proto device library (for test only) ==============================
include $(CLEAR_VARS)
LOCAL_MODULE := platformprotoslite
LOCAL_MODULE_TAGS := tests
LOCAL_PROTOC_OPTIMIZE_TYPE := lite
LOCAL_PROTOC_FLAGS := \
-Iexternal/protobuf/src
LOCAL_SRC_FILES := \
$(call all-proto-files-under, core/proto)
include $(BUILD_STATIC_JAVA_LIBRARY)
# Include subdirectory makefiles
# ============================================================

View File

@ -50,12 +50,15 @@ cc_test {
"testdata/*",
],
shared_libs: [
"libprotobuf-cpp-full",
],
static_libs: [
"libgmock",
"libplatformprotos"
],
shared_libs: [
"libprotobuf-cpp-full"
],
proto: {
type: "full",
},
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -125,6 +118,6 @@ TEST_F(CpuFreqParserTest, Success) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -153,6 +146,6 @@ TEST_F(CpuInfoParserTest, Success) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -76,7 +69,7 @@ TEST_F(KernelWakesParserTest, Short) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}
@ -114,6 +107,6 @@ TEST_F(KernelWakesParserTest, Normal) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -108,6 +101,6 @@ TEST_F(PageTypeInfoParserTest, Success) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -104,7 +97,7 @@ TEST_F(ProcrankParserTest, HasSwapInfo) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}
@ -142,6 +135,6 @@ TEST_F(ProcrankParserTest, NoSwapInfo) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}

View File

@ -21,7 +21,7 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
#include <gmock/gmock.h>
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <gtest/gtest.h>
#include <string.h>
#include <fcntl.h>
@ -42,13 +42,6 @@ public:
ASSERT_TRUE(tf.fd != -1);
}
string getSerializedString(::google::protobuf::Message& message) {
string expectedStr;
message.SerializeToFileDescriptor(tf.fd);
ReadFileToString(tf.path, &expectedStr);
return expectedStr;
}
protected:
TemporaryFile tf;
@ -99,6 +92,6 @@ TEST_F(SystemPropertiesParserTest, HasSwapInfo) {
CaptureStdout();
ASSERT_EQ(NO_ERROR, parser.Parse(fd, STDOUT_FILENO));
EXPECT_EQ(GetCapturedStdout(), getSerializedString(expected));
EXPECT_EQ(GetCapturedStdout(), expected.SerializeAsString());
close(fd);
}

View File

@ -31,5 +31,11 @@ cc_library_host_shared {
type: "full",
export_proto_headers: true,
},
export_shared_lib_headers: [
"libplatformprotos",
]
}

View File

@ -19,7 +19,7 @@ statsd_common_src := \
../../core/java/android/os/IStatsManager.aidl \
src/stats_log.proto \
src/statsd_config.proto \
src/atoms_copy.proto \
src/atoms.proto \
src/anomaly/AnomalyMonitor.cpp \
src/anomaly/AnomalyTracker.cpp \
src/condition/CombinationConditionTracker.cpp \
@ -67,6 +67,9 @@ statsd_common_c_includes := \
statsd_common_aidl_includes := \
$(LOCAL_PATH)/../../core/java
statsd_common_static_libraries := \
libplatformprotos
statsd_common_shared_libraries := \
libbase \
libbinder \
@ -121,6 +124,8 @@ LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static
LOCAL_AIDL_INCLUDES := $(statsd_common_aidl_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)
LOCAL_STATIC_LIBRARIES := $(statsd_common_static_libraries)
LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries) \
libgtest_prod
@ -174,17 +179,22 @@ LOCAL_SRC_FILES := \
tests/guardrail/StatsdStats_test.cpp
LOCAL_STATIC_LIBRARIES := \
$(statsd_common_static_libraries) \
libgmock
LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries)
LOCAL_PROTOC_OPTIMIZE_TYPE := lite
include $(BUILD_NATIVE_TEST)
statsd_common_src:=
statsd_common_aidl_includes:=
statsd_common_c_includes:=
statsd_common_static_libraries:=
statsd_common_shared_libraries:=
include $(BUILD_NATIVE_TEST)
##############################

View File

@ -21,6 +21,8 @@ package android.os.statsd;
option java_package = "com.android.os";
option java_outer_classname = "AtomsProto";
import "frameworks/base/core/proto/android/app/activitymanager.proto";
/**
* The master atom class. This message defines all of the available
* raw stats log events from the Android system, also known as "atoms."
@ -168,7 +170,7 @@ message UidProcessStateChanged {
// The state.
// TODO: Use the real (mapped) process states.
optional int32 state = 2;
optional android.app.ProcessState state = 2;
}
/**
@ -1072,4 +1074,4 @@ message ModemActivityInfoPulled {
optional uint64 controller_rx_time_ms = 9;
// product of current(mA), voltage(V) and time(ms)
optional uint64 energy_used = 10;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ package android.os.statsd;
option java_package = "com.android.os";
option java_outer_classname = "StatsLog";
import "frameworks/base/cmds/statsd/src/atoms_copy.proto";
import "frameworks/base/cmds/statsd/src/atoms.proto";
message KeyValuePair {
optional int32 key = 1;

View File

@ -16,19 +16,19 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES += ../../src/stats_log.proto \
../../src/atoms_copy.proto
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/../../src/
LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_PACKAGE_NAME := StatsdDogfood
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES += ../../src/stats_log.proto \
../../src/atoms.proto
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/../../src/
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_STATIC_JAVA_LIBRARIES := platformprotoslite
LOCAL_PROTOC_OPTIMIZE_TYPE := lite
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)

View File

@ -16,20 +16,20 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES += ../../src/stats_log.proto \
../../src/atoms_copy.proto \
../../src/statsd_config.proto
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/../../src/
LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_PACKAGE_NAME := StatsdLoadtest
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SRC_FILES += ../../src/stats_log.proto \
../../src/atoms.proto \
../../src/statsd_config.proto
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/../../src/
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_STATIC_JAVA_LIBRARIES := platformprotoslite
LOCAL_PROTOC_OPTIMIZE_TYPE := lite
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_DEX_PREOPT := false
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)

View File

@ -533,10 +533,10 @@ public class ActivityManager {
// to frameworks/base/core/proto/android/app/activitymanager.proto and the following method must
// be updated to correctly map between them.
/**
* Maps ActivityManager.PROCESS_STATE_ values to ActivityManagerProto.ProcessState enum.
* Maps ActivityManager.PROCESS_STATE_ values to ProcessState enum.
*
* @param amInt a process state of the form ActivityManager.PROCESS_STATE_
* @return the value of the corresponding android.app.ActivityManagerProto's ProcessState enum.
* @return the value of the corresponding ActivityManager's ProcessState enum.
* @hide
*/
public static final int processStateAmToProto(int amInt) {

View File

@ -20,61 +20,59 @@ package android.app;
option java_multiple_files = true;
message ActivityManagerProto {
// ActivityManager.java PROCESS_STATEs
enum ProcessState {
// Order matters for process states, so values have been spaced to provide
// room for future additions.
// ActivityManager.java PROCESS_STATEs
enum ProcessState {
// Order matters for process states, so values have been spaced to provide
// room for future additions.
// Not a real process state.
PROCESS_STATE_UNKNOWN = -100;
// Process is a persistent system process.
PROCESS_STATE_PERSISTENT = 0;
// Process is a persistent system process and is doing UI.
PROCESS_STATE_PERSISTENT_UI = 100;
// Process is hosting the current top activities. Note that this covers
// all activities that are visible to the user.
PROCESS_STATE_TOP = 200;
// Process is hosting a foreground service due to a system binding.
PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 300;
// Process is hosting a foreground service.
PROCESS_STATE_FOREGROUND_SERVICE = 400;
// Same as PROCESS_STATE_TOP but while device is sleeping.
PROCESS_STATE_TOP_SLEEPING = 500;
// Process is important to the user, and something they are aware of.
PROCESS_STATE_IMPORTANT_FOREGROUND = 600;
// Process is important to the user, but not something they are aware of.
PROCESS_STATE_IMPORTANT_BACKGROUND = 700;
// Process is in the background transient so we will try to keep running.
PROCESS_STATE_TRANSIENT_BACKGROUND = 800;
// Process is in the background running a backup/restore operation.
PROCESS_STATE_BACKUP = 900;
// Process is in the background, but it can't restore its state so we want
// to try to avoid killing it.
PROCESS_STATE_HEAVY_WEIGHT = 1000;
// Process is in the background running a service. Unlike oom_adj, this
// level is used for both the normal running in background state and the
// executing operations state.
PROCESS_STATE_SERVICE = 1100;
// Process is in the background running a receiver. Note that from the
// perspective of oom_adj, receivers run at a higher foreground level, but
// for our prioritization here that is not necessary and putting them
// below services means many fewer changes in some process states as they
// receive broadcasts.
PROCESS_STATE_RECEIVER = 1200;
// Process is in the background but hosts the home activity.
PROCESS_STATE_HOME = 1300;
// Process is in the background but hosts the last shown activity.
PROCESS_STATE_LAST_ACTIVITY = 1400;
// Process is being cached for later use and contains activities.
PROCESS_STATE_CACHED_ACTIVITY = 1500;
// Process is being cached for later use and is a client of another cached
// process that contains activities.
PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 1600;
// Process is being cached for later use and is empty.
PROCESS_STATE_CACHED_EMPTY = 1700;
// Process does not exist.
PROCESS_STATE_NONEXISTENT = 1800;
}
// Not a real process state.
PROCESS_STATE_UNKNOWN = -100;
// Process is a persistent system process.
PROCESS_STATE_PERSISTENT = 0;
// Process is a persistent system process and is doing UI.
PROCESS_STATE_PERSISTENT_UI = 100;
// Process is hosting the current top activities. Note that this covers
// all activities that are visible to the user.
PROCESS_STATE_TOP = 200;
// Process is hosting a foreground service due to a system binding.
PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 300;
// Process is hosting a foreground service.
PROCESS_STATE_FOREGROUND_SERVICE = 400;
// Same as PROCESS_STATE_TOP but while device is sleeping.
PROCESS_STATE_TOP_SLEEPING = 500;
// Process is important to the user, and something they are aware of.
PROCESS_STATE_IMPORTANT_FOREGROUND = 600;
// Process is important to the user, but not something they are aware of.
PROCESS_STATE_IMPORTANT_BACKGROUND = 700;
// Process is in the background transient so we will try to keep running.
PROCESS_STATE_TRANSIENT_BACKGROUND = 800;
// Process is in the background running a backup/restore operation.
PROCESS_STATE_BACKUP = 900;
// Process is in the background, but it can't restore its state so we want
// to try to avoid killing it.
PROCESS_STATE_HEAVY_WEIGHT = 1000;
// Process is in the background running a service. Unlike oom_adj, this
// level is used for both the normal running in background state and the
// executing operations state.
PROCESS_STATE_SERVICE = 1100;
// Process is in the background running a receiver. Note that from the
// perspective of oom_adj, receivers run at a higher foreground level, but
// for our prioritization here that is not necessary and putting them
// below services means many fewer changes in some process states as they
// receive broadcasts.
PROCESS_STATE_RECEIVER = 1200;
// Process is in the background but hosts the home activity.
PROCESS_STATE_HOME = 1300;
// Process is in the background but hosts the last shown activity.
PROCESS_STATE_LAST_ACTIVITY = 1400;
// Process is being cached for later use and contains activities.
PROCESS_STATE_CACHED_ACTIVITY = 1500;
// Process is being cached for later use and is a client of another cached
// process that contains activities.
PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 1600;
// Process is being cached for later use and is empty.
PROCESS_STATE_CACHED_EMPTY = 1700;
// Process does not exist.
PROCESS_STATE_NONEXISTENT = 1800;
}

View File

@ -57,7 +57,7 @@ message PowerManagerServiceDumpProto {
optional bool is_active = 3;
optional int32 num_wake_locks = 4;
optional bool is_process_state_unknown = 5;
optional .android.app.ActivityManagerProto.ProcessState process_state = 6;
optional .android.app.ProcessState process_state = 6;
}
optional ConstantsProto constants = 1;

View File

@ -36,6 +36,7 @@ LOCAL_SRC_FILES := \
src/IncidentReportArgs.cpp
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_PROTO_OPTIMIZE_TYPE := lite
include $(BUILD_SHARED_LIBRARY)