Skip to content

Commit bc72197

Browse files
author
Tom Cherry
committed
logd: use the compressed (serialized) log buffer by default
The serialized log buffer along with compression results in: * ~3.5x more logs than chatty * Less CPU usage * Less memory usage * Equivalent log range Also, delete tests that assume that the device logd implementation is chatty. There are actual unit tests for this same behavior that don't rely on the device logd. Test: serialized log buffer is used Change-Id: Ie12898617429a75b6caff92725aa7145650f8fc6
1 parent dfdc9b1 commit bc72197

File tree

2 files changed

+1
-125
lines changed

2 files changed

+1
-125
lines changed

logd/logd_test.cpp

-124
Original file line numberDiff line numberDiff line change
@@ -832,127 +832,3 @@ TEST(logd, getEventTag_newentry) {
832832
GTEST_LOG_(INFO) << "This test does nothing.\n";
833833
#endif
834834
}
835-
836-
#ifdef __ANDROID__
837-
static inline uint32_t get4LE(const uint8_t* src) {
838-
return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
839-
}
840-
841-
static inline uint32_t get4LE(const char* src) {
842-
return get4LE(reinterpret_cast<const uint8_t*>(src));
843-
}
844-
#endif
845-
846-
void __android_log_btwrite_multiple__helper(int count) {
847-
#ifdef __ANDROID__
848-
log_time ts(CLOCK_MONOTONIC);
849-
usleep(100);
850-
log_time ts1(CLOCK_MONOTONIC);
851-
852-
// We fork to create a unique pid for the submitted log messages
853-
// so that we do not collide with the other _multiple_ tests.
854-
855-
pid_t pid = fork();
856-
857-
if (pid == 0) {
858-
// child
859-
for (int i = count; i; --i) {
860-
ASSERT_LT(
861-
0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));
862-
usleep(100);
863-
}
864-
ASSERT_LT(0,
865-
__android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1)));
866-
usleep(1000000);
867-
868-
_exit(0);
869-
}
870-
871-
siginfo_t info = {};
872-
ASSERT_EQ(0, TEMP_FAILURE_RETRY(waitid(P_PID, pid, &info, WEXITED)));
873-
ASSERT_EQ(0, info.si_status);
874-
875-
struct logger_list* logger_list;
876-
ASSERT_TRUE(nullptr != (logger_list = android_logger_list_open(LOG_ID_EVENTS,
877-
ANDROID_LOG_NONBLOCK, 0, pid)));
878-
879-
int expected_count = (count < 2) ? count : 2;
880-
int expected_chatty_count = (count <= 2) ? 0 : 1;
881-
int expected_identical_count = (count < 2) ? 0 : (count - 2);
882-
static const int expected_expire_count = 0;
883-
884-
count = 0;
885-
int second_count = 0;
886-
int chatty_count = 0;
887-
int identical_count = 0;
888-
int expire_count = 0;
889-
890-
for (;;) {
891-
log_msg log_msg;
892-
if (android_logger_list_read(logger_list, &log_msg) <= 0) break;
893-
894-
if ((log_msg.entry.pid != pid) || (log_msg.entry.len < (4 + 1 + 8)) ||
895-
(log_msg.id() != LOG_ID_EVENTS))
896-
continue;
897-
898-
char* eventData = log_msg.msg();
899-
if (!eventData) continue;
900-
901-
uint32_t tag = get4LE(eventData);
902-
903-
if ((eventData[4] == EVENT_TYPE_LONG) &&
904-
(log_msg.entry.len == (4 + 1 + 8))) {
905-
if (tag != 0) continue;
906-
907-
log_time* tx = reinterpret_cast<log_time*>(eventData + 4 + 1);
908-
if (ts == *tx) {
909-
++count;
910-
} else if (ts1 == *tx) {
911-
++second_count;
912-
}
913-
} else if (eventData[4] == EVENT_TYPE_STRING) {
914-
if (tag != CHATTY_LOG_TAG) continue;
915-
++chatty_count;
916-
// int len = get4LE(eventData + 4 + 1);
917-
log_msg.buf[LOGGER_ENTRY_MAX_LEN] = '\0';
918-
const char* cp;
919-
if ((cp = strstr(eventData + 4 + 1 + 4, " identical "))) {
920-
unsigned val = 0;
921-
sscanf(cp, " identical %u lines", &val);
922-
identical_count += val;
923-
} else if ((cp = strstr(eventData + 4 + 1 + 4, " expire "))) {
924-
unsigned val = 0;
925-
sscanf(cp, " expire %u lines", &val);
926-
expire_count += val;
927-
}
928-
}
929-
}
930-
931-
android_logger_list_close(logger_list);
932-
933-
EXPECT_EQ(expected_count, count);
934-
EXPECT_EQ(1, second_count);
935-
EXPECT_EQ(expected_chatty_count, chatty_count);
936-
EXPECT_EQ(expected_identical_count, identical_count);
937-
EXPECT_EQ(expected_expire_count, expire_count);
938-
#else
939-
count = 0;
940-
GTEST_LOG_(INFO) << "This test does nothing.\n";
941-
#endif
942-
}
943-
944-
TEST(logd, multiple_test_1) {
945-
__android_log_btwrite_multiple__helper(1);
946-
}
947-
948-
TEST(logd, multiple_test_2) {
949-
__android_log_btwrite_multiple__helper(2);
950-
}
951-
952-
TEST(logd, multiple_test_3) {
953-
__android_log_btwrite_multiple__helper(3);
954-
}
955-
956-
TEST(logd, multiple_test_10) {
957-
__android_log_btwrite_multiple__helper(10);
958-
}

logd/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ int main(int argc, char* argv[]) {
258258
// Pruning configuration.
259259
PruneList prune_list;
260260

261-
std::string buffer_type = GetProperty("logd.buffer_type", "chatty");
261+
std::string buffer_type = GetProperty("logd.buffer_type", "serialized");
262262

263263
// Partial (required for chatty) or full logging statistics.
264264
bool enable_full_log_statistics = __android_logger_property_get_bool(

0 commit comments

Comments
 (0)