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

Commit bdd5a502 authored by Rafal Slawik's avatar Rafal Slawik
Browse files

Introduce IonHeapSize atom

IonHeapSize is replacing SystemIonHeapSize on devices with newer
kernels. It relies on libmeminfo to measure the total size of all ion
heaps, unlike the old atom that manually parsed a file from debugfs.

Test: m -j
Test: statsd_testdrive 10070
Bug: 140788538
Bug: 147722878
Change-Id: If3fa74bd96631116ef05656e7942fa6cf4e15005
parent c870f5a9
Loading
Loading
Loading
Loading
+19 −2
Original line number Original line Diff line number Diff line
@@ -341,7 +341,7 @@ message Atom {
    }
    }


    // Pulled events will start at field 10000.
    // Pulled events will start at field 10000.
    // Next: 10070
    // Next: 10071
    oneof pulled {
    oneof pulled {
        WifiBytesTransfer wifi_bytes_transfer = 10000;
        WifiBytesTransfer wifi_bytes_transfer = 10000;
        WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001;
        WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001;
@@ -398,7 +398,7 @@ message Atom {
        ExternalStorageInfo external_storage_info = 10053;
        ExternalStorageInfo external_storage_info = 10053;
        GpuStatsGlobalInfo gpu_stats_global_info = 10054;
        GpuStatsGlobalInfo gpu_stats_global_info = 10054;
        GpuStatsAppInfo gpu_stats_app_info = 10055;
        GpuStatsAppInfo gpu_stats_app_info = 10055;
        SystemIonHeapSize system_ion_heap_size = 10056;
        SystemIonHeapSize system_ion_heap_size = 10056 [deprecated = true];
        AppsOnExternalStorageInfo apps_on_external_storage_info = 10057;
        AppsOnExternalStorageInfo apps_on_external_storage_info = 10057;
        FaceSettings face_settings = 10058;
        FaceSettings face_settings = 10058;
        CoolingDevice cooling_device = 10059;
        CoolingDevice cooling_device = 10059;
@@ -412,6 +412,7 @@ message Atom {
        DangerousPermissionStateSampled dangerous_permission_state_sampled = 10067;
        DangerousPermissionStateSampled dangerous_permission_state_sampled = 10067;
        GraphicsStats graphics_stats = 10068;
        GraphicsStats graphics_stats = 10068;
        RuntimeAppOpsAccess runtime_app_ops_access = 10069;
        RuntimeAppOpsAccess runtime_app_ops_access = 10069;
        IonHeapSize ion_heap_size = 10070;
    }
    }


    // DO NOT USE field numbers above 100,000 in AOSP.
    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -6945,10 +6946,26 @@ message GpuStatsAppInfo {
 * Pulled from StatsCompanionService.
 * Pulled from StatsCompanionService.
 */
 */
message SystemIonHeapSize {
message SystemIonHeapSize {
    // Deprecated due to limited support of ion stats in debugfs.
    // Use `IonHeapSize` instead.
    option deprecated = true;

    // Size of the system ion heap in bytes.
    // Size of the system ion heap in bytes.
    // Read from debugfs.
    optional int64 size_in_bytes = 1;
    optional int64 size_in_bytes = 1;
}
}


/*
 * Logs the total size of the ion heap.
 *
 * Pulled from StatsCompanionService.
 */
message IonHeapSize {
    // Total size of all ion heaps in kilobytes.
    // Read from: /sys/kernel/ion/total_heaps_kb.
    optional int32 total_size_kb = 1;
}

/*
/*
 * Logs the per-process size of the system ion heap.
 * Logs the per-process size of the system ion heap.
 *
 *
+22 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.stats;
import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED;
import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED;
import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS;
import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS;
import static android.os.Debug.getIonHeapsSizeKb;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static android.os.Process.getUidForPid;
import static android.os.Process.getUidForPid;
import static android.os.storage.VolumeInfo.TYPE_PRIVATE;
import static android.os.storage.VolumeInfo.TYPE_PRIVATE;
@@ -251,6 +252,7 @@ public class StatsPullAtomService extends SystemService {
        registerProcessMemoryHighWaterMark();
        registerProcessMemoryHighWaterMark();
        registerProcessMemorySnapshot();
        registerProcessMemorySnapshot();
        registerSystemIonHeapSize();
        registerSystemIonHeapSize();
        registerIonHeapSize();
        registerProcessSystemIonHeapSize();
        registerProcessSystemIonHeapSize();
        registerTemperature();
        registerTemperature();
        registerCoolingDevice();
        registerCoolingDevice();
@@ -790,6 +792,26 @@ public class StatsPullAtomService extends SystemService {
        // No op.
        // No op.
    }
    }


    private void registerIonHeapSize() {
        int tagId = StatsLog.ION_HEAP_SIZE;
        mStatsManager.registerPullAtomCallback(
                tagId,
                /* PullAtomMetadata */ null,
                (atomTag, data) -> pullIonHeapSize(atomTag, data),
                Executors.newSingleThreadExecutor()
        );
    }

    private int pullIonHeapSize(int atomTag, List<StatsEvent> pulledData) {
        int ionHeapSizeInKilobytes = (int) getIonHeapsSizeKb();
        StatsEvent e = StatsEvent.newBuilder()
              .setAtomId(atomTag)
              .writeInt(ionHeapSizeInKilobytes)
              .build();
        pulledData.add(e);
        return StatsManager.PULL_SUCCESS;
    }

    private void registerProcessSystemIonHeapSize() {
    private void registerProcessSystemIonHeapSize() {
        // No op.
        // No op.
    }
    }