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

Commit c51ec676 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ib254db7e,I4aa0539a

* changes:
  Anomaly Alert declarations in StatsdStats
  Anomaly detection statsdstats
parents 2514d1ca 8f2f3d82
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ void CompanionDeathRecipient::binderDied(const wp<IBinder>& who) {

// ======================================================================
StatsService::StatsService(const sp<Looper>& handlerLooper)
    : mAnomalyMonitor(new AnomalyMonitor(2))  // TODO: Put this comment somewhere better
    : mAnomalyMonitor(new AnomalyMonitor(MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS))
{
    mUidMap = new UidMap();
    mConfigManager = new ConfigManager();
+4 −0
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ public:
    StatsService(const sp<Looper>& handlerLooper);
    virtual ~StatsService();

    /** The anomaly alarm registered with AlarmManager won't be updated by less than this. */
    // TODO: Consider making this configurable. And choose a good number.
    const uint32_t MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS = 5;

    virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
    virtual status_t dump(int fd, const Vector<String16>& args);
    virtual status_t command(FILE* in, FILE* out, FILE* err, Vector<String8>& args);
+13 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "Log.h"

#include "anomaly/AnomalyMonitor.h"
#include "guardrail/StatsdStats.h"

namespace android {
namespace os {
@@ -76,10 +77,7 @@ void AnomalyMonitor::remove(sp<const AnomalyAlarm> alarm) {
    if (!wasPresent) return;
    if (mPq.empty()) {
        if (DEBUG) ALOGD("Queue is empty. Cancel any alarm.");
        mRegisteredAlarmTimeSec = 0;
        if (mStatsCompanionService != nullptr) {
            mStatsCompanionService->cancelAnomalyAlarm();
        }
        cancelRegisteredAlarmTime_l();
        return;
    }
    uint32_t soonestAlarmTimeSec = mPq.top()->timestampSec;
@@ -106,10 +104,7 @@ unordered_set<sp<const AnomalyAlarm>, SpHash<AnomalyAlarm>> AnomalyMonitor::popS
    if (!oldAlarms.empty()) {
        if (mPq.empty()) {
            if (DEBUG) ALOGD("Queue is empty. Cancel any alarm.");
            mRegisteredAlarmTimeSec = 0;
            if (mStatsCompanionService != nullptr) {
                mStatsCompanionService->cancelAnomalyAlarm();
            }
            cancelRegisteredAlarmTime_l();
        } else {
            // Always update the registered alarm in this case (unlike remove()).
            updateRegisteredAlarmTime_l(mPq.top()->timestampSec);
@@ -123,6 +118,16 @@ void AnomalyMonitor::updateRegisteredAlarmTime_l(uint32_t timestampSec) {
    mRegisteredAlarmTimeSec = timestampSec;
    if (mStatsCompanionService != nullptr) {
        mStatsCompanionService->setAnomalyAlarm(secToMs(mRegisteredAlarmTimeSec));
        StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
    }
}

void AnomalyMonitor::cancelRegisteredAlarmTime_l() {
    if (DEBUG) ALOGD("Cancelling reg alarm.");
    mRegisteredAlarmTimeSec = 0;
    if (mStatsCompanionService != nullptr) {
        mStatsCompanionService->cancelAnomalyAlarm();
        StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
    }
}

+6 −0
Original line number Diff line number Diff line
@@ -138,6 +138,12 @@ private:
     */
    void updateRegisteredAlarmTime_l(uint32_t timestampSec);

    /**
     * Cancels the alarm registered with StatsCompanionService.
     * Also correspondingly sets mRegisteredAlarmTimeSec to 0.
     */
    void cancelRegisteredAlarmTime_l();

    /** Converts uint32 timestamp in seconds to a Java long in msec. */
    int64_t secToMs(uint32_t timeSec);
};
+5 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "Log.h"

#include "AnomalyTracker.h"
#include "guardrail/StatsdStats.h"

#include <android/os/IIncidentManager.h>
#include <android/os/IncidentReportArgs.h>
@@ -31,8 +32,9 @@ namespace statsd {
// TODO: Separate DurationAnomalyTracker as a separate subclass and let each MetricProducer
//       decide and let which one it wants.
// TODO: Get rid of bucketNumbers, and return to the original circular array method.
AnomalyTracker::AnomalyTracker(const Alert& alert)
AnomalyTracker::AnomalyTracker(const Alert& alert, const ConfigKey& configKey)
    : mAlert(alert),
      mConfigKey(configKey),
      mNumOfPastBuckets(mAlert.number_of_buckets() - 1) {
    VLOG("AnomalyTracker() called");
    if (mAlert.number_of_buckets() <= 0) {
@@ -220,6 +222,8 @@ void AnomalyTracker::declareAnomaly(const uint64_t& timestampNs) {
    } else {
        ALOGW("An anomaly has occurred! (But informing incidentd not requested.)");
    }

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

void AnomalyTracker::declareAnomalyIfAlarmExpired(const HashableDimensionKey& dimensionKey,
Loading