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

Commit 8fcd09a3 authored by Bookatz's avatar Bookatz
Browse files

Statsd anomaly detection atom

Creates an atom to represent when statsd's anomaly detection alert
fires, so that statsd can log when it detects an anomaly (in the output
and for any further processing).

Test: manually confirmed that atom was logged
Change-Id: I3376e4038bdc3402a536aab7cebad24b104a9aee
parent 112d5f09
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <android/os/IIncidentManager.h>
#include <android/os/IncidentReportArgs.h>
#include <binder/IServiceManager.h>
#include <statslog.h>
#include <time.h>

namespace android {
@@ -224,6 +225,9 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) {
    }

    StatsdStats::getInstance().noteAnomalyDeclared(mConfigKey, mAlert.name());

    android::util::stats_write(android::util::ANOMALY_DETECTED, mConfigKey.GetUid(),
                               mConfigKey.GetName().c_str(), mAlert.name().c_str());
}

void AnomalyTracker::declareAnomalyIfAlarmExpired(const HashableDimensionKey& dimensionKey,
+19 −1
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ message Atom {
        IsolatedUidChanged isolated_uid_changed = 43;
        PacketWakeupOccurred packet_wakeup_occurred = 44;
        DropboxErrorChanged dropbox_error_changed = 45;
        AppHook app_hook = 46;
        AnomalyDetected anomaly_detected = 46;
        AppHook app_hook = 47;
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }

@@ -840,6 +841,23 @@ message AppHook {
    optional State state = 3;
}

/**
 * Logs when statsd detects an anomaly.
 *
 * Logged from:
 *   frameworks/base/cmds/statsd/src/anomaly/AnomalyTracker.cpp
 */
message AnomalyDetected {
    // Uid that owns the config whose anomaly detection alert fired.
    optional int32 config_uid = 1;

    // Name of the config whose anomaly detection alert fired.
    optional string config_name = 2;

    // Name of the alert (i.e. name of the anomaly that was detected).
    optional string alert_name = 3;
}

/**
 * Pulls bytes transferred via wifi (Sum of foreground and background usage).
 *