Loading logd/LogBuffer.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -1100,6 +1100,10 @@ uint64_t LogBuffer::flushTo( } } // Help detect if the valid message before is from the same source so // we can differentiate chatty filter types. pid_t lastTid[LOG_ID_MAX] = { 0 }; for (; it != mLogElements.end(); ++it) { LogBufferElement *element = *it; Loading @@ -1126,10 +1130,19 @@ uint64_t LogBuffer::flushTo( } } bool sameTid = lastTid[element->getLogId()] == element->getTid(); // Dropped (chatty) immediately following a valid log from the // same source in the same log buffer indicates we have a // multiple identical squash. chatty that differs source // is due to spam filter. chatty to chatty of different // source is also due to spam filter. lastTid[element->getLogId()] = (element->getDropped() && !sameTid) ? 0 : element->getTid(); pthread_mutex_unlock(&mLogElementsLock); // range locking in LastLogTimes looks after us max = element->flushTo(reader, this, privileged); max = element->flushTo(reader, this, privileged, sameTid); if (max == element->FLUSH_ERROR) { return max; Loading logd/LogBufferElement.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ char *android::tidToName(pid_t tid) { // assumption: mMsg == NULL size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer *parent) { LogBuffer* parent, bool lastSame) { static const char tag[] = "chatty"; if (!__android_log_is_loggable_len(ANDROID_LOG_INFO, Loading @@ -123,7 +123,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, return 0; } static const char format_uid[] = "uid=%u%s%s expire %u line%s"; static const char format_uid[] = "uid=%u%s%s %s %u line%s"; parent->lock(); const char *name = parent->uidToName(mUid); parent->unlock(); Loading Loading @@ -165,8 +165,9 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } } // identical to below to calculate the buffer size required const char* type = lastSame ? "identical" : "expire"; size_t len = snprintf(NULL, 0, format_uid, mUid, name ? name : "", commName ? commName : "", commName ? commName : "", type, mDropped, (mDropped > 1) ? "s" : ""); size_t hdrLen; Loading Loading @@ -198,7 +199,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } snprintf(buffer + hdrLen, len + 1, format_uid, mUid, name ? name : "", commName ? commName : "", commName ? commName : "", type, mDropped, (mDropped > 1) ? "s" : ""); free(const_cast<char *>(name)); free(const_cast<char *>(commName)); Loading @@ -207,7 +208,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } uint64_t LogBufferElement::flushTo(SocketClient* reader, LogBuffer* parent, bool privileged) { bool privileged, bool lastSame) { struct logger_entry_v4 entry; memset(&entry, 0, sizeof(struct logger_entry_v4)); Loading @@ -229,7 +230,7 @@ uint64_t LogBufferElement::flushTo(SocketClient *reader, LogBuffer *parent, char *buffer = NULL; if (!mMsg) { entry.len = populateDroppedMessage(buffer, parent); entry.len = populateDroppedMessage(buffer, parent, lastSame); if (!entry.len) { return mSequence; } Loading logd/LogBufferElement.h +5 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ class LogBufferElement { // assumption: mMsg == NULL size_t populateDroppedMessage(char*& buffer, LogBuffer *parent); LogBuffer* parent, bool lastSame); public: LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, Loading Loading @@ -86,7 +87,8 @@ public: log_time getRealTime(void) const { return mRealTime; } static const uint64_t FLUSH_ERROR; uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); uint64_t flushTo(SocketClient* writer, LogBuffer* parent, bool privileged, bool lastSame); }; #endif logd/tests/logd_test.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -853,11 +853,13 @@ void __android_log_btwrite_multiple__helper(int count) { int expected_count = (count < 2) ? count : 2; int expected_chatty_count = (count <= 2) ? 0 : 1; int expected_expire_count = (count < 2) ? 0 : (count - 2); int expected_identical_count = (count < 2) ? 0 : (count - 2); static const int expected_expire_count = 0; count = 0; int second_count = 0; int chatty_count = 0; int identical_count = 0; int expire_count = 0; for (;;) { Loading Loading @@ -887,19 +889,25 @@ void __android_log_btwrite_multiple__helper(int count) { ++chatty_count; // int len = get4LE(eventData + 4 + 1); log_msg.buf[LOGGER_ENTRY_MAX_LEN] = '\0'; const char *cp = strstr(eventData + 4 + 1 + 4, " expire "); if (!cp) continue; const char *cp; if ((cp = strstr(eventData + 4 + 1 + 4, " identical "))) { unsigned val = 0; sscanf(cp, " identical %u lines", &val); identical_count += val; } else if ((cp = strstr(eventData + 4 + 1 + 4, " expire "))) { unsigned val = 0; sscanf(cp, " expire %u lines", &val); expire_count += val; } } } android_logger_list_close(logger_list); EXPECT_EQ(expected_count, count); EXPECT_EQ(1, second_count); EXPECT_EQ(expected_chatty_count, chatty_count); EXPECT_EQ(expected_identical_count, identical_count); EXPECT_EQ(expected_expire_count, expire_count); } Loading Loading
logd/LogBuffer.cpp +14 −1 Original line number Diff line number Diff line Loading @@ -1100,6 +1100,10 @@ uint64_t LogBuffer::flushTo( } } // Help detect if the valid message before is from the same source so // we can differentiate chatty filter types. pid_t lastTid[LOG_ID_MAX] = { 0 }; for (; it != mLogElements.end(); ++it) { LogBufferElement *element = *it; Loading @@ -1126,10 +1130,19 @@ uint64_t LogBuffer::flushTo( } } bool sameTid = lastTid[element->getLogId()] == element->getTid(); // Dropped (chatty) immediately following a valid log from the // same source in the same log buffer indicates we have a // multiple identical squash. chatty that differs source // is due to spam filter. chatty to chatty of different // source is also due to spam filter. lastTid[element->getLogId()] = (element->getDropped() && !sameTid) ? 0 : element->getTid(); pthread_mutex_unlock(&mLogElementsLock); // range locking in LastLogTimes looks after us max = element->flushTo(reader, this, privileged); max = element->flushTo(reader, this, privileged, sameTid); if (max == element->FLUSH_ERROR) { return max; Loading
logd/LogBufferElement.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ char *android::tidToName(pid_t tid) { // assumption: mMsg == NULL size_t LogBufferElement::populateDroppedMessage(char*& buffer, LogBuffer *parent) { LogBuffer* parent, bool lastSame) { static const char tag[] = "chatty"; if (!__android_log_is_loggable_len(ANDROID_LOG_INFO, Loading @@ -123,7 +123,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, return 0; } static const char format_uid[] = "uid=%u%s%s expire %u line%s"; static const char format_uid[] = "uid=%u%s%s %s %u line%s"; parent->lock(); const char *name = parent->uidToName(mUid); parent->unlock(); Loading Loading @@ -165,8 +165,9 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } } // identical to below to calculate the buffer size required const char* type = lastSame ? "identical" : "expire"; size_t len = snprintf(NULL, 0, format_uid, mUid, name ? name : "", commName ? commName : "", commName ? commName : "", type, mDropped, (mDropped > 1) ? "s" : ""); size_t hdrLen; Loading Loading @@ -198,7 +199,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } snprintf(buffer + hdrLen, len + 1, format_uid, mUid, name ? name : "", commName ? commName : "", commName ? commName : "", type, mDropped, (mDropped > 1) ? "s" : ""); free(const_cast<char *>(name)); free(const_cast<char *>(commName)); Loading @@ -207,7 +208,7 @@ size_t LogBufferElement::populateDroppedMessage(char *&buffer, } uint64_t LogBufferElement::flushTo(SocketClient* reader, LogBuffer* parent, bool privileged) { bool privileged, bool lastSame) { struct logger_entry_v4 entry; memset(&entry, 0, sizeof(struct logger_entry_v4)); Loading @@ -229,7 +230,7 @@ uint64_t LogBufferElement::flushTo(SocketClient *reader, LogBuffer *parent, char *buffer = NULL; if (!mMsg) { entry.len = populateDroppedMessage(buffer, parent); entry.len = populateDroppedMessage(buffer, parent, lastSame); if (!entry.len) { return mSequence; } Loading
logd/LogBufferElement.h +5 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ class LogBufferElement { // assumption: mMsg == NULL size_t populateDroppedMessage(char*& buffer, LogBuffer *parent); LogBuffer* parent, bool lastSame); public: LogBufferElement(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid, Loading Loading @@ -86,7 +87,8 @@ public: log_time getRealTime(void) const { return mRealTime; } static const uint64_t FLUSH_ERROR; uint64_t flushTo(SocketClient *writer, LogBuffer *parent, bool privileged); uint64_t flushTo(SocketClient* writer, LogBuffer* parent, bool privileged, bool lastSame); }; #endif
logd/tests/logd_test.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -853,11 +853,13 @@ void __android_log_btwrite_multiple__helper(int count) { int expected_count = (count < 2) ? count : 2; int expected_chatty_count = (count <= 2) ? 0 : 1; int expected_expire_count = (count < 2) ? 0 : (count - 2); int expected_identical_count = (count < 2) ? 0 : (count - 2); static const int expected_expire_count = 0; count = 0; int second_count = 0; int chatty_count = 0; int identical_count = 0; int expire_count = 0; for (;;) { Loading Loading @@ -887,19 +889,25 @@ void __android_log_btwrite_multiple__helper(int count) { ++chatty_count; // int len = get4LE(eventData + 4 + 1); log_msg.buf[LOGGER_ENTRY_MAX_LEN] = '\0'; const char *cp = strstr(eventData + 4 + 1 + 4, " expire "); if (!cp) continue; const char *cp; if ((cp = strstr(eventData + 4 + 1 + 4, " identical "))) { unsigned val = 0; sscanf(cp, " identical %u lines", &val); identical_count += val; } else if ((cp = strstr(eventData + 4 + 1 + 4, " expire "))) { unsigned val = 0; sscanf(cp, " expire %u lines", &val); expire_count += val; } } } android_logger_list_close(logger_list); EXPECT_EQ(expected_count, count); EXPECT_EQ(1, second_count); EXPECT_EQ(expected_chatty_count, chatty_count); EXPECT_EQ(expected_identical_count, identical_count); EXPECT_EQ(expected_expire_count, expire_count); } Loading