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

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

Merge "Wean statsd off batterystats: workchain, longPW"

parents 22e64ec6 d888df2b
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -4573,10 +4573,6 @@ public class BatteryStatsImpl extends BatteryStats {
    }
    public void noteLongPartialWakelockStart(String name, String historyName, int uid) {
        StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                uid, null, name, historyName,
                StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON);
        uid = mapUid(uid);
        noteLongPartialWakeLockStartInternal(name, historyName, uid);
    }
@@ -4587,9 +4583,6 @@ public class BatteryStatsImpl extends BatteryStats {
        for (int i = 0; i < N; ++i) {
            final int uid = mapUid(workSource.get(i));
            noteLongPartialWakeLockStartInternal(name, historyName, uid);
            StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                    workSource.get(i), workSource.getName(i), name, historyName,
                    StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON);
        }
        final ArrayList<WorkChain> workChains = workSource.getWorkChains();
@@ -4598,10 +4591,6 @@ public class BatteryStatsImpl extends BatteryStats {
                final WorkChain workChain = workChains.get(i);
                final int uid = workChain.getAttributionUid();
                noteLongPartialWakeLockStartInternal(name, historyName, uid);
                StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                        workChain.getUids(), workChain.getTags(), name, historyName,
                        StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON);
            }
        }
    }
@@ -4621,9 +4610,6 @@ public class BatteryStatsImpl extends BatteryStats {
    }
    public void noteLongPartialWakelockFinish(String name, String historyName, int uid) {
        StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, uid, null,
                name, historyName, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF);
        uid = mapUid(uid);
        noteLongPartialWakeLockFinishInternal(name, historyName, uid);
    }
@@ -4634,9 +4620,6 @@ public class BatteryStatsImpl extends BatteryStats {
        for (int i = 0; i < N; ++i) {
            final int uid = mapUid(workSource.get(i));
            noteLongPartialWakeLockFinishInternal(name, historyName, uid);
            StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                    workSource.get(i), workSource.getName(i), name, historyName,
                    StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF);
        }
        final ArrayList<WorkChain> workChains = workSource.getWorkChains();
@@ -4645,9 +4628,6 @@ public class BatteryStatsImpl extends BatteryStats {
                final WorkChain workChain = workChains.get(i);
                final int uid = workChain.getAttributionUid();
                noteLongPartialWakeLockFinishInternal(name, historyName, uid);
                StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                        workChain.getUids(), workChain.getTags(), name, historyName,
                        StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF);
            }
        }
    }
+11 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.os.WorkSource;
import android.provider.Settings;
import android.util.EventLog;
import android.util.Slog;
import android.util.StatsLog;
import android.view.inputmethod.InputMethodManagerInternal;

import com.android.internal.app.IBatteryStats;
@@ -231,8 +232,13 @@ final class Notifier {
        try {
            if (workSource != null) {
                mBatteryStats.noteLongPartialWakelockStartFromSource(tag, historyTag, workSource);
                StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, workSource,
                        tag, historyTag, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON);
            } else {
                mBatteryStats.noteLongPartialWakelockStart(tag, historyTag, ownerUid);
                StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                        ownerUid, null, tag, historyTag,
                        StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__ON);
            }
        } catch (RemoteException ex) {
            // Ignore
@@ -249,8 +255,13 @@ final class Notifier {
        try {
            if (workSource != null) {
                mBatteryStats.noteLongPartialWakelockFinishFromSource(tag, historyTag, workSource);
                StatsLog.write(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED, workSource,
                        tag, historyTag, StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF);
            } else {
                mBatteryStats.noteLongPartialWakelockFinish(tag, historyTag, ownerUid);
                StatsLog.write_non_chained(StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED,
                        ownerUid, null, tag, historyTag,
                        StatsLog.LONG_PARTIAL_WAKELOCK_STATE_CHANGED__STATE__OFF);
            }
        } catch (RemoteException ex) {
            // Ignore
+73 −0
Original line number Diff line number Diff line
@@ -656,6 +656,75 @@ static void write_java_method(
    }
}

static void write_java_work_source_method(FILE* out, const set<vector<java_type_t>>& signatures) {
    fprintf(out, "\n    // WorkSource methods.\n");
    for (set<vector<java_type_t>>::const_iterator signature = signatures.begin();
            signature != signatures.end(); signature++) {
        // Determine if there is Attribution in this signature.
        int attributionArg = -1;
        int argIndexMax = 0;
        for (vector<java_type_t>::const_iterator arg = signature->begin();
                arg != signature->end(); arg++) {
            argIndexMax++;
            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
                if (attributionArg > -1) {
                    fprintf(stderr, "An atom contains multiple AttributionNode fields.\n");
                    fprintf(stderr, "This is not supported. Aborting WorkSource method writing.\n");
                    fprintf(out, "\n// Invalid for WorkSource: more than one attribution chain.\n");
                    return;
                }
                attributionArg = argIndexMax;
            }
        }
        if (attributionArg < 0) {
            continue;
        }

        // Method header (signature)
        fprintf(out, "    public static void write(int code");
        int argIndex = 1;
        for (vector<java_type_t>::const_iterator arg = signature->begin();
                arg != signature->end(); arg++) {
            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
                fprintf(out, ", WorkSource ws");
            } else {
                fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
            }
            argIndex++;
        }
        fprintf(out, ") {\n");

        // write_non_chained() component. TODO: Remove when flat uids are no longer needed.
        fprintf(out, "        for (int i = 0; i < ws.size(); ++i) {\n");
        fprintf(out, "            write_non_chained(code");
        for (int argIndex = 1; argIndex <= argIndexMax; argIndex++) {
            if (argIndex == attributionArg) {
                fprintf(out, ", ws.get(i), ws.getName(i)");
            } else {
               fprintf(out, ", arg%d", argIndex);
            }
        }
        fprintf(out, ");\n");
        fprintf(out, "        }\n"); // close flor-loop

        // write() component.
        fprintf(out, "        ArrayList<WorkSource.WorkChain> workChains = ws.getWorkChains();\n");
        fprintf(out, "        if (workChains != null) {\n");
        fprintf(out, "            for (WorkSource.WorkChain wc : workChains) {\n");
        fprintf(out, "                write(code");
        for (int argIndex = 1; argIndex <= argIndexMax; argIndex++) {
            if (argIndex == attributionArg) {
                fprintf(out, ", wc.getUids(), wc.getTags()");
            } else {
               fprintf(out, ", arg%d", argIndex);
            }
        }
        fprintf(out, ");\n");
        fprintf(out, "            }\n"); // close for-loop
        fprintf(out, "        }\n"); // close if
        fprintf(out, "    }\n"); // close method
    }
}

static int
write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl)
@@ -665,6 +734,9 @@ write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionD
    fprintf(out, "\n");
    fprintf(out, "package android.util;\n");
    fprintf(out, "\n");
    fprintf(out, "import android.os.WorkSource;\n");
    fprintf(out, "import java.util.ArrayList;\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "/**\n");
    fprintf(out, " * API For logging statistics events.\n");
@@ -720,6 +792,7 @@ write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionD
    fprintf(out, "    // Write methods\n");
    write_java_method(out, "write", atoms.signatures, attributionDecl);
    write_java_method(out, "write_non_chained", atoms.non_chained_signatures, attributionDecl);
    write_java_work_source_method(out, atoms.signatures);

    fprintf(out, "}\n");