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

Commit b738f2ad authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4731145 from 3e180afa to pi-release

Change-Id: I8d21f4bb5274f9ec30e0f097037295914e5b6f5f
parents 066cfc50 3e180afa
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ const int FIELD_ID_LAST_REPORT_ELAPSED_NANOS = 3;
const int FIELD_ID_CURRENT_REPORT_ELAPSED_NANOS = 4;
const int FIELD_ID_LAST_REPORT_WALL_CLOCK_NANOS = 5;
const int FIELD_ID_CURRENT_REPORT_WALL_CLOCK_NANOS = 6;
const int FIELD_ID_DUMP_REPORT_REASON = 8;

#define NS_PER_HOUR 3600 * NS_PER_SEC

@@ -183,7 +184,7 @@ void StatsLogProcessor::OnLogEvent(LogEvent* event, bool reconnected) {
            mInReconnection = false;
            StatsdStats::getInstance().noteLogLost(currentTimestampNs);
            // Persist the data before we reset. Do we want this?
            WriteDataToDiskLocked();
            WriteDataToDiskLocked(CONFIG_RESET);
            // We see fresher event before we see the checkpoint. We might have lost data.
            // The best we can do is to reset.
            std::vector<ConfigKey> configKeys;
@@ -251,7 +252,7 @@ void StatsLogProcessor::OnConfigUpdatedLocked(
                           mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
    auto it = mMetricsManagers.find(key);
    if (it != mMetricsManagers.end()) {
        WriteDataToDiskLocked(it->first);
        WriteDataToDiskLocked(it->first, CONFIG_UPDATED);
    }
    if (newMetricsManager->isConfigValid()) {
        mUidMap->OnConfigUpdated(key);
@@ -292,6 +293,7 @@ void StatsLogProcessor::dumpStates(FILE* out, bool verbose) {
 */
void StatsLogProcessor::onDumpReport(const ConfigKey& key, const int64_t dumpTimeStampNs,
                                     const bool include_current_partial_bucket,
                                     const DumpReportReason dumpReportReason,
                                     vector<uint8_t>* outData) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);

@@ -317,7 +319,8 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, const int64_t dumpTim
        // Start of ConfigMetricsReport (reports).
        uint64_t reportsToken =
                proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS);
        onConfigMetricsReportLocked(key, dumpTimeStampNs, include_current_partial_bucket, &proto);
        onConfigMetricsReportLocked(key, dumpTimeStampNs, include_current_partial_bucket,
                                    dumpReportReason, &proto);
        proto.end(reportsToken);
        // End of ConfigMetricsReport (reports).
    } else {
@@ -346,6 +349,7 @@ void StatsLogProcessor::onDumpReport(const ConfigKey& key, const int64_t dumpTim
void StatsLogProcessor::onConfigMetricsReportLocked(const ConfigKey& key,
                                                    const int64_t dumpTimeStampNs,
                                                    const bool include_current_partial_bucket,
                                                    const DumpReportReason dumpReportReason,
                                                    ProtoOutputStream* proto) {
    // We already checked whether key exists in mMetricsManagers in
    // WriteDataToDisk.
@@ -374,6 +378,8 @@ void StatsLogProcessor::onConfigMetricsReportLocked(const ConfigKey& key,
                (long long)lastReportWallClockNs);
    proto->write(FIELD_TYPE_INT64 | FIELD_ID_CURRENT_REPORT_WALL_CLOCK_NANOS,
                (long long)getWallClockNs());
    // Dump report reason
    proto->write(FIELD_TYPE_INT32 | FIELD_ID_DUMP_REPORT_REASON, dumpReportReason);
}

void StatsLogProcessor::resetConfigsLocked(const int64_t timestampNs,
@@ -409,7 +415,7 @@ void StatsLogProcessor::OnConfigRemoved(const ConfigKey& key) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);
    auto it = mMetricsManagers.find(key);
    if (it != mMetricsManagers.end()) {
        WriteDataToDiskLocked(key);
        WriteDataToDiskLocked(key, CONFIG_REMOVED);
        mMetricsManagers.erase(it);
        mUidMap->OnConfigRemoved(key);
    }
@@ -455,10 +461,11 @@ void StatsLogProcessor::flushIfNecessaryLocked(
    }
}

void StatsLogProcessor::WriteDataToDiskLocked(const ConfigKey& key) {
void StatsLogProcessor::WriteDataToDiskLocked(const ConfigKey& key,
                                              const DumpReportReason dumpReportReason) {
    ProtoOutputStream proto;
    onConfigMetricsReportLocked(key, getElapsedRealtimeNs(),
                                true /* include_current_partial_bucket*/, &proto);
                                true /* include_current_partial_bucket*/, dumpReportReason, &proto);
    string file_name = StringPrintf("%s/%ld_%d_%lld", STATS_DATA_DIR,
         (long)getWallClockSec(), key.GetUid(), (long long)key.GetId());
    android::base::unique_fd fd(open(file_name.c_str(),
@@ -470,15 +477,15 @@ void StatsLogProcessor::WriteDataToDiskLocked(const ConfigKey& key) {
    proto.flush(fd.get());
}

void StatsLogProcessor::WriteDataToDiskLocked() {
void StatsLogProcessor::WriteDataToDiskLocked(const DumpReportReason dumpReportReason) {
    for (auto& pair : mMetricsManagers) {
        WriteDataToDiskLocked(pair.first);
        WriteDataToDiskLocked(pair.first, dumpReportReason);
    }
}

void StatsLogProcessor::WriteDataToDisk() {
void StatsLogProcessor::WriteDataToDisk(bool isShutdown) {
    std::lock_guard<std::mutex> lock(mMetricsMutex);
    WriteDataToDiskLocked();
    WriteDataToDiskLocked(DEVICE_SHUTDOWN);
}

void StatsLogProcessor::informPullAlarmFired(const int64_t timestampNs) {
+17 −4
Original line number Diff line number Diff line
@@ -32,6 +32,17 @@ namespace android {
namespace os {
namespace statsd {

// Keep this in sync with DumpReportReason enum in stats_log.proto
enum DumpReportReason {
    DEVICE_SHUTDOWN = 1,
    CONFIG_UPDATED = 2,
    CONFIG_REMOVED = 3,
    GET_DATA_CALLED = 4,
    ADB_DUMP = 5,
    CONFIG_RESET = 6,
    STATSCOMPANION_DIED = 7
};

class StatsLogProcessor : public ConfigListener {
public:
    StatsLogProcessor(const sp<UidMap>& uidMap, const sp<AlarmMonitor>& anomalyAlarmMonitor,
@@ -52,7 +63,8 @@ public:
    size_t GetMetricsSize(const ConfigKey& key) const;

    void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs,
                      const bool include_current_partial_bucket, vector<uint8_t>* outData);
                      const bool include_current_partial_bucket,
                      const DumpReportReason dumpReportReason, vector<uint8_t>* outData);

    /* Tells MetricsManager that the alarms in alarmSet have fired. Modifies anomaly alarmSet. */
    void onAnomalyAlarmFired(
@@ -65,7 +77,7 @@ public:
            unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet);

    /* Flushes data to disk. Data on memory will be gone after written to disk. */
    void WriteDataToDisk();
    void WriteDataToDisk(bool shutdown);

    inline sp<UidMap> getUidMap() {
        return mUidMap;
@@ -109,11 +121,12 @@ private:
    void OnConfigUpdatedLocked(
        const int64_t currentTimestampNs, const ConfigKey& key, const StatsdConfig& config);

    void WriteDataToDiskLocked();
    void WriteDataToDiskLocked(const ConfigKey& key);
    void WriteDataToDiskLocked(DumpReportReason dumpReportReason);
    void WriteDataToDiskLocked(const ConfigKey& key, DumpReportReason dumpReportReason);

    void onConfigMetricsReportLocked(const ConfigKey& key, const int64_t dumpTimeStampNs,
                                     const bool include_current_partial_bucket,
                                     const DumpReportReason dumpReportReason,
                                     util::ProtoOutputStream* proto);

    /* Check if we should send a broadcast if approaching memory limits and if we're over, we
+8 −9
Original line number Diff line number Diff line
@@ -592,7 +592,7 @@ status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String
        if (good) {
            vector<uint8_t> data;
            mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(),
                                     false /* include_current_bucket*/, &data);
                                     false /* include_current_bucket*/, ADB_DUMP, &data);
            // TODO: print the returned StatsLogReport to file instead of printing to logcat.
            if (proto) {
                for (size_t i = 0; i < data.size(); i ++) {
@@ -658,7 +658,7 @@ status_t StatsService::cmd_print_uid_map(FILE* out, const Vector<String8>& args)

status_t StatsService::cmd_write_data_to_disk(FILE* out) {
    fprintf(out, "Writing data to disk\n");
    mProcessor->WriteDataToDisk();
    mProcessor->WriteDataToDisk(false);
    return NO_ERROR;
}

@@ -815,11 +815,10 @@ Status StatsService::systemRunning() {
    return Status::ok();
}

Status StatsService::writeDataToDisk() {
Status StatsService::informDeviceShutdown(bool isShutdown) {
    ENFORCE_UID(AID_SYSTEM);

    VLOG("StatsService::writeDataToDisk");
    mProcessor->WriteDataToDisk();
    VLOG("StatsService::informDeviceShutdown");
    mProcessor->WriteDataToDisk(isShutdown);
    return Status::ok();
}

@@ -866,8 +865,8 @@ Status StatsService::getData(int64_t key, const String16& packageName, vector<ui
    IPCThreadState* ipc = IPCThreadState::self();
    VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
    ConfigKey configKey(ipc->getCallingUid(), key);
    mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(),
                             false /* include_current_bucket*/, output);
    mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), false /* include_current_bucket*/,
                             GET_DATA_CALLED, output);
    return Status::ok();
}

@@ -966,7 +965,7 @@ Status StatsService::unsetBroadcastSubscriber(int64_t configId,

void StatsService::binderDied(const wp <IBinder>& who) {
    ALOGW("statscompanion service died");
    mProcessor->WriteDataToDisk();
    mProcessor->WriteDataToDisk(STATSCOMPANION_DIED);
    mAnomalyAlarmMonitor->setStatsCompanionService(nullptr);
    mPeriodicAlarmMonitor->setStatsCompanionService(nullptr);
    SubscriberReporter::getInstance().setStatsCompanionService(nullptr);
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public:
                                    const vector<String16>& app);
    virtual Status informOnePackage(const String16& app, int32_t uid, int64_t version);
    virtual Status informOnePackageRemoved(const String16& app, int32_t uid);
    virtual Status writeDataToDisk();
    virtual Status informDeviceShutdown(bool isShutdown);

    /**
     * Called right before we start processing events.
+12 −7
Original line number Diff line number Diff line
@@ -112,10 +112,13 @@ void mergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<Uid
        VLOG("Unknown pull atom id %d", tagId);
        return;
    }
    if (android::util::AtomsInfo::kAtomsWithUidField.find(tagId) ==
        android::util::AtomsInfo::kAtomsWithUidField.end()) {
    int uidField;
    auto it = android::util::AtomsInfo::kAtomsWithUidField.find(tagId);
    if (it == android::util::AtomsInfo::kAtomsWithUidField.end()) {
        VLOG("No uid to merge for atom %d", tagId);
        return;
    } else {
        uidField = it->second;  // uidField is the field number in proto,
    }
    const vector<int>& additiveFields =
            StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId)->second.additiveFields;
@@ -129,11 +132,13 @@ void mergeIsolatedUidsToHostUid(vector<shared_ptr<LogEvent>>& data, const sp<Uid
    for (size_t i = 0; i < data.size(); i++) {
        vector<FieldValue>* valueList = data[i]->getMutableValues();

        int err = 0;
        int uid = data[i]->GetInt(1, &err);
        if (err != 0) {
            VLOG("Bad uid field for %s", data[i]->ToString().c_str());
            return;
        int uid;
        if (uidField > 0 && (int)data[i]->getValues().size() >= uidField &&
            (data[i]->getValues())[uidField - 1].mValue.getType() == INT) {
            uid = (*data[i]->getMutableValues())[uidField - 1].mValue.int_value;
        } else {
            ALOGE("Malformed log, uid not found. %s", data[i]->ToString().c_str());
            continue;
        }

        const int hostUid = uidMap->getHostUidOrSelf(uid);
Loading