Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c1dd67d authored by Wenjie Zhou's avatar Wenjie Zhou Committed by Android (Google) Code Review
Browse files

Merge "Add last logcat data to incident report"

parents 62bcfb93 c3bf8040
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -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) {
+5 −1
Original line number Diff line number Diff line
@@ -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;
};

/**
+46 −8
Original line number Diff line number Diff line
@@ -88,42 +88,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
+3 −1
Original line number Diff line number Diff line
@@ -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());