diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 4e57c9cdf8064..7b35723d8d988 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -341,7 +341,7 @@ message Atom { } // Pulled events will start at field 10000. - // Next: 10070 + // Next: 10071 oneof pulled { WifiBytesTransfer wifi_bytes_transfer = 10000; WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001; @@ -398,7 +398,7 @@ message Atom { ExternalStorageInfo external_storage_info = 10053; GpuStatsGlobalInfo gpu_stats_global_info = 10054; 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; FaceSettings face_settings = 10058; CoolingDevice cooling_device = 10059; @@ -412,6 +412,7 @@ message Atom { DangerousPermissionStateSampled dangerous_permission_state_sampled = 10067; GraphicsStats graphics_stats = 10068; RuntimeAppOpsAccess runtime_app_ops_access = 10069; + IonHeapSize ion_heap_size = 10070; } // DO NOT USE field numbers above 100,000 in AOSP. @@ -6945,10 +6946,26 @@ message GpuStatsAppInfo { * Pulled from StatsCompanionService. */ 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. + // Read from debugfs. 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. * diff --git a/services/core/java/com/android/server/stats/StatsPullAtomService.java b/services/core/java/com/android/server/stats/StatsPullAtomService.java index 5ee7eff20e24d..f1f31d53c0b6b 100644 --- a/services/core/java/com/android/server/stats/StatsPullAtomService.java +++ b/services/core/java/com/android/server/stats/StatsPullAtomService.java @@ -19,6 +19,7 @@ package com.android.server.stats; import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED; import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED; 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.getUidForPid; import static android.os.storage.VolumeInfo.TYPE_PRIVATE; @@ -251,6 +252,7 @@ public class StatsPullAtomService extends SystemService { registerProcessMemoryHighWaterMark(); registerProcessMemorySnapshot(); registerSystemIonHeapSize(); + registerIonHeapSize(); registerProcessSystemIonHeapSize(); registerTemperature(); registerCoolingDevice(); @@ -790,6 +792,26 @@ public class StatsPullAtomService extends SystemService { // 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 pulledData) { + int ionHeapSizeInKilobytes = (int) getIonHeapsSizeKb(); + StatsEvent e = StatsEvent.newBuilder() + .setAtomId(atomTag) + .writeInt(ionHeapSizeInKilobytes) + .build(); + pulledData.add(e); + return StatsManager.PULL_SUCCESS; + } + private void registerProcessSystemIonHeapSize() { // No op. }