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

Commit d6896898 authored by David Chen's avatar David Chen
Browse files

Updates uidmap to update snapshots and upload.

We send a snapshot of all installed apps with their uids every time
a user is added or removed and when statsd is started.
We keep track of the latest timestamp when a config key has retrieved
the UID map data. This allows us to remove older data when we're
guaranteed that all config sources have retrieved the old data.

Test: Added more unit tests to UidMap_test and passed on marlin-eng.
Change-Id: I34a3d61e75eedec44b98d896d7f6db0bc383f46a
parent 2141c451
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static
LOCAL_AIDL_INCLUDES := $(statsd_common_aidl_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)

LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries)
LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries) \
    libgtest_prod

LOCAL_MODULE_CLASS := EXECUTABLES

+18 −3
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ void StatsLogProcessor::OnConfigUpdated(const ConfigKey& key, const StatsdConfig

    unique_ptr<MetricsManager> newMetricsManager = std::make_unique<MetricsManager>(config);
    if (newMetricsManager->isConfigValid()) {
        mUidMap->OnConfigUpdated(key);
        mMetricsManagers[key] = std::move(newMetricsManager);
        // Why doesn't this work? mMetricsManagers.insert({key, std::move(newMetricsManager)});
        ALOGD("StatsdConfig valid");
@@ -69,14 +70,27 @@ void StatsLogProcessor::OnConfigUpdated(const ConfigKey& key, const StatsdConfig
    }
}

vector<StatsLogReport> StatsLogProcessor::onDumpReport(const ConfigKey& key) {
ConfigMetricsReport StatsLogProcessor::onDumpReport(const ConfigKey& key) {
    ConfigMetricsReport report;

    auto it = mMetricsManagers.find(key);
    if (it == mMetricsManagers.end()) {
        ALOGW("Config source %s does not exist", key.ToString().c_str());
        return vector<StatsLogReport>();
        return report;
    }

    return it->second->onDumpReport();
    auto set_key = report.mutable_config_key();
    set_key->set_uid(key.GetUid());
    set_key->set_name(key.GetName());
    for (auto m : it->second->onDumpReport()) {
        // Transfer the vector of StatsLogReport into a field
        // TODO: perhaps we just have bytes being returned from onDumpReport and transfer bytes
        auto dest = report.add_metrics();
        *dest = m;
    }
    auto temp = mUidMap->getOutput(key);
    report.set_allocated_uid_map(&temp);
    return report;
}

void StatsLogProcessor::OnConfigRemoved(const ConfigKey& key) {
@@ -84,6 +98,7 @@ void StatsLogProcessor::OnConfigRemoved(const ConfigKey& key) {
    if (it != mMetricsManagers.end()) {
        it->second->finish();
        mMetricsManagers.erase(it);
        mUidMap->OnConfigRemoved(key);
    }
    auto flushTime = mLastFlushTimes.find(key);
    if (flushTime != mLastFlushTimes.end()) {
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public:
    void OnConfigRemoved(const ConfigKey& key);

    // TODO: Once we have the ProtoOutputStream in c++, we can just return byte array.
    std::vector<StatsLogReport> onDumpReport(const ConfigKey& key);
    ConfigMetricsReport onDumpReport(const ConfigKey& key);

    /* Request a flush through a binder call. */
    void flush();
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public:

    // TODO: Implement this later.
    virtual void notifyAppUpgrade(const string& apk, const int uid, const int version) override{};
    // TODO: Implement this later.
    virtual void notifyAppRemoved(const string& apk, const int uid) override{};

protected:
    void onMatchedLogEventInternal(const size_t matcherIndex, const HashableDimensionKey& eventKey,
+2 −0
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ public:

    // TODO: Implement this later.
    virtual void notifyAppUpgrade(const string& apk, const int uid, const int version) override{};
    // TODO: Implement this later.
    virtual void notifyAppRemoved(const string& apk, const int uid) override{};

protected:
    void onMatchedLogEventInternal(const size_t matcherIndex, const HashableDimensionKey& eventKey,
Loading