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

Commit a62ae51b authored by Yao Chen's avatar Yao Chen Committed by Android (Google) Code Review
Browse files

Merge "Add cmd to let statsd print all logs it received for debugging." into pi-dev

parents dcd71294 876889cb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -141,10 +141,12 @@ LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries) \

LOCAL_MODULE_CLASS := EXECUTABLES

# Enable sanitizer on eng builds
# Enable sanitizer and allow very verbose printing on eng builds
ifeq ($(TARGET_BUILD_VARIANT),eng)
    LOCAL_CLANG := true
    LOCAL_SANITIZE := address
    LOCAL_CFLAGS += \
        -DVERY_VERBOSE_PRINTING
endif

LOCAL_INIT_RC := statsd.rc
+6 −0
Original line number Diff line number Diff line
@@ -177,6 +177,12 @@ void StatsLogProcessor::resetConfigsLocked(const int64_t timestampNs) {

void StatsLogProcessor::OnLogEvent(LogEvent* event, bool reconnected) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);

#ifdef VERY_VERBOSE_PRINTING
    if (mPrintAllLogs) {
        ALOGI("%s", event->ToString().c_str());
    }
#endif
    const int64_t currentTimestampNs = event->GetElapsedTimestampNs();

    if (reconnected && mLastTimestampSeen != 0) {
+11 −0
Original line number Diff line number Diff line
@@ -92,6 +92,13 @@ public:

    int64_t getLastReportTimeNs(const ConfigKey& key);

    inline void setPrintLogs(bool enabled) {
#ifdef VERY_VERBOSE_PRINTING
        std::lock_guard<std::mutex> lock(mMetricsMutex);
        mPrintAllLogs = enabled;
#endif
    }

private:
    // For testing only.
    inline sp<AlarmMonitor> getAnomalyAlarmMonitor() const {
@@ -171,6 +178,10 @@ private:

    long mLastPullerCacheClearTimeSec = 0;

#ifdef VERY_VERBOSE_PRINTING
    bool mPrintAllLogs = false;
#endif

    FRIEND_TEST(StatsLogProcessorTest, TestOutOfOrderLogs);
    FRIEND_TEST(StatsLogProcessorTest, TestRateLimitByteSize);
    FRIEND_TEST(StatsLogProcessorTest, TestRateLimitBroadcast);
+23 −0
Original line number Diff line number Diff line
@@ -334,6 +334,10 @@ status_t StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>&
        if (!args[0].compare(String8("clear-puller-cache"))) {
            return cmd_clear_puller_cache(out);
        }

        if (!args[0].compare(String8("print-logs"))) {
            return cmd_print_logs(out, args);
        }
    }

    print_cmd_help(out);
@@ -419,6 +423,9 @@ void StatsService::print_cmd_help(FILE* out) {
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd stats clear-puller-cache\n");
    fprintf(out, "  Clear cached puller data.\n");
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd stats print-logs\n");
    fprintf(out, "      Only works on eng build\n");
}

status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) {
@@ -738,6 +745,22 @@ status_t StatsService::cmd_clear_puller_cache(FILE* out) {
    }
}

status_t StatsService::cmd_print_logs(FILE* out, const Vector<String8>& args) {
    IPCThreadState* ipc = IPCThreadState::self();
    VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", ipc->getCallingPid(),
         ipc->getCallingUid());
    if (checkCallingPermission(String16(kPermissionDump))) {
        bool enabled = true;
        if (args.size() >= 2) {
            enabled = atoi(args[1].c_str()) != 0;
        }
        mProcessor->setPrintLogs(enabled);
        return NO_ERROR;
    } else {
        return PERMISSION_DENIED;
    }
}

Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version,
                                      const vector<String16>& app) {
    ENFORCE_UID(AID_SYSTEM);
+5 −0
Original line number Diff line number Diff line
@@ -220,6 +220,11 @@ private:
     */
    status_t cmd_clear_puller_cache(FILE* out);

    /**
     * Print all stats logs received to logcat.
     */
    status_t cmd_print_logs(FILE* out, const Vector<String8>& args);

    /**
     * Adds a configuration after checking permissions and obtaining UID from binder call.
     */