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

Commit 937d7429 authored by Chenjie Yu's avatar Chenjie Yu
Browse files

add system uptime and free disk space atoms and pullers

Test: will add cts later
Change-Id: I0b906fab82fca89b85bc0c7fbe06078115d43eec
parent 0e5f9c8a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ message Atom {
        CpuIdleTime cpu_idle_time = 10015;
        CpuActiveTime cpu_active_time = 10016;
        CpuClusterTime cpu_cluster_time = 10017;
        DiskSpace disk_space = 10018;
        SystemUptime system_uptime = 10019;
    }
}

@@ -1271,3 +1273,26 @@ message CpuClusterTime {
    optional uint64 idx = 2;
    optional uint64 time_ms = 3;
}

/*
 * Pulls free disk space, for data, system partition and temporary directory.
 */
message DiskSpace {
    // available bytes in data partition
    optional uint64 data_available_bytes = 1;
    // available bytes in system partition
    optional uint64 system_available_bytes = 2;
    // available bytes in download cache or temp directories
    optional uint64 temp_available_bytes = 3;
}

/*
 * Pulls system up time.
 */
message SystemUptime {
    // Milliseconds since the system was booted.
    // This clock stops when the system enters deep sleep (CPU off, display dark, device waiting
    // for external input).
    // It is not affected by clock scaling, idle, or other power saving mechanisms.
    optional uint64 uptime_ms = 1;
}
 No newline at end of file
+9 −0
Original line number Diff line number Diff line
@@ -66,6 +66,15 @@ StatsPullerManagerImpl::StatsPullerManagerImpl()
    mPullers.insert({android::util::CPU_TIME_PER_UID_FREQ, make_shared<CpuTimePerUidFreqPuller>()});
    mPullers.insert({android::util::CPU_SUSPEND_TIME, make_shared<StatsCompanionServicePuller>(android::util::CPU_SUSPEND_TIME)});
    mPullers.insert({android::util::CPU_IDLE_TIME, make_shared<StatsCompanionServicePuller>(android::util::CPU_IDLE_TIME)});
    mPullers.insert({android::util::DISK_SPACE,
                     make_shared<StatsCompanionServicePuller>(android::util::DISK_SPACE)});
    mPullers.insert({android::util::SYSTEM_UPTIME,
                     make_shared<StatsCompanionServicePuller>(android::util::SYSTEM_UPTIME)});
    mPullers.insert(
            {android::util::WIFI_ACTIVITY_ENERGY_INFO,
             make_shared<StatsCompanionServicePuller>(android::util::WIFI_ACTIVITY_ENERGY_INFO)});
    mPullers.insert({android::util::MODEM_ACTIVITY_INFO,
                     make_shared<StatsCompanionServicePuller>(android::util::MODEM_ACTIVITY_INFO)});

    mStatsCompanionService = StatsService::getStatsCompanionService();
}
+32 −7
Original line number Diff line number Diff line
@@ -28,12 +28,10 @@ import android.content.pm.UserInfo;
import android.net.NetworkStats;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiActivityEnergyInfo;
import android.os.SystemClock;
import android.telephony.ModemActivityInfo;
import android.telephony.TelephonyManager;
import android.os.BatteryStatsInternal;
import android.os.Binder;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.IStatsCompanionService;
import android.os.IStatsManager;
@@ -41,18 +39,22 @@ import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatFs;
import android.os.StatsLogEventWrapper;
import android.os.SynchronousResultReceiver;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.ModemActivityInfo;
import android.telephony.TelephonyManager;
import android.util.Slog;
import android.util.StatsLog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.os.KernelCpuSpeedReader;
import com.android.internal.os.KernelWakelockReader;
import com.android.internal.os.KernelWakelockStats;
import com.android.internal.os.KernelCpuSpeedReader;
import com.android.internal.os.PowerProfile;
import com.android.server.LocalServices;
import com.android.server.SystemService;
@@ -97,6 +99,11 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    private final KernelCpuSpeedReader[] mKernelCpuSpeedReaders;
    private IWifiManager mWifiManager = null;
    private TelephonyManager mTelephony = null;
    private final StatFs mStatFsData = new StatFs(Environment.getDataDirectory().getAbsolutePath());
    private final StatFs mStatFsSystem =
        new StatFs(Environment.getRootDirectory().getAbsolutePath());
    private final StatFs mStatFsTemp =
        new StatFs(Environment.getDownloadCacheDirectory().getAbsolutePath());

    public StatsCompanionService(Context context) {
        super();
@@ -560,7 +567,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                    if (clusterTimeMs != null) {
                        for (int speed = clusterTimeMs.length - 1; speed >= 0; --speed) {
                            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 3);
                            e.writeInt(tagId);
                            e.writeInt(cluster);
                            e.writeInt(speed);
                            e.writeLong(clusterTimeMs[speed]);
                            ret.add(e);
@@ -589,6 +596,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                        e.writeLong(wifiInfo.getControllerIdleTimeMillis());
                        e.writeLong(wifiInfo.getControllerEnergyUsed());
                        ret.add(e);
                        return ret.toArray(new StatsLogEventWrapper[ret.size()]);
                    } catch (RemoteException e) {
                        Slog.e(TAG, "Pulling wifiManager for wifi controller activity energy info has error", e);
                    } finally {
@@ -619,6 +627,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                    e.writeLong(modemInfo.getRxTimeMillis());
                    e.writeLong(modemInfo.getEnergyUsed());
                    ret.add(e);
                    return ret.toArray(new StatsLogEventWrapper[ret.size()]);
                }
                break;
            }
@@ -627,14 +636,30 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 1);
                e.writeLong(SystemClock.elapsedRealtime());
                ret.add(e);
                break;
                return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            case StatsLog.CPU_IDLE_TIME: {
                List<StatsLogEventWrapper> ret = new ArrayList();
                StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 1);
                e.writeLong(SystemClock.uptimeMillis());
                ret.add(e);
                break;
                return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            case StatsLog.DISK_SPACE: {
              List<StatsLogEventWrapper> ret = new ArrayList();
              StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 3);
              e.writeLong(mStatFsData.getAvailableBytes());
              e.writeLong(mStatFsSystem.getAvailableBytes());
              e.writeLong(mStatFsTemp.getAvailableBytes());
              ret.add(e);
              return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            case StatsLog.SYSTEM_UPTIME: {
              List<StatsLogEventWrapper> ret = new ArrayList();
              StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, 1);
              e.writeLong(SystemClock.uptimeMillis());
              ret.add(e);
              return ret.toArray(new StatsLogEventWrapper[ret.size()]);
            }
            default:
                Slog.w(TAG, "No such tagId data as " + tagId);