From 124dd4262f2a2c8e55fdb81af9981b1f949a9686 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 29 Apr 2015 14:48:32 -0400 Subject: [PATCH] Switch perfprofd from using full to lite version of protobuf library. Change-Id: Ie4cf7cd2e6e4f90bcdba39200c856c219b710065 --- perfprofd/Android.mk | 2 +- perfprofd/perf_profile.proto | 2 ++ perfprofd/tests/Android.mk | 2 +- perfprofd/tests/perfprofd_test.cc | 49 +++++++++++++++++++++++++-------------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/perfprofd/Android.mk b/perfprofd/Android.mk index 282c008a..16cd2710 100644 --- a/perfprofd/Android.mk +++ b/perfprofd/Android.mk @@ -57,7 +57,7 @@ LOCAL_CPP_EXTENSION := cc LOCAL_CXX_STL := libc++ LOCAL_SRC_FILES := perfprofdmain.cc LOCAL_STATIC_LIBRARIES := libperfprofdcore libperfprofdutils -LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full +LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-lite LOCAL_SYSTEM_SHARED_LIBRARIES := libc libstdc++ LOCAL_CPPFLAGS += $(perfprofd_cppflags) LOCAL_CFLAGS := -Wall -Werror -std=gnu++11 diff --git a/perfprofd/perf_profile.proto b/perfprofd/perf_profile.proto index 0c3da011..ee34163f 100644 --- a/perfprofd/perf_profile.proto +++ b/perfprofd/perf_profile.proto @@ -3,6 +3,8 @@ syntax = "proto2"; option java_package = "com.google.common.logging"; +option optimize_for = LITE_RUNTIME; + package wireless_android_play_playlog; // An entry of the map from a stack of addresses to count. diff --git a/perfprofd/tests/Android.mk b/perfprofd/tests/Android.mk index c8347a11..2a211a38 100644 --- a/perfprofd/tests/Android.mk +++ b/perfprofd/tests/Android.mk @@ -37,7 +37,7 @@ LOCAL_CXX_STL := libc++ LOCAL_STATIC_LIBRARIES := \ libperfprofdcore \ libperfprofdmockutils -LOCAL_SHARED_LIBRARIES := libprotobuf-cpp-full +LOCAL_SHARED_LIBRARIES := libprotobuf-cpp-lite LOCAL_C_INCLUDES += system/extras/perfprofd external/protobuf/src LOCAL_SRC_FILES := perfprofd_test.cc LOCAL_CPPFLAGS += $(perfprofd_test_cppflags) diff --git a/perfprofd/tests/perfprofd_test.cc b/perfprofd/tests/perfprofd_test.cc index 7e51e0d1..b70dd86e 100644 --- a/perfprofd/tests/perfprofd_test.cc +++ b/perfprofd/tests/perfprofd_test.cc @@ -217,8 +217,7 @@ class PerfProfdRunner { //...................................................................... static void readEncodedProfile(const char *testpoint, - wireless_android_play_playlog::AndroidPerfProfile &encodedProfile, - bool debugDump=false) + wireless_android_play_playlog::AndroidPerfProfile &encodedProfile) { struct stat statb; int perf_data_stat_result = stat(encoded_file_path().c_str(), &statb); @@ -235,17 +234,35 @@ static void readEncodedProfile(const char *testpoint, // decode encodedProfile.ParseFromString(encoded); +} + +static std::string encodedLoadModuleToString(const wireless_android_play_playlog::LoadModule &lm) +{ + std::stringstream ss; + ss << "name: \"" << lm.name() << "\"\n"; + if (lm.build_id() != "") { + ss << "build_id: \"" << lm.build_id() << "\"\n"; + } + return ss.str(); +} - if (debugDump) { - std::string textdump; - ::google::protobuf::TextFormat::PrintToString(encodedProfile, &textdump); - std::string dfp(dest_dir); dfp += "/"; dfp += testpoint; dfp += ".dump_encoded.txt"; - FILE *ofp = fopen(dfp.c_str(), "w"); - if (ofp) { - fwrite(textdump.c_str(), textdump.size(), 1, ofp); - fclose(ofp); +static std::string encodedModuleSamplesToString(const wireless_android_play_playlog::LoadModuleSamples &mod) +{ + std::stringstream ss; + + ss << "load_module_id: " << mod.load_module_id() << "\n"; + for (size_t k = 0; k < mod.address_samples_size(); k++) { + const auto &sample = mod.address_samples(k); + ss << " address_samples {\n"; + for (size_t l = 0; l < mod.address_samples(k).address_size(); + l++) { + auto address = mod.address_samples(k).address(l); + ss << " address: " << address << "\n"; } + ss << " count: " << sample.count() << "\n"; + ss << " }\n"; } + return ss.str(); } #define RAW_RESULT(x) #x @@ -546,8 +563,7 @@ TEST_F(PerfProfdTest, BasicRunWithCannedPerf) // Check a couple of load modules { const auto &lm0 = encodedProfile.load_modules(0); - std::string act_lm0; - ::google::protobuf::TextFormat::PrintToString(lm0, &act_lm0); + std::string act_lm0 = encodedLoadModuleToString(lm0); std::string sqact0 = squeezeWhite(act_lm0, "actual for lm 0"); const std::string expected_lm0 = RAW_RESULT( name: "/data/app/com.google.android.apps.plus-1/lib/arm/libcronet.so" @@ -556,8 +572,7 @@ TEST_F(PerfProfdTest, BasicRunWithCannedPerf) EXPECT_STREQ(sqexp0.c_str(), sqact0.c_str()); } { const auto &lm9 = encodedProfile.load_modules(9); - std::string act_lm9; - ::google::protobuf::TextFormat::PrintToString(lm9, &act_lm9); + std::string act_lm9 = encodedLoadModuleToString(lm9); std::string sqact9 = squeezeWhite(act_lm9, "actual for lm 9"); const std::string expected_lm9 = RAW_RESULT( name: "/system/lib/libandroid_runtime.so" build_id: "8164ed7b3a8b8f5a220d027788922510" @@ -569,8 +584,7 @@ TEST_F(PerfProfdTest, BasicRunWithCannedPerf) // Examine some of the samples now { const auto &p1 = encodedProfile.programs(0); const auto &lm1 = p1.modules(0); - std::string act_lm1; - ::google::protobuf::TextFormat::PrintToString(lm1, &act_lm1); + std::string act_lm1 = encodedModuleSamplesToString(lm1); std::string sqact1 = squeezeWhite(act_lm1, "actual for lm1"); const std::string expected_lm1 = RAW_RESULT( load_module_id: 9 address_samples { address: 296100 count: 1 } @@ -580,8 +594,7 @@ TEST_F(PerfProfdTest, BasicRunWithCannedPerf) } { const auto &p1 = encodedProfile.programs(2); const auto &lm2 = p1.modules(0); - std::string act_lm2; - ::google::protobuf::TextFormat::PrintToString(lm2, &act_lm2); + std::string act_lm2 = encodedModuleSamplesToString(lm2); std::string sqact2 = squeezeWhite(act_lm2, "actual for lm2"); const std::string expected_lm2 = RAW_RESULT( load_module_id: 2 -- 2.11.0