1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.os; 17 18 import com.android.internal.util.FrameworkStatsLog; 19 20 /** 21 * Activity manager communication with kernel out-of-memory (OOM) data handling 22 * and statsd atom logging. 23 * 24 * Expected data to get back from the OOM event's file. 25 * Note that this class fields' should be equivalent to the struct 26 * <b>OomKill</b> inside 27 * <pre> 28 * system/memory/libmeminfo/libmemevents/include/memevents/bpf_types.h 29 * </pre> 30 * 31 * @hide 32 */ 33 public final class OomKillRecord { 34 private long mTimeStampInMillis; 35 private int mPid; 36 private int mUid; 37 private String mProcessName; 38 private short mOomScoreAdj; 39 private long mTotalVmInKb; 40 private long mAnonRssInKb; 41 private long mFileRssInKb; 42 private long mShmemRssInKb; 43 private long mPgTablesInKb; 44 OomKillRecord(long timeStampInMillis, int pid, int uid, String processName, short oomScoreAdj, long totalVmInKb, long anonRssInKb, long fileRssInKb, long shmemRssInKb, long pgTablesInKb)45 public OomKillRecord(long timeStampInMillis, int pid, int uid, 46 String processName, short oomScoreAdj, 47 long totalVmInKb, long anonRssInKb, 48 long fileRssInKb, long shmemRssInKb, 49 long pgTablesInKb) { 50 this.mTimeStampInMillis = timeStampInMillis; 51 this.mPid = pid; 52 this.mUid = uid; 53 this.mProcessName = processName; 54 this.mOomScoreAdj = oomScoreAdj; 55 this.mTotalVmInKb = totalVmInKb; 56 this.mAnonRssInKb = anonRssInKb; 57 this.mFileRssInKb = fileRssInKb; 58 this.mShmemRssInKb = shmemRssInKb; 59 this.mPgTablesInKb = pgTablesInKb; 60 } 61 62 /** 63 * Logs the event when the kernel OOM killer claims a victims to reduce 64 * memory pressure. 65 * KernelOomKillOccurred = 754 66 */ logKillOccurred()67 public void logKillOccurred() { 68 FrameworkStatsLog.write( 69 FrameworkStatsLog.KERNEL_OOM_KILL_OCCURRED, 70 mUid, mPid, mOomScoreAdj, mTimeStampInMillis, 71 mProcessName, mTotalVmInKb, mAnonRssInKb, 72 mFileRssInKb, mShmemRssInKb, mPgTablesInKb); 73 } 74 getTimestampMilli()75 public long getTimestampMilli() { 76 return mTimeStampInMillis; 77 } 78 getPid()79 public int getPid() { 80 return mPid; 81 } 82 getUid()83 public int getUid() { 84 return mUid; 85 } 86 getProcessName()87 public String getProcessName() { 88 return mProcessName; 89 } 90 getOomScoreAdj()91 public short getOomScoreAdj() { 92 return mOomScoreAdj; 93 } 94 } 95