From 99f47a9e7c4374f2bbfc18e4a97aa7848245ea33 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 7 Apr 2014 14:58:08 -0700 Subject: [PATCH] logd: liblog: logcat: debuggerd: Add LOG_ID_CRASH Change-Id: Iea453764a1a4fc1661f461f10c641c30150e4d20 --- debuggerd/utility.cpp | 3 ++- include/log/log.h | 1 + liblog/log_read.c | 3 ++- liblog/log_read_kern.c | 3 ++- liblog/logd_write.c | 5 +++-- liblog/logd_write_kern.c | 3 +++ logcat/logcat.cpp | 20 ++++++++++++++++++-- logd/LogBuffer.cpp | 2 +- logd/tests/logd_test.cpp | 2 +- 9 files changed, 33 insertions(+), 9 deletions(-) diff --git a/debuggerd/utility.cpp b/debuggerd/utility.cpp index 9b2091450..d4c252f2d 100644 --- a/debuggerd/utility.cpp +++ b/debuggerd/utility.cpp @@ -24,6 +24,7 @@ #include #include +#include #include const int sleep_time_usec = 50000; // 0.05 seconds @@ -64,7 +65,7 @@ void _LOG(log_t* log, int scopeFlags, const char* fmt, ...) { } if (want_log_write) { - __android_log_write(ANDROID_LOG_INFO, "DEBUG", buf); + __android_log_buf_write(LOG_ID_CRASH, ANDROID_LOG_INFO, "DEBUG", buf); if (want_amfd_write) { int written = write_to_am(log->amfd, buf, len); if (written <= 0) { diff --git a/include/log/log.h b/include/log/log.h index d469f4044..5b76c1a4b 100644 --- a/include/log/log.h +++ b/include/log/log.h @@ -550,6 +550,7 @@ typedef enum log_id { LOG_ID_RADIO = 1, LOG_ID_EVENTS = 2, LOG_ID_SYSTEM = 3, + LOG_ID_CRASH = 4, LOG_ID_MAX } log_id_t; diff --git a/liblog/log_read.c b/liblog/log_read.c index 15be748f4..0ff94bff1 100644 --- a/liblog/log_read.c +++ b/liblog/log_read.c @@ -196,7 +196,8 @@ static const char *LOG_NAME[LOG_ID_MAX] = { [LOG_ID_MAIN] = "main", [LOG_ID_RADIO] = "radio", [LOG_ID_EVENTS] = "events", - [LOG_ID_SYSTEM] = "system" + [LOG_ID_SYSTEM] = "system", + [LOG_ID_CRASH] = "crash", }; const char *android_log_id_to_name(log_id_t log_id) diff --git a/liblog/log_read_kern.c b/liblog/log_read_kern.c index d9a6b2e22..021fe476e 100644 --- a/liblog/log_read_kern.c +++ b/liblog/log_read_kern.c @@ -58,7 +58,8 @@ static const char *LOG_NAME[LOG_ID_MAX] = { [LOG_ID_MAIN] = "main", [LOG_ID_RADIO] = "radio", [LOG_ID_EVENTS] = "events", - [LOG_ID_SYSTEM] = "system" + [LOG_ID_SYSTEM] = "system", + [LOG_ID_CRASH] = "crash" }; const char *android_log_id_to_name(log_id_t log_id) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 9c73dade2..94722d3a4 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -54,7 +54,7 @@ static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; static int logd_fd = -1; #if FAKE_LOG_DEVICE #define WEAK __attribute__((weak)) -static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 }; +static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 }; #endif /* @@ -243,7 +243,8 @@ static const char *LOG_NAME[LOG_ID_MAX] = { [LOG_ID_MAIN] = "main", [LOG_ID_RADIO] = "radio", [LOG_ID_EVENTS] = "events", - [LOG_ID_SYSTEM] = "system" + [LOG_ID_SYSTEM] = "system", + [LOG_ID_CRASH] = "crash" }; const WEAK char *android_log_id_to_name(log_id_t log_id) diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 5ef349b02..c29c28f2d 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -93,6 +93,9 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr) int log_fd; if (/*(int)log_id >= 0 &&*/ (int)log_id < (int)LOG_ID_MAX) { + if (log_id == LOG_ID_CRASH) { + log_id = LOG_ID_MAIN; + } log_fd = log_fds[(int)log_id]; } else { return -EBADF; diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index ca972087a..995a42e07 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -227,8 +227,9 @@ static void show_help(const char *cmd) " -T print only the most recent lines (does not imply -d)\n" " -g get the size of the log's ring buffer and exit\n" " -b Request alternate ring buffer, 'main', 'system', 'radio',\n" - " 'events' or 'all'. Multiple -b parameters are allowed and\n" - " results are interleaved. The default is -b main -b system.\n" + " 'events', 'crash' or 'all'. Multiple -b parameters are\n" + " allowed and results are interleaved. The default is\n" + " -b main -b system -b crash.\n" " -B output the log in binary.\n" " -S output statistics.\n" " -G set size of log ring buffer, may suffix with K or M.\n" @@ -447,10 +448,17 @@ int main(int argc, char **argv) if (android_name_to_log_id("events") == LOG_ID_EVENTS) { dev->next = new log_device_t("events", true, 'e'); if (dev->next) { + dev = dev->next; android::g_devCount++; needBinary = true; } } + if (android_name_to_log_id("crash") == LOG_ID_CRASH) { + dev->next = new log_device_t("crash", false, 'c'); + if (dev->next) { + android::g_devCount++; + } + } break; } @@ -607,6 +615,14 @@ int main(int argc, char **argv) devices->next = new log_device_t("system", false, 's'); android::g_devCount++; } + if (android_name_to_log_id("crash") == LOG_ID_CRASH) { + if (devices->next) { + devices->next->next = new log_device_t("crash", false, 'c'); + } else { + devices->next = new log_device_t("crash", false, 'c'); + } + android::g_devCount++; + } } if (android::g_logRotateSizeKBytes != 0 diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 70f3e9194..8dcab87fd 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -165,7 +165,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows) { size_t worst_sizes = 0; size_t second_worst_sizes = 0; - if (mPrune.worstUidEnabled()) { + if ((id != LOG_ID_CRASH) && mPrune.worstUidEnabled()) { LidStatistics &l = stats.id(id); UidStatisticsCollection::iterator iu; for (iu = l.begin(); iu != l.end(); ++iu) { diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index 70f8fe951..9ad897384 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp @@ -31,7 +31,7 @@ */ static void my_android_logger_get_statistics(char *buf, size_t len) { - snprintf(buf, len, "getStatistics 0 1 2 3"); + snprintf(buf, len, "getStatistics 0 1 2 3 4"); int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM);