diff options
-rw-r--r-- | cmds/incidentd/src/Section.cpp | 30 | ||||
-rw-r--r-- | cmds/incidentd/src/Section.h | 6 | ||||
-rw-r--r-- | core/proto/android/os/incident.proto | 54 | ||||
-rw-r--r-- | tools/incident_section_gen/main.cpp | 4 |
4 files changed, 77 insertions, 17 deletions
diff --git a/cmds/incidentd/src/Section.cpp b/cmds/incidentd/src/Section.cpp index f476fcf91bd5..0176f8047974 100644 --- a/cmds/incidentd/src/Section.cpp +++ b/cmds/incidentd/src/Section.cpp @@ -476,10 +476,27 @@ status_t DumpsysSection::BlockingCall(int pipeWriteFd) const { // initialization only once in Section.cpp. map<log_id_t, log_time> LogSection::gLastLogsRetrieved; -LogSection::LogSection(int id, log_id_t logID) : WorkerThreadSection(id), mLogID(logID) { - name = "logcat "; - name += android_log_id_to_name(logID); - switch (logID) { +LogSection::LogSection(int id, const char* logID, ...) : WorkerThreadSection(id), mLogMode(logModeBase) { + name = "logcat -b "; + name += logID; + + va_list args; + va_start(args, logID); + mLogID = android_name_to_log_id(logID); + while(true) { + const char* arg = va_arg(args, const char*); + if (arg == NULL) { + break; + } + if (!strcmp(arg, "-L")) { + // Read from last logcat buffer + mLogMode = mLogMode | ANDROID_LOG_PSTORE; + } + name += " "; + name += arg; + } + + switch (mLogID) { case LOG_ID_EVENTS: case LOG_ID_STATS: case LOG_ID_SECURITY: @@ -512,9 +529,8 @@ status_t LogSection::BlockingCall(int pipeWriteFd) const { // Open log buffer and getting logs since last retrieved time if any. unique_ptr<logger_list, void (*)(logger_list*)> loggers( gLastLogsRetrieved.find(mLogID) == gLastLogsRetrieved.end() - ? android_logger_list_alloc(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, 0) - : android_logger_list_alloc_time(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, - gLastLogsRetrieved[mLogID], 0), + ? android_logger_list_alloc(mLogMode, 0, 0) + : android_logger_list_alloc_time(mLogMode, gLastLogsRetrieved[mLogID], 0), android_logger_list_free); if (android_logger_open(loggers.get(), mLogID) == NULL) { diff --git a/cmds/incidentd/src/Section.h b/cmds/incidentd/src/Section.h index c9b80563a609..fcf12f7336fd 100644 --- a/cmds/incidentd/src/Section.h +++ b/cmds/incidentd/src/Section.h @@ -146,8 +146,11 @@ class LogSection : public WorkerThreadSection { // global last log retrieved timestamp for each log_id_t. static map<log_id_t, log_time> gLastLogsRetrieved; + // log mode: read only & non blocking. + const static int logModeBase = ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK; + public: - LogSection(int id, log_id_t logID); + LogSection(int id, const char* logID, ...); virtual ~LogSection(); virtual status_t BlockingCall(int pipeWriteFd) const; @@ -155,6 +158,7 @@ public: private: log_id_t mLogID; bool mBinary; + int mLogMode; }; /** diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto index 7d0629ee6fba..db65352da3e9 100644 --- a/core/proto/android/os/incident.proto +++ b/core/proto/android/os/incident.proto @@ -87,42 +87,80 @@ message IncidentProto { optional android.util.LogProto main_logs = 1101 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_MAIN" + (section).args = "main" ]; optional android.util.LogProto radio_logs = 1102 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_RADIO" + (section).args = "radio" ]; optional android.util.LogProto events_logs = 1103 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_EVENTS" + (section).args = "events" ]; optional android.util.LogProto system_logs = 1104 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_SYSTEM" + (section).args = "system" ]; optional android.util.LogProto crash_logs = 1105 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_CRASH" + (section).args = "crash" ]; optional android.util.LogProto stats_logs = 1106 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_STATS" + (section).args = "stats" ]; optional android.util.LogProto security_logs = 1107 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_SECURITY" + (section).args = "security" ]; optional android.util.LogProto kernel_logs = 1108 [ (section).type = SECTION_LOG, - (section).args = "LOG_ID_KERNEL" + (section).args = "kernel" + ]; + + // Last logcat sections. + // Note that kernel logs is not persisted since it's contained in last kmsg. + optional android.util.LogProto last_main_logs = 1109 [ + (section).type = SECTION_LOG, + (section).args = "main -L" + ]; + + optional android.util.LogProto last_radio_logs = 1110 [ + (section).type = SECTION_LOG, + (section).args = "radio -L" + ]; + + optional android.util.LogProto last_events_logs = 1111 [ + (section).type = SECTION_LOG, + (section).args = "events -L" + ]; + + optional android.util.LogProto last_system_logs = 1112 [ + (section).type = SECTION_LOG, + (section).args = "system -L" + ]; + + optional android.util.LogProto last_crash_logs = 1113 [ + (section).type = SECTION_LOG, + (section).args = "crash -L" + ]; + + optional android.util.LogProto last_stats_logs = 1114 [ + (section).type = SECTION_LOG, + (section).args = "stats -L" + ]; + + // security logs is only available with "Device Owner" mode + optional android.util.LogProto last_security_logs = 1115 [ + (section).type = SECTION_LOG, + (section).args = "security -L" ]; // Stack dumps diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp index 91f875ed9918..ded4b916c452 100644 --- a/tools/incident_section_gen/main.cpp +++ b/tools/incident_section_gen/main.cpp @@ -436,7 +436,9 @@ static bool generateSectionListCpp(Descriptor const* descriptor) { printf(" NULL),\n"); break; case SECTION_LOG: - printf(" new LogSection(%d, %s),\n", field->number(), s.args().c_str()); + printf(" new LogSection(%d, ", field->number()); + splitAndPrint(s.args()); + printf(" NULL),\n"); break; case SECTION_GZIP: printf(" new GZipSection(%d,", field->number()); |