The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
| 17 | package android.os; |
| 18 | |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 22 | import android.app.AppGlobals; |
| 23 | import android.content.Context; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 26 | import com.android.internal.util.FastPrintWriter; |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 27 | import com.android.internal.util.Preconditions; |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 28 | import com.android.internal.util.TypedProperties; |
| 29 | |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 30 | import dalvik.system.VMDebug; |
| 31 | |
| 32 | import org.apache.harmony.dalvik.ddmc.Chunk; |
| 33 | import org.apache.harmony.dalvik.ddmc.ChunkHandler; |
| 34 | import org.apache.harmony.dalvik.ddmc.DdmServer; |
| 35 | |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 36 | import java.io.File; |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 37 | import java.io.FileDescriptor; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 38 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import java.io.FileOutputStream; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 40 | import java.io.FileReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import java.io.IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import java.io.PrintWriter; |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 43 | import java.io.Reader; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 44 | import java.lang.annotation.ElementType; |
| 45 | import java.lang.annotation.Retention; |
| 46 | import java.lang.annotation.RetentionPolicy; |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 47 | import java.lang.annotation.Target; |
| 48 | import java.lang.reflect.Field; |
| 49 | import java.lang.reflect.Modifier; |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 50 | import java.util.HashMap; |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 51 | import java.util.Map; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 55 | * Provides various debugging methods for Android applications, including |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | * tracing and allocation counts. |
| 57 | * <p><strong>Logging Trace Files</strong></p> |
| 58 | * <p>Debug can create log files that give details about an application, such as |
| 59 | * a call stack and start/stop times for any running methods. See <a |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 60 | * href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs with |
| 61 | * Traceview</a> for information about reading trace files. To start logging |
| 62 | * trace files, call one of the startMethodTracing() methods. To stop tracing, |
| 63 | * call {@link #stopMethodTracing()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | */ |
| 65 | public final class Debug |
| 66 | { |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 67 | private static final String TAG = "Debug"; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /** |
| 70 | * Flags for startMethodTracing(). These can be ORed together. |
| 71 | * |
| 72 | * TRACE_COUNT_ALLOCS adds the results from startAllocCounting to the |
| 73 | * trace key file. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 74 | * |
| 75 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 77 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | public static final int TRACE_COUNT_ALLOCS = VMDebug.TRACE_COUNT_ALLOCS; |
| 79 | |
| 80 | /** |
| 81 | * Flags for printLoadedClasses(). Default behavior is to only show |
| 82 | * the class name. |
| 83 | */ |
| 84 | public static final int SHOW_FULL_DETAIL = 1; |
| 85 | public static final int SHOW_CLASSLOADER = (1 << 1); |
| 86 | public static final int SHOW_INITIALIZED = (1 << 2); |
| 87 | |
| 88 | // set/cleared by waitForDebugger() |
| 89 | private static volatile boolean mWaiting = false; |
| 90 | |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 91 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | private Debug() {} |
| 93 | |
| 94 | /* |
| 95 | * How long to wait for the debugger to finish sending requests. I've |
| 96 | * seen this hit 800msec on the device while waiting for a response |
| 97 | * to travel over USB and get processed, so we take that and add |
| 98 | * half a second. |
| 99 | */ |
| 100 | private static final int MIN_DEBUGGER_IDLE = 1300; // msec |
| 101 | |
| 102 | /* how long to sleep when polling for activity */ |
| 103 | private static final int SPIN_DELAY = 200; // msec |
| 104 | |
| 105 | /** |
| 106 | * Default trace file path and file |
| 107 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | private static final String DEFAULT_TRACE_BODY = "dmtrace"; |
| 109 | private static final String DEFAULT_TRACE_EXTENSION = ".trace"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * This class is used to retrieved various statistics about the memory mappings for this |
justinmuller | 6455138 | 2013-10-16 22:06:55 -0600 | [diff] [blame] | 113 | * process. The returned info is broken down by dalvik, native, and other. All results are in kB. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | */ |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 115 | public static class MemoryInfo implements Parcelable { |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 116 | /** The proportional set size for dalvik heap. (Doesn't include other Dalvik overhead.) */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | public int dalvikPss; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 118 | /** The proportional set size that is swappable for dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 119 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 120 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 121 | public int dalvikSwappablePss; |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 122 | /** @hide The resident set size for dalvik heap. (Without other Dalvik overhead.) */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 123 | @UnsupportedAppUsage |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 124 | public int dalvikRss; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 125 | /** The private dirty pages used by dalvik heap. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | public int dalvikPrivateDirty; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 127 | /** The shared dirty pages used by dalvik heap. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | public int dalvikSharedDirty; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 129 | /** The private clean pages used by dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 130 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 131 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 132 | public int dalvikPrivateClean; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 133 | /** The shared clean pages used by dalvik heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 134 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 135 | @UnsupportedAppUsage |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 136 | public int dalvikSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 137 | /** The dirty dalvik pages that have been swapped out. */ |
| 138 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 139 | @UnsupportedAppUsage |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 140 | public int dalvikSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 141 | /** The dirty dalvik pages that have been swapped out, proportional. */ |
| 142 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 143 | @UnsupportedAppUsage |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 144 | public int dalvikSwappedOutPss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
| 146 | /** The proportional set size for the native heap. */ |
| 147 | public int nativePss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 148 | /** The proportional set size that is swappable for the native heap. */ |
| 149 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 150 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 151 | public int nativeSwappablePss; |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 152 | /** @hide The resident set size for the native heap. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 153 | @UnsupportedAppUsage |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 154 | public int nativeRss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | /** The private dirty pages used by the native heap. */ |
| 156 | public int nativePrivateDirty; |
| 157 | /** The shared dirty pages used by the native heap. */ |
| 158 | public int nativeSharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 159 | /** The private clean pages used by the native heap. */ |
| 160 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 161 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 162 | public int nativePrivateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 163 | /** The shared clean pages used by the native heap. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 164 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 165 | @UnsupportedAppUsage |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 166 | public int nativeSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 167 | /** The dirty native pages that have been swapped out. */ |
| 168 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 169 | @UnsupportedAppUsage |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 170 | public int nativeSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 171 | /** The dirty native pages that have been swapped out, proportional. */ |
| 172 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 173 | @UnsupportedAppUsage |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 174 | public int nativeSwappedOutPss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | |
| 176 | /** The proportional set size for everything else. */ |
| 177 | public int otherPss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 178 | /** The proportional set size that is swappable for everything else. */ |
| 179 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 180 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 181 | public int otherSwappablePss; |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 182 | /** @hide The resident set size for everything else. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 183 | @UnsupportedAppUsage |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 184 | public int otherRss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | /** The private dirty pages used by everything else. */ |
| 186 | public int otherPrivateDirty; |
| 187 | /** The shared dirty pages used by everything else. */ |
| 188 | public int otherSharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 189 | /** The private clean pages used by everything else. */ |
| 190 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 191 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 192 | public int otherPrivateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 193 | /** The shared clean pages used by everything else. */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 194 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 195 | @UnsupportedAppUsage |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 196 | public int otherSharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 197 | /** The dirty pages used by anyting else that have been swapped out. */ |
| 198 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 199 | @UnsupportedAppUsage |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 200 | public int otherSwappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 201 | /** The dirty pages used by anyting else that have been swapped out, proportional. */ |
| 202 | /** @hide We may want to expose this, eventually. */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 203 | @UnsupportedAppUsage |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 204 | public int otherSwappedOutPss; |
| 205 | |
| 206 | /** Whether the kernel reports proportional swap usage */ |
| 207 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 208 | @UnsupportedAppUsage |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 209 | public boolean hasSwappedOutPss; |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 210 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 211 | /** @hide */ |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 212 | public static final int HEAP_UNKNOWN = 0; |
| 213 | /** @hide */ |
| 214 | public static final int HEAP_DALVIK = 1; |
| 215 | /** @hide */ |
| 216 | public static final int HEAP_NATIVE = 2; |
| 217 | |
| 218 | /** @hide */ |
| 219 | public static final int OTHER_DALVIK_OTHER = 0; |
| 220 | /** @hide */ |
| 221 | public static final int OTHER_STACK = 1; |
| 222 | /** @hide */ |
| 223 | public static final int OTHER_CURSOR = 2; |
| 224 | /** @hide */ |
| 225 | public static final int OTHER_ASHMEM = 3; |
| 226 | /** @hide */ |
| 227 | public static final int OTHER_GL_DEV = 4; |
| 228 | /** @hide */ |
| 229 | public static final int OTHER_UNKNOWN_DEV = 5; |
| 230 | /** @hide */ |
| 231 | public static final int OTHER_SO = 6; |
| 232 | /** @hide */ |
| 233 | public static final int OTHER_JAR = 7; |
| 234 | /** @hide */ |
| 235 | public static final int OTHER_APK = 8; |
| 236 | /** @hide */ |
| 237 | public static final int OTHER_TTF = 9; |
| 238 | /** @hide */ |
| 239 | public static final int OTHER_DEX = 10; |
| 240 | /** @hide */ |
| 241 | public static final int OTHER_OAT = 11; |
| 242 | /** @hide */ |
| 243 | public static final int OTHER_ART = 12; |
| 244 | /** @hide */ |
| 245 | public static final int OTHER_UNKNOWN_MAP = 13; |
| 246 | /** @hide */ |
| 247 | public static final int OTHER_GRAPHICS = 14; |
| 248 | /** @hide */ |
| 249 | public static final int OTHER_GL = 15; |
| 250 | /** @hide */ |
| 251 | public static final int OTHER_OTHER_MEMTRACK = 16; |
| 252 | |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 253 | // Needs to be declared here for the DVK_STAT ranges below. |
| 254 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 255 | @UnsupportedAppUsage |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 256 | public static final int NUM_OTHER_STATS = 17; |
| 257 | |
| 258 | // Dalvik subsections. |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 259 | /** @hide */ |
| 260 | public static final int OTHER_DALVIK_NORMAL = 17; |
| 261 | /** @hide */ |
| 262 | public static final int OTHER_DALVIK_LARGE = 18; |
| 263 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 264 | public static final int OTHER_DALVIK_ZYGOTE = 19; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 265 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 266 | public static final int OTHER_DALVIK_NON_MOVING = 20; |
| 267 | // Section begins and ends for dumpsys, relative to the DALVIK categories. |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 268 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 269 | public static final int OTHER_DVK_STAT_DALVIK_START = |
| 270 | OTHER_DALVIK_NORMAL - NUM_OTHER_STATS; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 271 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 272 | public static final int OTHER_DVK_STAT_DALVIK_END = |
| 273 | OTHER_DALVIK_NON_MOVING - NUM_OTHER_STATS; |
| 274 | |
| 275 | // Dalvik Other subsections. |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 276 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 277 | public static final int OTHER_DALVIK_OTHER_LINEARALLOC = 21; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 278 | /** @hide */ |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 279 | public static final int OTHER_DALVIK_OTHER_ACCOUNTING = 22; |
| 280 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 281 | public static final int OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE = 23; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 282 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 283 | public static final int OTHER_DALVIK_OTHER_APP_CODE_CACHE = 24; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 284 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 285 | public static final int OTHER_DALVIK_OTHER_COMPILER_METADATA = 25; |
| 286 | /** @hide */ |
| 287 | public static final int OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE = 26; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 288 | /** @hide */ |
| 289 | public static final int OTHER_DVK_STAT_DALVIK_OTHER_START = |
| 290 | OTHER_DALVIK_OTHER_LINEARALLOC - NUM_OTHER_STATS; |
| 291 | /** @hide */ |
| 292 | public static final int OTHER_DVK_STAT_DALVIK_OTHER_END = |
| 293 | OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE - NUM_OTHER_STATS; |
| 294 | |
| 295 | // Dex subsections (Boot vdex, App dex, and App vdex). |
| 296 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 297 | public static final int OTHER_DEX_BOOT_VDEX = 27; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 298 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 299 | public static final int OTHER_DEX_APP_DEX = 28; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 300 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 301 | public static final int OTHER_DEX_APP_VDEX = 29; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 302 | /** @hide */ |
| 303 | public static final int OTHER_DVK_STAT_DEX_START = OTHER_DEX_BOOT_VDEX - NUM_OTHER_STATS; |
| 304 | /** @hide */ |
| 305 | public static final int OTHER_DVK_STAT_DEX_END = OTHER_DEX_APP_VDEX - NUM_OTHER_STATS; |
| 306 | |
| 307 | // Art subsections (App image, boot image). |
| 308 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 309 | public static final int OTHER_ART_APP = 30; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 310 | /** @hide */ |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 311 | public static final int OTHER_ART_BOOT = 31; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 312 | /** @hide */ |
| 313 | public static final int OTHER_DVK_STAT_ART_START = OTHER_ART_APP - NUM_OTHER_STATS; |
| 314 | /** @hide */ |
| 315 | public static final int OTHER_DVK_STAT_ART_END = OTHER_ART_BOOT - NUM_OTHER_STATS; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 316 | |
| 317 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 318 | @UnsupportedAppUsage |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 319 | public static final int NUM_DVK_STATS = OTHER_ART_BOOT + 1 - OTHER_DALVIK_NORMAL; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 320 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 321 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 322 | public static final int NUM_CATEGORIES = 9; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 323 | |
| 324 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 325 | public static final int OFFSET_PSS = 0; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 326 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 327 | public static final int OFFSET_SWAPPABLE_PSS = 1; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 328 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 329 | public static final int OFFSET_RSS = 2; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 330 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 331 | public static final int OFFSET_PRIVATE_DIRTY = 3; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 332 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 333 | public static final int OFFSET_SHARED_DIRTY = 4; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 334 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 335 | public static final int OFFSET_PRIVATE_CLEAN = 5; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 336 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 337 | public static final int OFFSET_SHARED_CLEAN = 6; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 338 | /** @hide */ |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 339 | public static final int OFFSET_SWAPPED_OUT = 7; |
| 340 | /** @hide */ |
| 341 | public static final int OFFSET_SWAPPED_OUT_PSS = 8; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 342 | |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 343 | @UnsupportedAppUsage |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 344 | private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 345 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 346 | public MemoryInfo() { |
| 347 | } |
| 348 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 349 | /** |
Dianne Hackborn | 8c76d91 | 2018-08-23 15:20:05 -0700 | [diff] [blame] | 350 | * @hide Copy contents from another object. |
| 351 | */ |
| 352 | public void set(MemoryInfo other) { |
| 353 | dalvikPss = other.dalvikPss; |
| 354 | dalvikSwappablePss = other.dalvikSwappablePss; |
| 355 | dalvikRss = other.dalvikRss; |
| 356 | dalvikPrivateDirty = other.dalvikPrivateDirty; |
| 357 | dalvikSharedDirty = other.dalvikSharedDirty; |
| 358 | dalvikPrivateClean = other.dalvikPrivateClean; |
| 359 | dalvikSharedClean = other.dalvikSharedClean; |
| 360 | dalvikSwappedOut = other.dalvikSwappedOut; |
| 361 | dalvikSwappedOutPss = other.dalvikSwappedOutPss; |
| 362 | |
| 363 | nativePss = other.nativePss; |
| 364 | nativeSwappablePss = other.nativeSwappablePss; |
| 365 | nativeRss = other.nativeRss; |
| 366 | nativePrivateDirty = other.nativePrivateDirty; |
| 367 | nativeSharedDirty = other.nativeSharedDirty; |
| 368 | nativePrivateClean = other.nativePrivateClean; |
| 369 | nativeSharedClean = other.nativeSharedClean; |
| 370 | nativeSwappedOut = other.nativeSwappedOut; |
| 371 | nativeSwappedOutPss = other.nativeSwappedOutPss; |
| 372 | |
| 373 | otherPss = other.otherPss; |
| 374 | otherSwappablePss = other.otherSwappablePss; |
| 375 | otherRss = other.otherRss; |
| 376 | otherPrivateDirty = other.otherPrivateDirty; |
| 377 | otherSharedDirty = other.otherSharedDirty; |
| 378 | otherPrivateClean = other.otherPrivateClean; |
| 379 | otherSharedClean = other.otherSharedClean; |
| 380 | otherSwappedOut = other.otherSwappedOut; |
| 381 | otherSwappedOutPss = other.otherSwappedOutPss; |
| 382 | |
| 383 | hasSwappedOutPss = other.hasSwappedOutPss; |
| 384 | |
| 385 | System.arraycopy(other.otherStats, 0, otherStats, 0, otherStats.length); |
| 386 | } |
| 387 | |
| 388 | /** |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 389 | * Return total PSS memory usage in kB. |
| 390 | */ |
| 391 | public int getTotalPss() { |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 392 | return dalvikPss + nativePss + otherPss + getTotalSwappedOutPss(); |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 393 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 394 | |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 395 | /** |
| 396 | * @hide Return total PSS memory usage in kB. |
| 397 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 398 | @UnsupportedAppUsage |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 399 | public int getTotalUss() { |
| 400 | return dalvikPrivateClean + dalvikPrivateDirty |
| 401 | + nativePrivateClean + nativePrivateDirty |
| 402 | + otherPrivateClean + otherPrivateDirty; |
| 403 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 404 | |
| 405 | /** |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 406 | * Return total PSS memory usage in kB mapping a file of one of the following extension: |
| 407 | * .so, .jar, .apk, .ttf, .dex, .odex, .oat, .art . |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 408 | */ |
| 409 | public int getTotalSwappablePss() { |
| 410 | return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss; |
| 411 | } |
| 412 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 413 | /** |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 414 | * @hide Return total RSS memory usage in kB. |
| 415 | */ |
| 416 | public int getTotalRss() { |
| 417 | return dalvikRss + nativeRss + otherRss; |
| 418 | } |
| 419 | |
| 420 | /** |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 421 | * Return total private dirty memory usage in kB. |
| 422 | */ |
| 423 | public int getTotalPrivateDirty() { |
| 424 | return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty; |
| 425 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 426 | |
Dianne Hackborn | 4f21c4c | 2009-09-17 10:24:05 -0700 | [diff] [blame] | 427 | /** |
| 428 | * Return total shared dirty memory usage in kB. |
| 429 | */ |
| 430 | public int getTotalSharedDirty() { |
| 431 | return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty; |
| 432 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 433 | |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Return total shared clean memory usage in kB. |
| 436 | */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 437 | public int getTotalPrivateClean() { |
| 438 | return dalvikPrivateClean + nativePrivateClean + otherPrivateClean; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Return total shared clean memory usage in kB. |
| 443 | */ |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 444 | public int getTotalSharedClean() { |
| 445 | return dalvikSharedClean + nativeSharedClean + otherSharedClean; |
| 446 | } |
| 447 | |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Return total swapped out memory in kB. |
| 450 | * @hide |
| 451 | */ |
| 452 | public int getTotalSwappedOut() { |
| 453 | return dalvikSwappedOut + nativeSwappedOut + otherSwappedOut; |
| 454 | } |
| 455 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 456 | /** |
| 457 | * Return total swapped out memory in kB, proportional. |
| 458 | * @hide |
| 459 | */ |
| 460 | public int getTotalSwappedOutPss() { |
| 461 | return dalvikSwappedOutPss + nativeSwappedOutPss + otherSwappedOutPss; |
| 462 | } |
| 463 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 464 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 465 | @UnsupportedAppUsage |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 466 | public int getOtherPss(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 467 | return otherStats[which * NUM_CATEGORIES + OFFSET_PSS]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 470 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 471 | public int getOtherSwappablePss(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 472 | return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPABLE_PSS]; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 475 | /** @hide */ |
| 476 | public int getOtherRss(int which) { |
| 477 | return otherStats[which * NUM_CATEGORIES + OFFSET_RSS]; |
| 478 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 479 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 480 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 481 | @UnsupportedAppUsage |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 482 | public int getOtherPrivateDirty(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 483 | return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_DIRTY]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 486 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 487 | @UnsupportedAppUsage |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 488 | public int getOtherSharedDirty(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 489 | return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_DIRTY]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 492 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 493 | public int getOtherPrivateClean(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 494 | return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_CLEAN]; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 495 | } |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 496 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 497 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 498 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 499 | public int getOtherPrivate(int which) { |
| 500 | return getOtherPrivateClean(which) + getOtherPrivateDirty(which); |
| 501 | } |
| 502 | |
| 503 | /** @hide */ |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 504 | public int getOtherSharedClean(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 505 | return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_CLEAN]; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 508 | /** @hide */ |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 509 | public int getOtherSwappedOut(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 510 | return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT]; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** @hide */ |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 514 | public int getOtherSwappedOutPss(int which) { |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 515 | return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT_PSS]; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** @hide */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 519 | @UnsupportedAppUsage |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 520 | public static String getOtherLabel(int which) { |
| 521 | switch (which) { |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 522 | case OTHER_DALVIK_OTHER: return "Dalvik Other"; |
| 523 | case OTHER_STACK: return "Stack"; |
| 524 | case OTHER_CURSOR: return "Cursor"; |
| 525 | case OTHER_ASHMEM: return "Ashmem"; |
| 526 | case OTHER_GL_DEV: return "Gfx dev"; |
| 527 | case OTHER_UNKNOWN_DEV: return "Other dev"; |
| 528 | case OTHER_SO: return ".so mmap"; |
| 529 | case OTHER_JAR: return ".jar mmap"; |
| 530 | case OTHER_APK: return ".apk mmap"; |
| 531 | case OTHER_TTF: return ".ttf mmap"; |
| 532 | case OTHER_DEX: return ".dex mmap"; |
| 533 | case OTHER_OAT: return ".oat mmap"; |
| 534 | case OTHER_ART: return ".art mmap"; |
| 535 | case OTHER_UNKNOWN_MAP: return "Other mmap"; |
| 536 | case OTHER_GRAPHICS: return "EGL mtrack"; |
| 537 | case OTHER_GL: return "GL mtrack"; |
| 538 | case OTHER_OTHER_MEMTRACK: return "Other mtrack"; |
| 539 | case OTHER_DALVIK_NORMAL: return ".Heap"; |
| 540 | case OTHER_DALVIK_LARGE: return ".LOS"; |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 541 | case OTHER_DALVIK_ZYGOTE: return ".Zygote"; |
| 542 | case OTHER_DALVIK_NON_MOVING: return ".NonMoving"; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 543 | case OTHER_DALVIK_OTHER_LINEARALLOC: return ".LinearAlloc"; |
| 544 | case OTHER_DALVIK_OTHER_ACCOUNTING: return ".GC"; |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 545 | case OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE: return ".ZygoteJIT"; |
| 546 | case OTHER_DALVIK_OTHER_APP_CODE_CACHE: return ".AppJIT"; |
Mathieu Chartier | 95550dd | 2017-07-13 15:01:34 -0700 | [diff] [blame] | 547 | case OTHER_DALVIK_OTHER_COMPILER_METADATA: return ".CompilerMetadata"; |
| 548 | case OTHER_DALVIK_OTHER_INDIRECT_REFERENCE_TABLE: return ".IndirectRef"; |
| 549 | case OTHER_DEX_BOOT_VDEX: return ".Boot vdex"; |
| 550 | case OTHER_DEX_APP_DEX: return ".App dex"; |
| 551 | case OTHER_DEX_APP_VDEX: return ".App vdex"; |
| 552 | case OTHER_ART_APP: return ".App art"; |
| 553 | case OTHER_ART_BOOT: return ".Boot art"; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 554 | default: return "????"; |
| 555 | } |
| 556 | } |
| 557 | |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 558 | /** |
| 559 | * Returns the value of a particular memory statistic or {@code null} if no |
| 560 | * such memory statistic exists. |
| 561 | * |
| 562 | * <p>The following table lists the memory statistics that are supported. |
| 563 | * Note that memory statistics may be added or removed in a future API level.</p> |
| 564 | * |
| 565 | * <table> |
| 566 | * <thead> |
| 567 | * <tr> |
| 568 | * <th>Memory statistic name</th> |
| 569 | * <th>Meaning</th> |
| 570 | * <th>Example</th> |
| 571 | * <th>Supported (API Levels)</th> |
| 572 | * </tr> |
| 573 | * </thead> |
| 574 | * <tbody> |
| 575 | * <tr> |
| 576 | * <td>summary.java-heap</td> |
| 577 | * <td>The private Java Heap usage in kB. This corresponds to the Java Heap field |
| 578 | * in the App Summary section output by dumpsys meminfo.</td> |
| 579 | * <td>{@code 1442}</td> |
| 580 | * <td>23</td> |
| 581 | * </tr> |
| 582 | * <tr> |
| 583 | * <td>summary.native-heap</td> |
| 584 | * <td>The private Native Heap usage in kB. This corresponds to the Native Heap |
| 585 | * field in the App Summary section output by dumpsys meminfo.</td> |
| 586 | * <td>{@code 1442}</td> |
| 587 | * <td>23</td> |
| 588 | * </tr> |
| 589 | * <tr> |
| 590 | * <td>summary.code</td> |
| 591 | * <td>The memory usage for static code and resources in kB. This corresponds to |
| 592 | * the Code field in the App Summary section output by dumpsys meminfo.</td> |
| 593 | * <td>{@code 1442}</td> |
| 594 | * <td>23</td> |
| 595 | * </tr> |
| 596 | * <tr> |
| 597 | * <td>summary.stack</td> |
| 598 | * <td>The stack usage in kB. This corresponds to the Stack field in the |
| 599 | * App Summary section output by dumpsys meminfo.</td> |
| 600 | * <td>{@code 1442}</td> |
| 601 | * <td>23</td> |
| 602 | * </tr> |
| 603 | * <tr> |
| 604 | * <td>summary.graphics</td> |
| 605 | * <td>The graphics usage in kB. This corresponds to the Graphics field in the |
| 606 | * App Summary section output by dumpsys meminfo.</td> |
| 607 | * <td>{@code 1442}</td> |
| 608 | * <td>23</td> |
| 609 | * </tr> |
| 610 | * <tr> |
| 611 | * <td>summary.private-other</td> |
| 612 | * <td>Other private memory usage in kB. This corresponds to the Private Other |
| 613 | * field output in the App Summary section by dumpsys meminfo.</td> |
| 614 | * <td>{@code 1442}</td> |
| 615 | * <td>23</td> |
| 616 | * </tr> |
| 617 | * <tr> |
| 618 | * <td>summary.system</td> |
| 619 | * <td>Shared and system memory usage in kB. This corresponds to the System |
| 620 | * field output in the App Summary section by dumpsys meminfo.</td> |
| 621 | * <td>{@code 1442}</td> |
| 622 | * <td>23</td> |
| 623 | * </tr> |
| 624 | * <tr> |
| 625 | * <td>summary.total-pss</td> |
| 626 | * <td>Total PPS memory usage in kB.</td> |
| 627 | * <td>{@code 1442}</td> |
| 628 | * <td>23</td> |
| 629 | * </tr> |
| 630 | * <tr> |
| 631 | * <td>summary.total-swap</td> |
| 632 | * <td>Total swap usage in kB.</td> |
| 633 | * <td>{@code 1442}</td> |
| 634 | * <td>23</td> |
| 635 | * </tr> |
| 636 | * </tbody> |
| 637 | * </table> |
| 638 | */ |
Dianne Hackborn | b02ce29 | 2015-10-12 15:14:16 -0700 | [diff] [blame] | 639 | public String getMemoryStat(String statName) { |
Richard Uhler | 350e6dc | 2015-05-18 10:48:52 -0700 | [diff] [blame] | 640 | switch(statName) { |
| 641 | case "summary.java-heap": |
| 642 | return Integer.toString(getSummaryJavaHeap()); |
| 643 | case "summary.native-heap": |
| 644 | return Integer.toString(getSummaryNativeHeap()); |
| 645 | case "summary.code": |
| 646 | return Integer.toString(getSummaryCode()); |
| 647 | case "summary.stack": |
| 648 | return Integer.toString(getSummaryStack()); |
| 649 | case "summary.graphics": |
| 650 | return Integer.toString(getSummaryGraphics()); |
| 651 | case "summary.private-other": |
| 652 | return Integer.toString(getSummaryPrivateOther()); |
| 653 | case "summary.system": |
| 654 | return Integer.toString(getSummarySystem()); |
| 655 | case "summary.total-pss": |
| 656 | return Integer.toString(getSummaryTotalPss()); |
| 657 | case "summary.total-swap": |
| 658 | return Integer.toString(getSummaryTotalSwap()); |
| 659 | default: |
| 660 | return null; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * Returns a map of the names/values of the memory statistics |
| 666 | * that {@link #getMemoryStat(String)} supports. |
| 667 | * |
| 668 | * @return a map of the names/values of the supported memory statistics. |
| 669 | */ |
| 670 | public Map<String, String> getMemoryStats() { |
| 671 | Map<String, String> stats = new HashMap<String, String>(); |
| 672 | stats.put("summary.java-heap", Integer.toString(getSummaryJavaHeap())); |
| 673 | stats.put("summary.native-heap", Integer.toString(getSummaryNativeHeap())); |
| 674 | stats.put("summary.code", Integer.toString(getSummaryCode())); |
| 675 | stats.put("summary.stack", Integer.toString(getSummaryStack())); |
| 676 | stats.put("summary.graphics", Integer.toString(getSummaryGraphics())); |
| 677 | stats.put("summary.private-other", Integer.toString(getSummaryPrivateOther())); |
| 678 | stats.put("summary.system", Integer.toString(getSummarySystem())); |
| 679 | stats.put("summary.total-pss", Integer.toString(getSummaryTotalPss())); |
| 680 | stats.put("summary.total-swap", Integer.toString(getSummaryTotalSwap())); |
| 681 | return stats; |
| 682 | } |
| 683 | |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 684 | /** |
| 685 | * Pss of Java Heap bytes in KB due to the application. |
| 686 | * Notes: |
| 687 | * * OTHER_ART is the boot image. Anything private here is blamed on |
| 688 | * the application, not the system. |
| 689 | * * dalvikPrivateDirty includes private zygote, which means the |
| 690 | * application dirtied something allocated by the zygote. We blame |
| 691 | * the application for that memory, not the system. |
| 692 | * * Does not include OTHER_DALVIK_OTHER, which is considered VM |
| 693 | * Overhead and lumped into Private Other. |
| 694 | * * We don't include dalvikPrivateClean, because there should be no |
| 695 | * such thing as private clean for the Java Heap. |
| 696 | * @hide |
| 697 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 698 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 699 | public int getSummaryJavaHeap() { |
| 700 | return dalvikPrivateDirty + getOtherPrivate(OTHER_ART); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Pss of Native Heap bytes in KB due to the application. |
| 705 | * Notes: |
| 706 | * * Includes private dirty malloc space. |
| 707 | * * We don't include nativePrivateClean, because there should be no |
| 708 | * such thing as private clean for the Native Heap. |
| 709 | * @hide |
| 710 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 711 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 712 | public int getSummaryNativeHeap() { |
| 713 | return nativePrivateDirty; |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Pss of code and other static resource bytes in KB due to |
| 718 | * the application. |
| 719 | * @hide |
| 720 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 721 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 722 | public int getSummaryCode() { |
| 723 | return getOtherPrivate(OTHER_SO) |
| 724 | + getOtherPrivate(OTHER_JAR) |
| 725 | + getOtherPrivate(OTHER_APK) |
| 726 | + getOtherPrivate(OTHER_TTF) |
| 727 | + getOtherPrivate(OTHER_DEX) |
Nicolas Geoffray | 0567cd4 | 2019-10-02 21:11:43 +0100 | [diff] [blame] | 728 | + getOtherPrivate(OTHER_OAT) |
| 729 | + getOtherPrivate(OTHER_DALVIK_OTHER_ZYGOTE_CODE_CACHE) |
| 730 | + getOtherPrivate(OTHER_DALVIK_OTHER_APP_CODE_CACHE); |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Pss in KB of the stack due to the application. |
| 735 | * Notes: |
| 736 | * * Includes private dirty stack, which includes both Java and Native |
| 737 | * stack. |
| 738 | * * Does not include private clean stack, because there should be no |
| 739 | * such thing as private clean for the stack. |
| 740 | * @hide |
| 741 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 742 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 743 | public int getSummaryStack() { |
| 744 | return getOtherPrivateDirty(OTHER_STACK); |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Pss in KB of graphics due to the application. |
| 749 | * Notes: |
| 750 | * * Includes private Gfx, EGL, and GL. |
| 751 | * * Warning: These numbers can be misreported by the graphics drivers. |
| 752 | * * We don't include shared graphics. It may make sense to, because |
| 753 | * shared graphics are likely buffers due to the application |
| 754 | * anyway, but it's simpler to implement to just group all shared |
| 755 | * memory into the System category. |
| 756 | * @hide |
| 757 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 758 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 759 | public int getSummaryGraphics() { |
| 760 | return getOtherPrivate(OTHER_GL_DEV) |
| 761 | + getOtherPrivate(OTHER_GRAPHICS) |
| 762 | + getOtherPrivate(OTHER_GL); |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * Pss in KB due to the application that haven't otherwise been |
| 767 | * accounted for. |
| 768 | * @hide |
| 769 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 770 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 771 | public int getSummaryPrivateOther() { |
| 772 | return getTotalPrivateClean() |
| 773 | + getTotalPrivateDirty() |
| 774 | - getSummaryJavaHeap() |
| 775 | - getSummaryNativeHeap() |
| 776 | - getSummaryCode() |
| 777 | - getSummaryStack() |
| 778 | - getSummaryGraphics(); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Pss in KB due to the system. |
| 783 | * Notes: |
| 784 | * * Includes all shared memory. |
| 785 | * @hide |
| 786 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 787 | @UnsupportedAppUsage |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 788 | public int getSummarySystem() { |
| 789 | return getTotalPss() |
| 790 | - getTotalPrivateClean() |
| 791 | - getTotalPrivateDirty(); |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Total Pss in KB. |
| 796 | * @hide |
| 797 | */ |
| 798 | public int getSummaryTotalPss() { |
| 799 | return getTotalPss(); |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * Total Swap in KB. |
| 804 | * Notes: |
| 805 | * * Some of this memory belongs in other categories, but we don't |
| 806 | * know if the Swap memory is shared or private, so we don't know |
| 807 | * what to blame on the application and what on the system. |
| 808 | * For now, just lump all the Swap in one place. |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 809 | * For kernels reporting SwapPss {@link #getSummaryTotalSwapPss()} |
| 810 | * will report the application proportional Swap. |
Richard Uhler | c14b9cf | 2015-03-13 12:38:38 -0700 | [diff] [blame] | 811 | * @hide |
| 812 | */ |
| 813 | public int getSummaryTotalSwap() { |
| 814 | return getTotalSwappedOut(); |
| 815 | } |
| 816 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 817 | /** |
| 818 | * Total proportional Swap in KB. |
| 819 | * Notes: |
| 820 | * * Always 0 if {@link #hasSwappedOutPss} is false. |
| 821 | * @hide |
| 822 | */ |
| 823 | public int getSummaryTotalSwapPss() { |
| 824 | return getTotalSwappedOutPss(); |
| 825 | } |
| 826 | |
Dianne Hackborn | ef0a402 | 2016-05-11 14:21:07 -0700 | [diff] [blame] | 827 | /** |
| 828 | * Return true if the kernel is reporting pss swapped out... that is, if |
| 829 | * {@link #getSummaryTotalSwapPss()} will return non-0 values. |
| 830 | * @hide |
| 831 | */ |
| 832 | public boolean hasSwappedOutPss() { |
| 833 | return hasSwappedOutPss; |
| 834 | } |
| 835 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 836 | public int describeContents() { |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | public void writeToParcel(Parcel dest, int flags) { |
| 841 | dest.writeInt(dalvikPss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 842 | dest.writeInt(dalvikSwappablePss); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 843 | dest.writeInt(dalvikRss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 844 | dest.writeInt(dalvikPrivateDirty); |
| 845 | dest.writeInt(dalvikSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 846 | dest.writeInt(dalvikPrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 847 | dest.writeInt(dalvikSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 848 | dest.writeInt(dalvikSwappedOut); |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 849 | dest.writeInt(dalvikSwappedOutPss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 850 | dest.writeInt(nativePss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 851 | dest.writeInt(nativeSwappablePss); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 852 | dest.writeInt(nativeRss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 853 | dest.writeInt(nativePrivateDirty); |
| 854 | dest.writeInt(nativeSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 855 | dest.writeInt(nativePrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 856 | dest.writeInt(nativeSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 857 | dest.writeInt(nativeSwappedOut); |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 858 | dest.writeInt(nativeSwappedOutPss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 859 | dest.writeInt(otherPss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 860 | dest.writeInt(otherSwappablePss); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 861 | dest.writeInt(otherRss); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 862 | dest.writeInt(otherPrivateDirty); |
| 863 | dest.writeInt(otherSharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 864 | dest.writeInt(otherPrivateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 865 | dest.writeInt(otherSharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 866 | dest.writeInt(otherSwappedOut); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 867 | dest.writeInt(hasSwappedOutPss ? 1 : 0); |
| 868 | dest.writeInt(otherSwappedOutPss); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 869 | dest.writeIntArray(otherStats); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | public void readFromParcel(Parcel source) { |
| 873 | dalvikPss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 874 | dalvikSwappablePss = source.readInt(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 875 | dalvikRss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 876 | dalvikPrivateDirty = source.readInt(); |
| 877 | dalvikSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 878 | dalvikPrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 879 | dalvikSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 880 | dalvikSwappedOut = source.readInt(); |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 881 | dalvikSwappedOutPss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 882 | nativePss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 883 | nativeSwappablePss = source.readInt(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 884 | nativeRss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 885 | nativePrivateDirty = source.readInt(); |
| 886 | nativeSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 887 | nativePrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 888 | nativeSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 889 | nativeSwappedOut = source.readInt(); |
Richard Uhler | 91702eb3 | 2017-06-23 16:54:25 +0100 | [diff] [blame] | 890 | nativeSwappedOutPss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 891 | otherPss = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 892 | otherSwappablePss = source.readInt(); |
Dianne Hackborn | e17b445 | 2018-01-10 13:15:40 -0800 | [diff] [blame] | 893 | otherRss = source.readInt(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 894 | otherPrivateDirty = source.readInt(); |
| 895 | otherSharedDirty = source.readInt(); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 896 | otherPrivateClean = source.readInt(); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 897 | otherSharedClean = source.readInt(); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 898 | otherSwappedOut = source.readInt(); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 899 | hasSwappedOutPss = source.readInt() != 0; |
| 900 | otherSwappedOutPss = source.readInt(); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 901 | otherStats = source.createIntArray(); |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 902 | } |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 903 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 904 | public static final @android.annotation.NonNull Creator<MemoryInfo> CREATOR = new Creator<MemoryInfo>() { |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 905 | public MemoryInfo createFromParcel(Parcel source) { |
| 906 | return new MemoryInfo(source); |
| 907 | } |
| 908 | public MemoryInfo[] newArray(int size) { |
| 909 | return new MemoryInfo[size]; |
| 910 | } |
| 911 | }; |
| 912 | |
| 913 | private MemoryInfo(Parcel source) { |
| 914 | readFromParcel(source); |
| 915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | |
| 919 | /** |
| 920 | * Wait until a debugger attaches. As soon as the debugger attaches, |
| 921 | * this returns, so you will need to place a breakpoint after the |
| 922 | * waitForDebugger() call if you want to start tracing immediately. |
| 923 | */ |
| 924 | public static void waitForDebugger() { |
| 925 | if (!VMDebug.isDebuggingEnabled()) { |
| 926 | //System.out.println("debugging not enabled, not waiting"); |
| 927 | return; |
| 928 | } |
| 929 | if (isDebuggerConnected()) |
| 930 | return; |
| 931 | |
| 932 | // if DDMS is listening, inform them of our plight |
| 933 | System.out.println("Sending WAIT chunk"); |
| 934 | byte[] data = new byte[] { 0 }; // 0 == "waiting for debugger" |
| 935 | Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1); |
| 936 | DdmServer.sendChunk(waitChunk); |
| 937 | |
| 938 | mWaiting = true; |
| 939 | while (!isDebuggerConnected()) { |
| 940 | try { Thread.sleep(SPIN_DELAY); } |
| 941 | catch (InterruptedException ie) {} |
| 942 | } |
| 943 | mWaiting = false; |
| 944 | |
| 945 | System.out.println("Debugger has connected"); |
| 946 | |
| 947 | /* |
| 948 | * There is no "ready to go" signal from the debugger, and we're |
| 949 | * not allowed to suspend ourselves -- the debugger expects us to |
| 950 | * be running happily, and gets confused if we aren't. We need to |
| 951 | * allow the debugger a chance to set breakpoints before we start |
| 952 | * running again. |
| 953 | * |
| 954 | * Sit and spin until the debugger has been idle for a short while. |
| 955 | */ |
| 956 | while (true) { |
| 957 | long delta = VMDebug.lastDebuggerActivity(); |
| 958 | if (delta < 0) { |
| 959 | System.out.println("debugger detached?"); |
| 960 | break; |
| 961 | } |
| 962 | |
| 963 | if (delta < MIN_DEBUGGER_IDLE) { |
| 964 | System.out.println("waiting for debugger to settle..."); |
| 965 | try { Thread.sleep(SPIN_DELAY); } |
| 966 | catch (InterruptedException ie) {} |
| 967 | } else { |
| 968 | System.out.println("debugger has settled (" + delta + ")"); |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | /** |
| 975 | * Returns "true" if one or more threads is waiting for a debugger |
| 976 | * to attach. |
| 977 | */ |
| 978 | public static boolean waitingForDebugger() { |
| 979 | return mWaiting; |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * Determine if a debugger is currently attached. |
| 984 | */ |
| 985 | public static boolean isDebuggerConnected() { |
| 986 | return VMDebug.isDebuggerConnected(); |
| 987 | } |
| 988 | |
| 989 | /** |
Andy McFadden | e577232 | 2010-01-22 07:23:31 -0800 | [diff] [blame] | 990 | * Returns an array of strings that identify VM features. This is |
| 991 | * used by DDMS to determine what sorts of operations the VM can |
| 992 | * perform. |
| 993 | * |
| 994 | * @hide |
| 995 | */ |
| 996 | public static String[] getVmFeatureList() { |
| 997 | return VMDebug.getVmFeatureList(); |
| 998 | } |
| 999 | |
| 1000 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | * Change the JDWP port. |
| 1002 | * |
| 1003 | * @deprecated no longer needed or useful |
| 1004 | */ |
| 1005 | @Deprecated |
| 1006 | public static void changeDebugPort(int port) {} |
| 1007 | |
| 1008 | /** |
| 1009 | * This is the pathname to the sysfs file that enables and disables |
| 1010 | * tracing on the qemu emulator. |
| 1011 | */ |
| 1012 | private static final String SYSFS_QEMU_TRACE_STATE = "/sys/qemu_trace/state"; |
| 1013 | |
| 1014 | /** |
| 1015 | * Enable qemu tracing. For this to work requires running everything inside |
| 1016 | * the qemu emulator; otherwise, this method will have no effect. The trace |
| 1017 | * file is specified on the command line when the emulator is started. For |
| 1018 | * example, the following command line <br /> |
| 1019 | * <code>emulator -trace foo</code><br /> |
| 1020 | * will start running the emulator and create a trace file named "foo". This |
| 1021 | * method simply enables writing the trace records to the trace file. |
| 1022 | * |
| 1023 | * <p> |
| 1024 | * The main differences between this and {@link #startMethodTracing()} are |
| 1025 | * that tracing in the qemu emulator traces every cpu instruction of every |
| 1026 | * process, including kernel code, so we have more complete information, |
| 1027 | * including all context switches. We can also get more detailed information |
| 1028 | * such as cache misses. The sequence of calls is determined by |
| 1029 | * post-processing the instruction trace. The qemu tracing is also done |
| 1030 | * without modifying the application or perturbing the timing of calls |
| 1031 | * because no instrumentation is added to the application being traced. |
| 1032 | * </p> |
| 1033 | * |
| 1034 | * <p> |
| 1035 | * One limitation of using this method compared to using |
| 1036 | * {@link #startMethodTracing()} on the real device is that the emulator |
| 1037 | * does not model all of the real hardware effects such as memory and |
| 1038 | * bus contention. The emulator also has a simple cache model and cannot |
| 1039 | * capture all the complexities of a real cache. |
| 1040 | * </p> |
| 1041 | */ |
| 1042 | public static void startNativeTracing() { |
| 1043 | // Open the sysfs file for writing and write "1" to it. |
| 1044 | PrintWriter outStream = null; |
| 1045 | try { |
| 1046 | FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1047 | outStream = new FastPrintWriter(fos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | outStream.println("1"); |
| 1049 | } catch (Exception e) { |
| 1050 | } finally { |
| 1051 | if (outStream != null) |
| 1052 | outStream.close(); |
| 1053 | } |
| 1054 | |
| 1055 | VMDebug.startEmulatorTracing(); |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * Stop qemu tracing. See {@link #startNativeTracing()} to start tracing. |
| 1060 | * |
| 1061 | * <p>Tracing can be started and stopped as many times as desired. When |
| 1062 | * the qemu emulator itself is stopped then the buffered trace records |
| 1063 | * are flushed and written to the trace file. In fact, it is not necessary |
| 1064 | * to call this method at all; simply killing qemu is sufficient. But |
| 1065 | * starting and stopping a trace is useful for examining a specific |
| 1066 | * region of code.</p> |
| 1067 | */ |
| 1068 | public static void stopNativeTracing() { |
| 1069 | VMDebug.stopEmulatorTracing(); |
| 1070 | |
| 1071 | // Open the sysfs file for writing and write "0" to it. |
| 1072 | PrintWriter outStream = null; |
| 1073 | try { |
| 1074 | FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 1075 | outStream = new FastPrintWriter(fos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | outStream.println("0"); |
| 1077 | } catch (Exception e) { |
| 1078 | // We could print an error message here but we probably want |
| 1079 | // to quietly ignore errors if we are not running in the emulator. |
| 1080 | } finally { |
| 1081 | if (outStream != null) |
| 1082 | outStream.close(); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * Enable "emulator traces", in which information about the current |
| 1088 | * method is made available to the "emulator -trace" feature. There |
| 1089 | * is no corresponding "disable" call -- this is intended for use by |
| 1090 | * the framework when tracing should be turned on and left that way, so |
| 1091 | * that traces captured with F9/F10 will include the necessary data. |
| 1092 | * |
| 1093 | * This puts the VM into "profile" mode, which has performance |
| 1094 | * consequences. |
| 1095 | * |
| 1096 | * To temporarily enable tracing, use {@link #startNativeTracing()}. |
| 1097 | */ |
| 1098 | public static void enableEmulatorTraceOutput() { |
| 1099 | VMDebug.startEmulatorTracing(); |
| 1100 | } |
| 1101 | |
| 1102 | /** |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1103 | * Start method tracing with default log name and buffer size. |
| 1104 | * <p> |
| 1105 | * By default, the trace file is called "dmtrace.trace" and it's placed |
| 1106 | * under your package-specific directory on primary shared/external storage, |
| 1107 | * as returned by {@link Context#getExternalFilesDir(String)}. |
| 1108 | * <p> |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 1109 | * See <a href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs |
| 1110 | * with Traceview</a> for information about reading trace files. |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1111 | * <p class="note"> |
| 1112 | * When method tracing is enabled, the VM will run more slowly than usual, |
| 1113 | * so the timings from the trace files should only be considered in relative |
| 1114 | * terms (e.g. was run #1 faster than run #2). The times for native methods |
| 1115 | * will not change, so don't try to use this to compare the performance of |
| 1116 | * interpreted and native implementations of the same method. As an |
| 1117 | * alternative, consider using sampling-based method tracing via |
| 1118 | * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing |
| 1119 | * in the emulator via {@link #startNativeTracing()}. |
| 1120 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | */ |
| 1122 | public static void startMethodTracing() { |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1123 | VMDebug.startMethodTracing(fixTracePath(null), 0, 0, false, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /** |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1127 | * Start method tracing, specifying the trace log file path. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | * <p> |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1129 | * When a relative file path is given, the trace file will be placed under |
| 1130 | * your package-specific directory on primary shared/external storage, as |
| 1131 | * returned by {@link Context#getExternalFilesDir(String)}. |
| 1132 | * <p> |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 1133 | * See <a href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs |
| 1134 | * with Traceview</a> for information about reading trace files. |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1135 | * <p class="note"> |
| 1136 | * When method tracing is enabled, the VM will run more slowly than usual, |
| 1137 | * so the timings from the trace files should only be considered in relative |
| 1138 | * terms (e.g. was run #1 faster than run #2). The times for native methods |
| 1139 | * will not change, so don't try to use this to compare the performance of |
| 1140 | * interpreted and native implementations of the same method. As an |
| 1141 | * alternative, consider using sampling-based method tracing via |
| 1142 | * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing |
| 1143 | * in the emulator via {@link #startNativeTracing()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | * </p> |
| 1145 | * |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1146 | * @param tracePath Path to the trace log file to create. If {@code null}, |
| 1147 | * this will default to "dmtrace.trace". If the file already |
| 1148 | * exists, it will be truncated. If the path given does not end |
| 1149 | * in ".trace", it will be appended for you. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | */ |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1151 | public static void startMethodTracing(String tracePath) { |
| 1152 | startMethodTracing(tracePath, 0, 0); |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * Start method tracing, specifying the trace log file name and the buffer |
| 1157 | * size. |
| 1158 | * <p> |
| 1159 | * When a relative file path is given, the trace file will be placed under |
| 1160 | * your package-specific directory on primary shared/external storage, as |
| 1161 | * returned by {@link Context#getExternalFilesDir(String)}. |
| 1162 | * <p> |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 1163 | * See <a href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs |
| 1164 | * with Traceview</a> for information about reading trace files. |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1165 | * <p class="note"> |
| 1166 | * When method tracing is enabled, the VM will run more slowly than usual, |
| 1167 | * so the timings from the trace files should only be considered in relative |
| 1168 | * terms (e.g. was run #1 faster than run #2). The times for native methods |
| 1169 | * will not change, so don't try to use this to compare the performance of |
| 1170 | * interpreted and native implementations of the same method. As an |
| 1171 | * alternative, consider using sampling-based method tracing via |
| 1172 | * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing |
| 1173 | * in the emulator via {@link #startNativeTracing()}. |
| 1174 | * </p> |
| 1175 | * |
| 1176 | * @param tracePath Path to the trace log file to create. If {@code null}, |
| 1177 | * this will default to "dmtrace.trace". If the file already |
| 1178 | * exists, it will be truncated. If the path given does not end |
| 1179 | * in ".trace", it will be appended for you. |
| 1180 | * @param bufferSize The maximum amount of trace data we gather. If not |
| 1181 | * given, it defaults to 8MB. |
| 1182 | */ |
| 1183 | public static void startMethodTracing(String tracePath, int bufferSize) { |
| 1184 | startMethodTracing(tracePath, bufferSize, 0); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Start method tracing, specifying the trace log file name, the buffer |
| 1189 | * size, and flags. |
| 1190 | * <p> |
| 1191 | * When a relative file path is given, the trace file will be placed under |
| 1192 | * your package-specific directory on primary shared/external storage, as |
| 1193 | * returned by {@link Context#getExternalFilesDir(String)}. |
| 1194 | * <p> |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 1195 | * See <a href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs |
| 1196 | * with Traceview</a> for information about reading trace files. |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1197 | * <p class="note"> |
| 1198 | * When method tracing is enabled, the VM will run more slowly than usual, |
| 1199 | * so the timings from the trace files should only be considered in relative |
| 1200 | * terms (e.g. was run #1 faster than run #2). The times for native methods |
| 1201 | * will not change, so don't try to use this to compare the performance of |
| 1202 | * interpreted and native implementations of the same method. As an |
| 1203 | * alternative, consider using sampling-based method tracing via |
| 1204 | * {@link #startMethodTracingSampling(String, int, int)} or "native" tracing |
| 1205 | * in the emulator via {@link #startNativeTracing()}. |
| 1206 | * </p> |
| 1207 | * |
| 1208 | * @param tracePath Path to the trace log file to create. If {@code null}, |
| 1209 | * this will default to "dmtrace.trace". If the file already |
| 1210 | * exists, it will be truncated. If the path given does not end |
| 1211 | * in ".trace", it will be appended for you. |
| 1212 | * @param bufferSize The maximum amount of trace data we gather. If not |
| 1213 | * given, it defaults to 8MB. |
| 1214 | * @param flags Flags to control method tracing. The only one that is |
| 1215 | * currently defined is {@link #TRACE_COUNT_ALLOCS}. |
| 1216 | */ |
| 1217 | public static void startMethodTracing(String tracePath, int bufferSize, int flags) { |
| 1218 | VMDebug.startMethodTracing(fixTracePath(tracePath), bufferSize, flags, false, 0); |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1221 | /** |
| 1222 | * Start sampling-based method tracing, specifying the trace log file name, |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1223 | * the buffer size, and the sampling interval. |
| 1224 | * <p> |
| 1225 | * When a relative file path is given, the trace file will be placed under |
| 1226 | * your package-specific directory on primary shared/external storage, as |
| 1227 | * returned by {@link Context#getExternalFilesDir(String)}. |
| 1228 | * <p> |
Ricardo Loo Foronda | ac750a8 | 2018-01-25 09:10:47 -0800 | [diff] [blame] | 1229 | * See <a href="{@docRoot}studio/profile/traceview.html">Inspect Trace Logs |
| 1230 | * with Traceview</a> for information about reading trace files. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1231 | * |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1232 | * @param tracePath Path to the trace log file to create. If {@code null}, |
| 1233 | * this will default to "dmtrace.trace". If the file already |
| 1234 | * exists, it will be truncated. If the path given does not end |
| 1235 | * in ".trace", it will be appended for you. |
| 1236 | * @param bufferSize The maximum amount of trace data we gather. If not |
| 1237 | * given, it defaults to 8MB. |
| 1238 | * @param intervalUs The amount of time between each sample in microseconds. |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1239 | */ |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1240 | public static void startMethodTracingSampling(String tracePath, int bufferSize, |
| 1241 | int intervalUs) { |
| 1242 | VMDebug.startMethodTracing(fixTracePath(tracePath), bufferSize, 0, true, intervalUs); |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1243 | } |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1244 | |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1245 | /** |
| 1246 | * Formats name of trace log file for method tracing. |
| 1247 | */ |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1248 | private static String fixTracePath(String tracePath) { |
| 1249 | if (tracePath == null || tracePath.charAt(0) != '/') { |
| 1250 | final Context context = AppGlobals.getInitialApplication(); |
| 1251 | final File dir; |
| 1252 | if (context != null) { |
| 1253 | dir = context.getExternalFilesDir(null); |
| 1254 | } else { |
| 1255 | dir = Environment.getExternalStorageDirectory(); |
| 1256 | } |
Jeff Hao | d02e60f | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 1257 | |
Jeff Sharkey | 3a6e0ec | 2016-03-21 16:42:57 -0600 | [diff] [blame] | 1258 | if (tracePath == null) { |
| 1259 | tracePath = new File(dir, DEFAULT_TRACE_BODY).getAbsolutePath(); |
| 1260 | } else { |
| 1261 | tracePath = new File(dir, tracePath).getAbsolutePath(); |
| 1262 | } |
| 1263 | } |
| 1264 | if (!tracePath.endsWith(DEFAULT_TRACE_EXTENSION)) { |
| 1265 | tracePath += DEFAULT_TRACE_EXTENSION; |
| 1266 | } |
| 1267 | return tracePath; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | /** |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1271 | * Like startMethodTracing(String, int, int), but taking an already-opened |
| 1272 | * FileDescriptor in which the trace is written. The file name is also |
| 1273 | * supplied simply for logging. Makes a dup of the file descriptor. |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 1274 | * |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1275 | * Not exposed in the SDK unless we are really comfortable with supporting |
| 1276 | * this and find it would be useful. |
| 1277 | * @hide |
| 1278 | */ |
| 1279 | public static void startMethodTracing(String traceName, FileDescriptor fd, |
Shukang Zhou | 6ec0b7e | 2017-01-24 15:30:29 -0800 | [diff] [blame] | 1280 | int bufferSize, int flags, boolean streamOutput) { |
| 1281 | VMDebug.startMethodTracing(traceName, fd, bufferSize, flags, false, 0, streamOutput); |
Dianne Hackborn | 9c8dd55 | 2009-06-23 19:22:52 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | /** |
Andy McFadden | 72a20db0c | 2010-01-22 12:20:41 -0800 | [diff] [blame] | 1285 | * Starts method tracing without a backing file. When stopMethodTracing |
| 1286 | * is called, the result is sent directly to DDMS. (If DDMS is not |
| 1287 | * attached when tracing ends, the profiling data will be discarded.) |
| 1288 | * |
| 1289 | * @hide |
| 1290 | */ |
Jeff Hao | 7be3a13 | 2013-08-22 15:53:12 -0700 | [diff] [blame] | 1291 | public static void startMethodTracingDdms(int bufferSize, int flags, |
| 1292 | boolean samplingEnabled, int intervalUs) { |
| 1293 | VMDebug.startMethodTracingDdms(bufferSize, flags, samplingEnabled, intervalUs); |
Andy McFadden | 72a20db0c | 2010-01-22 12:20:41 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | /** |
Jeff Hao | ac27705 | 2013-08-29 11:19:39 -0700 | [diff] [blame] | 1297 | * Determine whether method tracing is currently active and what type is |
| 1298 | * active. |
| 1299 | * |
The Android Open Source Project | 7b0b1ed | 2009-03-18 22:20:26 -0700 | [diff] [blame] | 1300 | * @hide |
| 1301 | */ |
Jeff Hao | ac27705 | 2013-08-29 11:19:39 -0700 | [diff] [blame] | 1302 | public static int getMethodTracingMode() { |
| 1303 | return VMDebug.getMethodTracingMode(); |
The Android Open Source Project | 7b0b1ed | 2009-03-18 22:20:26 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | * Stop method tracing. |
| 1308 | */ |
| 1309 | public static void stopMethodTracing() { |
| 1310 | VMDebug.stopMethodTracing(); |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * Get an indication of thread CPU usage. The value returned |
| 1315 | * indicates the amount of time that the current thread has spent |
| 1316 | * executing code or waiting for certain types of I/O. |
| 1317 | * |
| 1318 | * The time is expressed in nanoseconds, and is only meaningful |
| 1319 | * when compared to the result from an earlier call. Note that |
| 1320 | * nanosecond resolution does not imply nanosecond accuracy. |
| 1321 | * |
| 1322 | * On system which don't support this operation, the call returns -1. |
| 1323 | */ |
| 1324 | public static long threadCpuTimeNanos() { |
| 1325 | return VMDebug.threadCpuTimeNanos(); |
| 1326 | } |
| 1327 | |
| 1328 | /** |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1329 | * Start counting the number and aggregate size of memory allocations. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | * |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1331 | * <p>The {@link #startAllocCounting() start} method resets the counts and enables counting. |
| 1332 | * The {@link #stopAllocCounting() stop} method disables the counting so that the analysis |
| 1333 | * code doesn't cause additional allocations. The various <code>get</code> methods return |
| 1334 | * the specified value. And the various <code>reset</code> methods reset the specified |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1335 | * count.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | * |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1337 | * <p>Counts are kept for the system as a whole (global) and for each thread. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | * The per-thread counts for threads other than the current thread |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1339 | * are not cleared by the "reset" or "start" calls.</p> |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1340 | * |
| 1341 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | */ |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1343 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | public static void startAllocCounting() { |
| 1345 | VMDebug.startAllocCounting(); |
| 1346 | } |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1347 | |
| 1348 | /** |
| 1349 | * Stop counting the number and aggregate size of memory allocations. |
| 1350 | * |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1351 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 1352 | */ |
Ian Rogers | c2a3adb | 2013-04-19 11:31:48 -0700 | [diff] [blame] | 1353 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | public static void stopAllocCounting() { |
| 1355 | VMDebug.stopAllocCounting(); |
| 1356 | } |
| 1357 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1358 | /** |
| 1359 | * Returns the global count of objects allocated by the runtime between a |
| 1360 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1361 | * |
| 1362 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1363 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1364 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1365 | public static int getGlobalAllocCount() { |
| 1366 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS); |
| 1367 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1368 | |
| 1369 | /** |
| 1370 | * Clears the global count of objects allocated. |
| 1371 | * @see #getGlobalAllocCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1372 | * |
| 1373 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1374 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1375 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1376 | public static void resetGlobalAllocCount() { |
| 1377 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_OBJECTS); |
| 1378 | } |
| 1379 | |
| 1380 | /** |
| 1381 | * Returns the global size, in bytes, of objects allocated by the runtime between a |
| 1382 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1383 | * |
| 1384 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1385 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1386 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1387 | public static int getGlobalAllocSize() { |
| 1388 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES); |
| 1389 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1390 | |
| 1391 | /** |
| 1392 | * Clears the global size of objects allocated. |
Dianne Hackborn | 3fa8969 | 2013-09-13 17:20:00 -0700 | [diff] [blame] | 1393 | * @see #getGlobalAllocSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1394 | * |
| 1395 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1396 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1397 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1398 | public static void resetGlobalAllocSize() { |
| 1399 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_ALLOCATED_BYTES); |
| 1400 | } |
| 1401 | |
| 1402 | /** |
| 1403 | * Returns the global count of objects freed by the runtime between a |
| 1404 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1405 | * |
| 1406 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1407 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1408 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | public static int getGlobalFreedCount() { |
| 1410 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS); |
| 1411 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1412 | |
| 1413 | /** |
| 1414 | * Clears the global count of objects freed. |
| 1415 | * @see #getGlobalFreedCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1416 | * |
| 1417 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1418 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1419 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1420 | public static void resetGlobalFreedCount() { |
| 1421 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_OBJECTS); |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * Returns the global size, in bytes, of objects freed by the runtime between a |
| 1426 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1427 | * |
| 1428 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1429 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1430 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | public static int getGlobalFreedSize() { |
| 1432 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES); |
| 1433 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1434 | |
| 1435 | /** |
| 1436 | * Clears the global size of objects freed. |
| 1437 | * @see #getGlobalFreedSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1438 | * |
| 1439 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1440 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1441 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1442 | public static void resetGlobalFreedSize() { |
| 1443 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_FREED_BYTES); |
| 1444 | } |
| 1445 | |
| 1446 | /** |
| 1447 | * Returns the number of non-concurrent GC invocations between a |
| 1448 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1449 | * |
| 1450 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1451 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1452 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1453 | public static int getGlobalGcInvocationCount() { |
| 1454 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS); |
| 1455 | } |
| 1456 | |
| 1457 | /** |
| 1458 | * Clears the count of non-concurrent GC invocations. |
| 1459 | * @see #getGlobalGcInvocationCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1460 | * |
| 1461 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1462 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1463 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1464 | public static void resetGlobalGcInvocationCount() { |
| 1465 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_GC_INVOCATIONS); |
| 1466 | } |
| 1467 | |
| 1468 | /** |
| 1469 | * Returns the number of classes successfully initialized (ie those that executed without |
| 1470 | * throwing an exception) between a {@link #startAllocCounting() start} and |
| 1471 | * {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1472 | * |
| 1473 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1474 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1475 | @Deprecated |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1476 | public static int getGlobalClassInitCount() { |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1477 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT); |
| 1478 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1479 | |
| 1480 | /** |
| 1481 | * Clears the count of classes initialized. |
| 1482 | * @see #getGlobalClassInitCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1483 | * |
| 1484 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1485 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1486 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1487 | public static void resetGlobalClassInitCount() { |
| 1488 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_COUNT); |
| 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * Returns the time spent successfully initializing classes between a |
| 1493 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1494 | * |
| 1495 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1496 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1497 | @Deprecated |
Andy McFadden | c4e1bf7 | 2010-02-22 17:07:36 -0800 | [diff] [blame] | 1498 | public static int getGlobalClassInitTime() { |
| 1499 | /* cumulative elapsed time for class initialization, in usec */ |
| 1500 | return VMDebug.getAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME); |
| 1501 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1502 | |
| 1503 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1504 | * Clears the count of time spent initializing classes. |
| 1505 | * @see #getGlobalClassInitTime() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1506 | * |
| 1507 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1508 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1509 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1510 | public static void resetGlobalClassInitTime() { |
| 1511 | VMDebug.resetAllocCount(VMDebug.KIND_GLOBAL_CLASS_INIT_TIME); |
| 1512 | } |
| 1513 | |
| 1514 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1515 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1516 | * @deprecated This method is now obsolete. |
| 1517 | */ |
| 1518 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | public static int getGlobalExternalAllocCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1520 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1522 | |
| 1523 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1524 | * This method exists for compatibility and has no effect. |
| 1525 | * @deprecated This method is now obsolete. |
| 1526 | */ |
| 1527 | @Deprecated |
| 1528 | public static void resetGlobalExternalAllocSize() {} |
| 1529 | |
| 1530 | /** |
| 1531 | * This method exists for compatibility and has no effect. |
| 1532 | * @deprecated This method is now obsolete. |
| 1533 | */ |
| 1534 | @Deprecated |
| 1535 | public static void resetGlobalExternalAllocCount() {} |
| 1536 | |
| 1537 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1538 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1539 | * @deprecated This method is now obsolete. |
| 1540 | */ |
| 1541 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | public static int getGlobalExternalAllocSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1543 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1545 | |
| 1546 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1547 | * This method exists for compatibility and always returns 0. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1548 | * @deprecated This method is now obsolete. |
| 1549 | */ |
| 1550 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | public static int getGlobalExternalFreedCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1552 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1554 | |
| 1555 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1556 | * This method exists for compatibility and has no effect. |
| 1557 | * @deprecated This method is now obsolete. |
| 1558 | */ |
| 1559 | @Deprecated |
| 1560 | public static void resetGlobalExternalFreedCount() {} |
| 1561 | |
| 1562 | /** |
| 1563 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1564 | * @deprecated This method is now obsolete. |
| 1565 | */ |
| 1566 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | public static int getGlobalExternalFreedSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1568 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1570 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1571 | /** |
| 1572 | * This method exists for compatibility and has no effect. |
| 1573 | * @deprecated This method is now obsolete. |
| 1574 | */ |
| 1575 | @Deprecated |
| 1576 | public static void resetGlobalExternalFreedSize() {} |
| 1577 | |
| 1578 | /** |
| 1579 | * Returns the thread-local count of objects allocated by the runtime between a |
| 1580 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1581 | * |
| 1582 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1583 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1584 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | public static int getThreadAllocCount() { |
| 1586 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS); |
| 1587 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1588 | |
| 1589 | /** |
| 1590 | * Clears the thread-local count of objects allocated. |
| 1591 | * @see #getThreadAllocCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1592 | * |
| 1593 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1594 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1595 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1596 | public static void resetThreadAllocCount() { |
| 1597 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_OBJECTS); |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Returns the thread-local size of objects allocated by the runtime between a |
| 1602 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
| 1603 | * @return The allocated size in bytes. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1604 | * |
| 1605 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1606 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1607 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | public static int getThreadAllocSize() { |
| 1609 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES); |
| 1610 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1611 | |
| 1612 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1613 | * Clears the thread-local count of objects allocated. |
| 1614 | * @see #getThreadAllocSize() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1615 | * |
| 1616 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1617 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1618 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1619 | public static void resetThreadAllocSize() { |
| 1620 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_ALLOCATED_BYTES); |
| 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1625 | * @deprecated This method is now obsolete. |
| 1626 | */ |
| 1627 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | public static int getThreadExternalAllocCount() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1629 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1631 | |
| 1632 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1633 | * This method exists for compatibility and has no effect. |
| 1634 | * @deprecated This method is now obsolete. |
| 1635 | */ |
| 1636 | @Deprecated |
| 1637 | public static void resetThreadExternalAllocCount() {} |
| 1638 | |
| 1639 | /** |
| 1640 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1641 | * @deprecated This method is now obsolete. |
| 1642 | */ |
| 1643 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | public static int getThreadExternalAllocSize() { |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1645 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | } |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1647 | |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1648 | /** |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1649 | * This method exists for compatibility and has no effect. |
Carl Shapiro | b596198 | 2010-12-22 15:54:53 -0800 | [diff] [blame] | 1650 | * @deprecated This method is now obsolete. |
| 1651 | */ |
| 1652 | @Deprecated |
| 1653 | public static void resetThreadExternalAllocSize() {} |
| 1654 | |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1655 | /** |
| 1656 | * Returns the number of thread-local non-concurrent GC invocations between a |
| 1657 | * {@link #startAllocCounting() start} and {@link #stopAllocCounting() stop}. |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1658 | * |
| 1659 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1660 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1661 | @Deprecated |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1662 | public static int getThreadGcInvocationCount() { |
| 1663 | return VMDebug.getAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS); |
| 1664 | } |
| 1665 | |
| 1666 | /** |
| 1667 | * Clears the thread-local count of non-concurrent GC invocations. |
| 1668 | * @see #getThreadGcInvocationCount() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1669 | * |
| 1670 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1671 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1672 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | public static void resetThreadGcInvocationCount() { |
| 1674 | VMDebug.resetAllocCount(VMDebug.KIND_THREAD_GC_INVOCATIONS); |
| 1675 | } |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1676 | |
| 1677 | /** |
| 1678 | * Clears all the global and thread-local memory allocation counters. |
| 1679 | * @see #startAllocCounting() |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1680 | * |
| 1681 | * @deprecated Accurate counting is a burden on the runtime and may be removed. |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 1682 | */ |
Hiroshi Yamauchi | 172da26 | 2015-03-04 12:29:19 -0800 | [diff] [blame] | 1683 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | public static void resetAllCounts() { |
| 1685 | VMDebug.resetAllocCount(VMDebug.KIND_ALL_COUNTS); |
| 1686 | } |
| 1687 | |
| 1688 | /** |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1689 | * Returns the value of a particular runtime statistic or {@code null} if no |
| 1690 | * such runtime statistic exists. |
| 1691 | * |
| 1692 | * <p>The following table lists the runtime statistics that the runtime supports. |
Hans Boehm | 98491ba | 2019-10-08 17:54:47 -0700 | [diff] [blame] | 1693 | * All statistics are approximate. Individual allocations may not be immediately reflected |
| 1694 | * in the results. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1695 | * Note runtime statistics may be added or removed in a future API level.</p> |
| 1696 | * |
| 1697 | * <table> |
| 1698 | * <thead> |
| 1699 | * <tr> |
| 1700 | * <th>Runtime statistic name</th> |
| 1701 | * <th>Meaning</th> |
| 1702 | * <th>Example</th> |
| 1703 | * <th>Supported (API Levels)</th> |
| 1704 | * </tr> |
| 1705 | * </thead> |
| 1706 | * <tbody> |
| 1707 | * <tr> |
| 1708 | * <td>art.gc.gc-count</td> |
| 1709 | * <td>The number of garbage collection runs.</td> |
| 1710 | * <td>{@code 164}</td> |
| 1711 | * <td>23</td> |
| 1712 | * </tr> |
| 1713 | * <tr> |
| 1714 | * <td>art.gc.gc-time</td> |
| 1715 | * <td>The total duration of garbage collection runs in ms.</td> |
| 1716 | * <td>{@code 62364}</td> |
| 1717 | * <td>23</td> |
| 1718 | * </tr> |
| 1719 | * <tr> |
| 1720 | * <td>art.gc.bytes-allocated</td> |
| 1721 | * <td>The total number of bytes that the application allocated.</td> |
| 1722 | * <td>{@code 1463948408}</td> |
| 1723 | * <td>23</td> |
| 1724 | * </tr> |
| 1725 | * <tr> |
| 1726 | * <td>art.gc.bytes-freed</td> |
| 1727 | * <td>The total number of bytes that garbage collection reclaimed.</td> |
| 1728 | * <td>{@code 1313493084}</td> |
| 1729 | * <td>23</td> |
| 1730 | * </tr> |
| 1731 | * <tr> |
| 1732 | * <td>art.gc.blocking-gc-count</td> |
| 1733 | * <td>The number of blocking garbage collection runs.</td> |
| 1734 | * <td>{@code 2}</td> |
| 1735 | * <td>23</td> |
| 1736 | * </tr> |
| 1737 | * <tr> |
| 1738 | * <td>art.gc.blocking-gc-time</td> |
| 1739 | * <td>The total duration of blocking garbage collection runs in ms.</td> |
| 1740 | * <td>{@code 804}</td> |
| 1741 | * <td>23</td> |
| 1742 | * </tr> |
| 1743 | * <tr> |
| 1744 | * <td>art.gc.gc-count-rate-histogram</td> |
Hiroshi Yamauchi | 2d6327d | 2015-05-28 15:28:16 -0700 | [diff] [blame] | 1745 | * <td>Every 10 seconds, the gc-count-rate is computed as the number of garbage |
| 1746 | * collection runs that have occurred over the last 10 |
| 1747 | * seconds. art.gc.gc-count-rate-histogram is a histogram of the gc-count-rate |
| 1748 | * samples taken since the process began. The histogram can be used to identify |
| 1749 | * instances of high rates of garbage collection runs. For example, a histogram |
| 1750 | * of "0:34503,1:45350,2:11281,3:8088,4:43,5:8" shows that most of the time |
| 1751 | * there are between 0 and 2 garbage collection runs every 10 seconds, but there |
| 1752 | * were 8 distinct 10-second intervals in which 5 garbage collection runs |
| 1753 | * occurred.</td> |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1754 | * <td>{@code 0:34503,1:45350,2:11281,3:8088,4:43,5:8}</td> |
| 1755 | * <td>23</td> |
| 1756 | * </tr> |
| 1757 | * <tr> |
| 1758 | * <td>art.gc.blocking-gc-count-rate-histogram</td> |
Hiroshi Yamauchi | 2d6327d | 2015-05-28 15:28:16 -0700 | [diff] [blame] | 1759 | * <td>Every 10 seconds, the blocking-gc-count-rate is computed as the number of |
| 1760 | * blocking garbage collection runs that have occurred over the last 10 |
| 1761 | * seconds. art.gc.blocking-gc-count-rate-histogram is a histogram of the |
| 1762 | * blocking-gc-count-rate samples taken since the process began. The histogram |
| 1763 | * can be used to identify instances of high rates of blocking garbage |
| 1764 | * collection runs. For example, a histogram of "0:99269,1:1,2:1" shows that |
| 1765 | * most of the time there are zero blocking garbage collection runs every 10 |
| 1766 | * seconds, but there was one 10-second interval in which one blocking garbage |
| 1767 | * collection run occurred, and there was one interval in which two blocking |
| 1768 | * garbage collection runs occurred.</td> |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1769 | * <td>{@code 0:99269,1:1,2:1}</td> |
| 1770 | * <td>23</td> |
| 1771 | * </tr> |
| 1772 | * </tbody> |
| 1773 | * </table> |
| 1774 | * |
| 1775 | * @param statName |
| 1776 | * the name of the runtime statistic to look up. |
| 1777 | * @return the value of the specified runtime statistic or {@code null} if the |
| 1778 | * runtime statistic doesn't exist. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1779 | */ |
| 1780 | public static String getRuntimeStat(String statName) { |
| 1781 | return VMDebug.getRuntimeStat(statName); |
| 1782 | } |
| 1783 | |
| 1784 | /** |
| 1785 | * Returns a map of the names/values of the runtime statistics |
Hiroshi Yamauchi | d800167 | 2015-04-14 16:07:26 -0700 | [diff] [blame] | 1786 | * that {@link #getRuntimeStat(String)} supports. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1787 | * |
| 1788 | * @return a map of the names/values of the supported runtime statistics. |
Hiroshi Yamauchi | 8b5a293d | 2015-04-02 12:26:10 -0700 | [diff] [blame] | 1789 | */ |
| 1790 | public static Map<String, String> getRuntimeStats() { |
| 1791 | return VMDebug.getRuntimeStats(); |
| 1792 | } |
| 1793 | |
| 1794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | * Returns the size of the native heap. |
| 1796 | * @return The size of the native heap in bytes. |
| 1797 | */ |
| 1798 | public static native long getNativeHeapSize(); |
| 1799 | |
| 1800 | /** |
| 1801 | * Returns the amount of allocated memory in the native heap. |
| 1802 | * @return The allocated size in bytes. |
| 1803 | */ |
| 1804 | public static native long getNativeHeapAllocatedSize(); |
| 1805 | |
| 1806 | /** |
| 1807 | * Returns the amount of free memory in the native heap. |
| 1808 | * @return The freed size in bytes. |
| 1809 | */ |
| 1810 | public static native long getNativeHeapFreeSize(); |
| 1811 | |
| 1812 | /** |
| 1813 | * Retrieves information about this processes memory usages. This information is broken down by |
Dianne Hackborn | b02ce29 | 2015-10-12 15:14:16 -0700 | [diff] [blame] | 1814 | * how much is in use by dalvik, the native heap, and everything else. |
| 1815 | * |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1816 | * <p><b>Note:</b> this method directly retrieves memory information for the given process |
Dianne Hackborn | b02ce29 | 2015-10-12 15:14:16 -0700 | [diff] [blame] | 1817 | * from low-level data available to it. It may not be able to retrieve information about |
| 1818 | * some protected allocations, such as graphics. If you want to be sure you can see |
Kweku Adams | 983829f | 2017-12-06 14:53:50 -0800 | [diff] [blame] | 1819 | * all information about allocations by the process, use |
| 1820 | * {@link android.app.ActivityManager#getProcessMemoryInfo(int[])} instead.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | */ |
| 1822 | public static native void getMemoryInfo(MemoryInfo memoryInfo); |
| 1823 | |
| 1824 | /** |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1825 | * Note: currently only works when the requested pid has the same UID |
| 1826 | * as the caller. |
| 1827 | * @hide |
| 1828 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1829 | @UnsupportedAppUsage |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1830 | public static native void getMemoryInfo(int pid, MemoryInfo memoryInfo); |
| 1831 | |
| 1832 | /** |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1833 | * Retrieves the PSS memory used by the process as given by the |
| 1834 | * smaps. |
| 1835 | */ |
| 1836 | public static native long getPss(); |
| 1837 | |
| 1838 | /** |
Rafal Slawik | 4d07896 | 2018-08-20 18:23:49 +0100 | [diff] [blame] | 1839 | * Retrieves the PSS memory used by the process as given by the smaps. Optionally supply a long |
| 1840 | * array of up to 3 entries to also receive (up to 3 values in order): the Uss and SwapPss and |
| 1841 | * Rss (only filled in as of {@link android.os.Build.VERSION_CODES#P}) of the process, and |
| 1842 | * another array to also retrieve the separate memtrack size. |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 1843 | * @hide |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1844 | */ |
Rafal Slawik | 4d07896 | 2018-08-20 18:23:49 +0100 | [diff] [blame] | 1845 | public static native long getPss(int pid, long[] outUssSwapPssRss, long[] outMemtrack); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1846 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1847 | /** @hide */ |
| 1848 | public static final int MEMINFO_TOTAL = 0; |
| 1849 | /** @hide */ |
| 1850 | public static final int MEMINFO_FREE = 1; |
| 1851 | /** @hide */ |
| 1852 | public static final int MEMINFO_BUFFERS = 2; |
| 1853 | /** @hide */ |
| 1854 | public static final int MEMINFO_CACHED = 3; |
| 1855 | /** @hide */ |
| 1856 | public static final int MEMINFO_SHMEM = 4; |
| 1857 | /** @hide */ |
| 1858 | public static final int MEMINFO_SLAB = 5; |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1859 | /** @hide */ |
| 1860 | public static final int MEMINFO_SLAB_RECLAIMABLE = 6; |
| 1861 | /** @hide */ |
| 1862 | public static final int MEMINFO_SLAB_UNRECLAIMABLE = 7; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1863 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1864 | public static final int MEMINFO_SWAP_TOTAL = 8; |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 1865 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1866 | public static final int MEMINFO_SWAP_FREE = 9; |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 1867 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1868 | public static final int MEMINFO_ZRAM_TOTAL = 10; |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 1869 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1870 | public static final int MEMINFO_MAPPED = 11; |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 1871 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1872 | public static final int MEMINFO_VM_ALLOC_USED = 12; |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 1873 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1874 | public static final int MEMINFO_PAGE_TABLES = 13; |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 1875 | /** @hide */ |
Robert Benea | 5e09980 | 2017-10-04 18:28:01 -0700 | [diff] [blame] | 1876 | public static final int MEMINFO_KERNEL_STACK = 14; |
Suren Baghdasaryan | 5f8e17b | 2019-11-17 14:25:50 -0800 | [diff] [blame] | 1877 | /** |
| 1878 | * Note: MEMINFO_KRECLAIMABLE includes MEMINFO_SLAB_RECLAIMABLE (see KReclaimable field |
| 1879 | * description in kernel documentation). |
| 1880 | * @hide |
| 1881 | */ |
| 1882 | public static final int MEMINFO_KRECLAIMABLE = 15; |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 1883 | /** @hide */ |
Suren Baghdasaryan | 5f8e17b | 2019-11-17 14:25:50 -0800 | [diff] [blame] | 1884 | public static final int MEMINFO_COUNT = 16; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1885 | |
| 1886 | /** |
| 1887 | * Retrieves /proc/meminfo. outSizes is filled with fields |
| 1888 | * as defined by MEMINFO_* offsets. |
| 1889 | * @hide |
| 1890 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1891 | @UnsupportedAppUsage |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1892 | public static native void getMemInfo(long[] outSizes); |
| 1893 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1894 | /** |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1895 | * Establish an object allocation limit in the current thread. |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1896 | * This feature was never enabled in release builds. The |
| 1897 | * allocation limits feature was removed in Honeycomb. This |
| 1898 | * method exists for compatibility and always returns -1 and has |
| 1899 | * no effect. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | * |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1901 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | */ |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1903 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | public static int setAllocationLimit(int limit) { |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1905 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | /** |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1909 | * Establish a global object allocation limit. This feature was |
Carl Shapiro | 7e94284 | 2011-01-12 17:17:45 -0800 | [diff] [blame] | 1910 | * never enabled in release builds. The allocation limits feature |
| 1911 | * was removed in Honeycomb. This method exists for compatibility |
| 1912 | * and always returns -1 and has no effect. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | * |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1914 | * @deprecated This method is now obsolete. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | */ |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1916 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | public static int setGlobalAllocationLimit(int limit) { |
Carl Shapiro | 1107383 | 2011-01-12 16:28:57 -0800 | [diff] [blame] | 1918 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /** |
| 1922 | * Dump a list of all currently loaded class to the log file. |
| 1923 | * |
| 1924 | * @param flags See constants above. |
| 1925 | */ |
| 1926 | public static void printLoadedClasses(int flags) { |
| 1927 | VMDebug.printLoadedClasses(flags); |
| 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * Get the number of loaded classes. |
| 1932 | * @return the number of loaded classes. |
| 1933 | */ |
| 1934 | public static int getLoadedClassCount() { |
| 1935 | return VMDebug.getLoadedClassCount(); |
| 1936 | } |
| 1937 | |
| 1938 | /** |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1939 | * Dump "hprof" data to the specified file. This may cause a GC. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | * |
| 1941 | * @param fileName Full pathname of output file (e.g. "/sdcard/dump.hprof"). |
| 1942 | * @throws UnsupportedOperationException if the VM was built without |
| 1943 | * HPROF support. |
| 1944 | * @throws IOException if an error occurs while opening or writing files. |
| 1945 | */ |
| 1946 | public static void dumpHprofData(String fileName) throws IOException { |
| 1947 | VMDebug.dumpHprofData(fileName); |
| 1948 | } |
| 1949 | |
| 1950 | /** |
Andy McFadden | 824c510 | 2010-07-09 16:26:57 -0700 | [diff] [blame] | 1951 | * Like dumpHprofData(String), but takes an already-opened |
| 1952 | * FileDescriptor to which the trace is written. The file name is also |
| 1953 | * supplied simply for logging. Makes a dup of the file descriptor. |
| 1954 | * |
| 1955 | * Primarily for use by the "am" shell command. |
| 1956 | * |
| 1957 | * @hide |
| 1958 | */ |
| 1959 | public static void dumpHprofData(String fileName, FileDescriptor fd) |
| 1960 | throws IOException { |
| 1961 | VMDebug.dumpHprofData(fileName, fd); |
| 1962 | } |
| 1963 | |
| 1964 | /** |
| 1965 | * Collect "hprof" and send it to DDMS. This may cause a GC. |
Andy McFadden | 07a9661 | 2010-01-28 16:54:37 -0800 | [diff] [blame] | 1966 | * |
| 1967 | * @throws UnsupportedOperationException if the VM was built without |
| 1968 | * HPROF support. |
Andy McFadden | 07a9661 | 2010-01-28 16:54:37 -0800 | [diff] [blame] | 1969 | * @hide |
| 1970 | */ |
| 1971 | public static void dumpHprofDataDdms() { |
| 1972 | VMDebug.dumpHprofDataDdms(); |
| 1973 | } |
| 1974 | |
| 1975 | /** |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1976 | * Writes native heap data to the specified file descriptor. |
| 1977 | * |
| 1978 | * @hide |
| 1979 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1980 | @UnsupportedAppUsage |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1981 | public static native void dumpNativeHeap(FileDescriptor fd); |
| 1982 | |
| 1983 | /** |
Christopher Ferris | 8d652f8 | 2017-04-11 16:29:18 -0700 | [diff] [blame] | 1984 | * Writes malloc info data to the specified file descriptor. |
| 1985 | * |
| 1986 | * @hide |
| 1987 | */ |
| 1988 | public static native void dumpNativeMallocInfo(FileDescriptor fd); |
| 1989 | |
| 1990 | /** |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1991 | * Returns a count of the extant instances of a class. |
| 1992 | * |
| 1993 | * @hide |
| 1994 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 1995 | @UnsupportedAppUsage |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1996 | public static long countInstancesOfClass(Class cls) { |
Brian Carlstrom | 7495cfa | 2010-11-30 18:06:00 -0800 | [diff] [blame] | 1997 | return VMDebug.countInstancesOfClass(cls, true); |
Brian Carlstrom | c21550a | 2010-10-05 21:34:06 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | * Returns the number of sent transactions from this process. |
| 2002 | * @return The number of sent transactions or -1 if it could not read t. |
| 2003 | */ |
| 2004 | public static native int getBinderSentTransactions(); |
| 2005 | |
| 2006 | /** |
| 2007 | * Returns the number of received transactions from the binder driver. |
| 2008 | * @return The number of received transactions or -1 if it could not read the stats. |
| 2009 | */ |
| 2010 | public static native int getBinderReceivedTransactions(); |
| 2011 | |
| 2012 | /** |
| 2013 | * Returns the number of active local Binder objects that exist in the |
| 2014 | * current process. |
| 2015 | */ |
| 2016 | public static final native int getBinderLocalObjectCount(); |
| 2017 | |
| 2018 | /** |
| 2019 | * Returns the number of references to remote proxy Binder objects that |
| 2020 | * exist in the current process. |
| 2021 | */ |
| 2022 | public static final native int getBinderProxyObjectCount(); |
| 2023 | |
| 2024 | /** |
| 2025 | * Returns the number of death notification links to Binder objects that |
| 2026 | * exist in the current process. |
| 2027 | */ |
| 2028 | public static final native int getBinderDeathObjectCount(); |
| 2029 | |
| 2030 | /** |
Andy McFadden | 599c918 | 2009-04-08 00:35:56 -0700 | [diff] [blame] | 2031 | * Primes the register map cache. |
| 2032 | * |
| 2033 | * Only works for classes in the bootstrap class loader. Does not |
| 2034 | * cause classes to be loaded if they're not already present. |
| 2035 | * |
| 2036 | * The classAndMethodDesc argument is a concatentation of the VM-internal |
| 2037 | * class descriptor, method name, and method descriptor. Examples: |
| 2038 | * Landroid/os/Looper;.loop:()V |
| 2039 | * Landroid/app/ActivityThread;.main:([Ljava/lang/String;)V |
| 2040 | * |
| 2041 | * @param classAndMethodDesc the method to prepare |
| 2042 | * |
| 2043 | * @hide |
| 2044 | */ |
| 2045 | public static final boolean cacheRegisterMap(String classAndMethodDesc) { |
| 2046 | return VMDebug.cacheRegisterMap(classAndMethodDesc); |
| 2047 | } |
| 2048 | |
| 2049 | /** |
Andy McFadden | bfd6d48 | 2009-10-22 17:25:57 -0700 | [diff] [blame] | 2050 | * Dumps the contents of VM reference tables (e.g. JNI locals and |
| 2051 | * globals) to the log file. |
| 2052 | * |
| 2053 | * @hide |
| 2054 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2055 | @UnsupportedAppUsage |
Andy McFadden | bfd6d48 | 2009-10-22 17:25:57 -0700 | [diff] [blame] | 2056 | public static final void dumpReferenceTables() { |
| 2057 | VMDebug.dumpReferenceTables(); |
| 2058 | } |
| 2059 | |
| 2060 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | * API for gathering and querying instruction counts. |
| 2062 | * |
| 2063 | * Example usage: |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 2064 | * <pre> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | * Debug.InstructionCount icount = new Debug.InstructionCount(); |
| 2066 | * icount.resetAndStart(); |
| 2067 | * [... do lots of stuff ...] |
| 2068 | * if (icount.collect()) { |
| 2069 | * System.out.println("Total instructions executed: " |
| 2070 | * + icount.globalTotal()); |
| 2071 | * System.out.println("Method invocations: " |
| 2072 | * + icount.globalMethodInvocations()); |
| 2073 | * } |
Chet Haase | 2970c49 | 2010-11-09 13:58:04 -0800 | [diff] [blame] | 2074 | * </pre> |
Jeff Hao | 7d0b3d4 | 2014-09-17 15:45:05 -0700 | [diff] [blame] | 2075 | * |
| 2076 | * @deprecated Instruction counting is no longer supported. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | */ |
Jeff Hao | 7d0b3d4 | 2014-09-17 15:45:05 -0700 | [diff] [blame] | 2078 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | public static class InstructionCount { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | public InstructionCount() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * Reset counters and ensure counts are running. Counts may |
| 2085 | * have already been running. |
| 2086 | * |
| 2087 | * @return true if counting was started |
| 2088 | */ |
| 2089 | public boolean resetAndStart() { |
Narayan Kamath | 19541e8 | 2017-05-30 18:04:36 +0100 | [diff] [blame] | 2090 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * Collect instruction counts. May or may not stop the |
| 2095 | * counting process. |
| 2096 | */ |
| 2097 | public boolean collect() { |
Narayan Kamath | 19541e8 | 2017-05-30 18:04:36 +0100 | [diff] [blame] | 2098 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * Return the total number of instructions executed globally (i.e. in |
| 2103 | * all threads). |
| 2104 | */ |
| 2105 | public int globalTotal() { |
Narayan Kamath | 19541e8 | 2017-05-30 18:04:36 +0100 | [diff] [blame] | 2106 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Return the total number of method-invocation instructions |
| 2111 | * executed globally. |
| 2112 | */ |
| 2113 | public int globalMethodInvocations() { |
Narayan Kamath | 19541e8 | 2017-05-30 18:04:36 +0100 | [diff] [blame] | 2114 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2118 | /** |
| 2119 | * A Map of typed debug properties. |
| 2120 | */ |
| 2121 | private static final TypedProperties debugProperties; |
| 2122 | |
| 2123 | /* |
| 2124 | * Load the debug properties from the standard files into debugProperties. |
| 2125 | */ |
| 2126 | static { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2127 | if (false) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2128 | final String TAG = "DebugProperties"; |
| 2129 | final String[] files = { "/system/debug.prop", "/debug.prop", "/data/debug.prop" }; |
| 2130 | final TypedProperties tp = new TypedProperties(); |
| 2131 | |
| 2132 | // Read the properties from each of the files, if present. |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2133 | for (String file : files) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2134 | Reader r; |
| 2135 | try { |
| 2136 | r = new FileReader(file); |
| 2137 | } catch (FileNotFoundException ex) { |
| 2138 | // It's ok if a file is missing. |
| 2139 | continue; |
| 2140 | } |
| 2141 | |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2142 | try { |
| 2143 | tp.load(r); |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2144 | } catch (Exception ex) { |
| 2145 | throw new RuntimeException("Problem loading " + file, ex); |
| 2146 | } finally { |
| 2147 | try { |
| 2148 | r.close(); |
| 2149 | } catch (IOException ex) { |
| 2150 | // Ignore this error. |
| 2151 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | debugProperties = tp.isEmpty() ? null : tp; |
| 2156 | } else { |
| 2157 | debugProperties = null; |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | |
| 2162 | /** |
| 2163 | * Returns true if the type of the field matches the specified class. |
| 2164 | * Handles the case where the class is, e.g., java.lang.Boolean, but |
| 2165 | * the field is of the primitive "boolean" type. Also handles all of |
| 2166 | * the java.lang.Number subclasses. |
| 2167 | */ |
| 2168 | private static boolean fieldTypeMatches(Field field, Class<?> cl) { |
| 2169 | Class<?> fieldClass = field.getType(); |
| 2170 | if (fieldClass == cl) { |
| 2171 | return true; |
| 2172 | } |
| 2173 | Field primitiveTypeField; |
| 2174 | try { |
| 2175 | /* All of the classes we care about (Boolean, Integer, etc.) |
| 2176 | * have a Class field called "TYPE" that points to the corresponding |
| 2177 | * primitive class. |
| 2178 | */ |
| 2179 | primitiveTypeField = cl.getField("TYPE"); |
| 2180 | } catch (NoSuchFieldException ex) { |
| 2181 | return false; |
| 2182 | } |
| 2183 | try { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2184 | return fieldClass == (Class<?>) primitiveTypeField.get(null); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2185 | } catch (IllegalAccessException ex) { |
| 2186 | return false; |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | |
| 2191 | /** |
| 2192 | * Looks up the property that corresponds to the field, and sets the field's value |
| 2193 | * if the types match. |
| 2194 | */ |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2195 | private static void modifyFieldIfSet(final Field field, final TypedProperties properties, |
| 2196 | final String propertyName) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2197 | if (field.getType() == java.lang.String.class) { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2198 | int stringInfo = properties.getStringInfo(propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2199 | switch (stringInfo) { |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2200 | case TypedProperties.STRING_SET: |
| 2201 | // Handle as usual below. |
| 2202 | break; |
| 2203 | case TypedProperties.STRING_NULL: |
| 2204 | try { |
| 2205 | field.set(null, null); // null object for static fields; null string |
| 2206 | } catch (IllegalAccessException ex) { |
| 2207 | throw new IllegalArgumentException( |
| 2208 | "Cannot set field for " + propertyName, ex); |
| 2209 | } |
| 2210 | return; |
| 2211 | case TypedProperties.STRING_NOT_SET: |
| 2212 | return; |
| 2213 | case TypedProperties.STRING_TYPE_MISMATCH: |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2214 | throw new IllegalArgumentException( |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2215 | "Type of " + propertyName + " " + |
| 2216 | " does not match field type (" + field.getType() + ")"); |
| 2217 | default: |
| 2218 | throw new IllegalStateException( |
| 2219 | "Unexpected getStringInfo(" + propertyName + ") return value " + |
| 2220 | stringInfo); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2221 | } |
| 2222 | } |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2223 | Object value = properties.get(propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2224 | if (value != null) { |
| 2225 | if (!fieldTypeMatches(field, value.getClass())) { |
| 2226 | throw new IllegalArgumentException( |
| 2227 | "Type of " + propertyName + " (" + value.getClass() + ") " + |
| 2228 | " does not match field type (" + field.getType() + ")"); |
| 2229 | } |
| 2230 | try { |
| 2231 | field.set(null, value); // null object for static fields |
| 2232 | } catch (IllegalAccessException ex) { |
| 2233 | throw new IllegalArgumentException( |
| 2234 | "Cannot set field for " + propertyName, ex); |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | |
| 2240 | /** |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2241 | * Equivalent to <code>setFieldsOn(cl, false)</code>. |
| 2242 | * |
| 2243 | * @see #setFieldsOn(Class, boolean) |
Romain Guy | d4103d0 | 2009-05-14 12:24:21 -0700 | [diff] [blame] | 2244 | * |
| 2245 | * @hide |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2246 | */ |
| 2247 | public static void setFieldsOn(Class<?> cl) { |
| 2248 | setFieldsOn(cl, false); |
| 2249 | } |
| 2250 | |
| 2251 | /** |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2252 | * Reflectively sets static fields of a class based on internal debugging |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2253 | * properties. This method is a no-op if false is |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2254 | * false. |
| 2255 | * <p> |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2256 | * <strong>NOTE TO APPLICATION DEVELOPERS</strong>: false will |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2257 | * always be false in release builds. This API is typically only useful |
| 2258 | * for platform developers. |
| 2259 | * </p> |
| 2260 | * Class setup: define a class whose only fields are non-final, static |
| 2261 | * primitive types (except for "char") or Strings. In a static block |
| 2262 | * after the field definitions/initializations, pass the class to |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2263 | * this method, Debug.setFieldsOn(). Example: |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2264 | * <pre> |
| 2265 | * package com.example; |
| 2266 | * |
| 2267 | * import android.os.Debug; |
| 2268 | * |
| 2269 | * public class MyDebugVars { |
| 2270 | * public static String s = "a string"; |
| 2271 | * public static String s2 = "second string"; |
| 2272 | * public static String ns = null; |
| 2273 | * public static boolean b = false; |
| 2274 | * public static int i = 5; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2275 | * @Debug.DebugProperty |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2276 | * public static float f = 0.1f; |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2277 | * @@Debug.DebugProperty |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2278 | * public static double d = 0.5d; |
| 2279 | * |
| 2280 | * // This MUST appear AFTER all fields are defined and initialized! |
| 2281 | * static { |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2282 | * // Sets all the fields |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2283 | * Debug.setFieldsOn(MyDebugVars.class); |
Christian Mehlmauer | 798e2d3 | 2010-06-17 18:24:07 +0200 | [diff] [blame] | 2284 | * |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2285 | * // Sets only the fields annotated with @Debug.DebugProperty |
| 2286 | * // Debug.setFieldsOn(MyDebugVars.class, true); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2287 | * } |
| 2288 | * } |
| 2289 | * </pre> |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2290 | * setFieldsOn() may override the value of any field in the class based |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2291 | * on internal properties that are fixed at boot time. |
| 2292 | * <p> |
| 2293 | * These properties are only set during platform debugging, and are not |
| 2294 | * meant to be used as a general-purpose properties store. |
| 2295 | * |
| 2296 | * {@hide} |
| 2297 | * |
| 2298 | * @param cl The class to (possibly) modify |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2299 | * @param partial If false, sets all static fields, otherwise, only set |
| 2300 | * fields with the {@link android.os.Debug.DebugProperty} |
| 2301 | * annotation |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2302 | * @throws IllegalArgumentException if any fields are final or non-static, |
| 2303 | * or if the type of the field does not match the type of |
| 2304 | * the internal debugging property value. |
| 2305 | */ |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2306 | public static void setFieldsOn(Class<?> cl, boolean partial) { |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 2307 | if (false) { |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2308 | if (debugProperties != null) { |
| 2309 | /* Only look for fields declared directly by the class, |
| 2310 | * so we don't mysteriously change static fields in superclasses. |
| 2311 | */ |
| 2312 | for (Field field : cl.getDeclaredFields()) { |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2313 | if (!partial || field.getAnnotation(DebugProperty.class) != null) { |
| 2314 | final String propertyName = cl.getName() + "." + field.getName(); |
| 2315 | boolean isStatic = Modifier.isStatic(field.getModifiers()); |
| 2316 | boolean isFinal = Modifier.isFinal(field.getModifiers()); |
| 2317 | |
| 2318 | if (!isStatic || isFinal) { |
| 2319 | throw new IllegalArgumentException(propertyName + |
| 2320 | " must be static and non-final"); |
| 2321 | } |
| 2322 | modifyFieldIfSet(field, debugProperties, propertyName); |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2323 | } |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2324 | } |
| 2325 | } |
| 2326 | } else { |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 2327 | Log.wtf(TAG, |
Dave Bort | e9bfd9b | 2009-05-04 14:35:23 -0700 | [diff] [blame] | 2328 | "setFieldsOn(" + (cl == null ? "null" : cl.getName()) + |
Dave Bort | 1ce5bd3 | 2009-04-22 17:36:56 -0700 | [diff] [blame] | 2329 | ") called in non-DEBUG build"); |
| 2330 | } |
| 2331 | } |
Romain Guy | c4b11a7 | 2009-05-13 15:46:37 -0700 | [diff] [blame] | 2332 | |
| 2333 | /** |
| 2334 | * Annotation to put on fields you want to set with |
| 2335 | * {@link Debug#setFieldsOn(Class, boolean)}. |
| 2336 | * |
| 2337 | * @hide |
| 2338 | */ |
| 2339 | @Target({ ElementType.FIELD }) |
| 2340 | @Retention(RetentionPolicy.RUNTIME) |
| 2341 | public @interface DebugProperty { |
| 2342 | } |
Dan Egnor | 3eda979 | 2010-03-05 13:28:36 -0800 | [diff] [blame] | 2343 | |
| 2344 | /** |
| 2345 | * Get a debugging dump of a system service by name. |
| 2346 | * |
| 2347 | * <p>Most services require the caller to hold android.permission.DUMP. |
| 2348 | * |
| 2349 | * @param name of the service to dump |
| 2350 | * @param fd to write dump output to (usually an output log file) |
| 2351 | * @param args to pass to the service's dump method, may be null |
| 2352 | * @return true if the service was dumped successfully, false if |
| 2353 | * the service could not be found or had an error while dumping |
| 2354 | */ |
| 2355 | public static boolean dumpService(String name, FileDescriptor fd, String[] args) { |
| 2356 | IBinder service = ServiceManager.getService(name); |
| 2357 | if (service == null) { |
| 2358 | Log.e(TAG, "Can't find service to dump: " + name); |
| 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | try { |
| 2363 | service.dump(fd, args); |
| 2364 | return true; |
| 2365 | } catch (RemoteException e) { |
| 2366 | Log.e(TAG, "Can't dump service: " + name, e); |
| 2367 | return false; |
| 2368 | } |
| 2369 | } |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2370 | |
| 2371 | /** |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 2372 | * Append the Java stack traces of a given native process to a specified file. |
| 2373 | * |
songjinshi | e02e3ea | 2016-12-16 17:48:21 +0800 | [diff] [blame] | 2374 | * @param pid pid to dump. |
| 2375 | * @param file path of file to append dump to. |
| 2376 | * @param timeoutSecs time to wait in seconds, or 0 to wait forever. |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 2377 | * @hide |
| 2378 | */ |
Narayan Kamath | f013daa | 2017-05-09 12:55:02 +0100 | [diff] [blame] | 2379 | public static native boolean dumpJavaBacktraceToFileTimeout(int pid, String file, |
| 2380 | int timeoutSecs); |
| 2381 | |
| 2382 | /** |
| 2383 | * Append the native stack traces of a given process to a specified file. |
| 2384 | * |
| 2385 | * @param pid pid to dump. |
| 2386 | * @param file path of file to append dump to. |
| 2387 | * @param timeoutSecs time to wait in seconds, or 0 to wait forever. |
| 2388 | * @hide |
| 2389 | */ |
| 2390 | public static native boolean dumpNativeBacktraceToFileTimeout(int pid, String file, |
| 2391 | int timeoutSecs); |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 2392 | |
| 2393 | /** |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 2394 | * Get description of unreachable native memory. |
| 2395 | * @param limit the number of leaks to provide info on, 0 to only get a summary. |
| 2396 | * @param contents true to include a hex dump of the contents of unreachable memory. |
| 2397 | * @return the String containing a description of unreachable memory. |
| 2398 | * @hide */ |
| 2399 | public static native String getUnreachableMemory(int limit, boolean contents); |
| 2400 | |
| 2401 | /** |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2402 | * Return a String describing the calling method and location at a particular stack depth. |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 2403 | * @param callStack the Thread stack |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2404 | * @param depth the depth of stack to return information for. |
| 2405 | * @return the String describing the caller at that depth. |
| 2406 | */ |
| 2407 | private static String getCaller(StackTraceElement callStack[], int depth) { |
| 2408 | // callStack[4] is the caller of the method that called getCallers() |
| 2409 | if (4 + depth >= callStack.length) { |
| 2410 | return "<bottom of call stack>"; |
| 2411 | } |
| 2412 | StackTraceElement caller = callStack[4 + depth]; |
| 2413 | return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber(); |
| 2414 | } |
| 2415 | |
| 2416 | /** |
| 2417 | * Return a string consisting of methods and locations at multiple call stack levels. |
| 2418 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2419 | * @return a string describing the call stack. |
| 2420 | * {@hide} |
| 2421 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2422 | @UnsupportedAppUsage |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2423 | public static String getCallers(final int depth) { |
| 2424 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2425 | StringBuffer sb = new StringBuffer(); |
| 2426 | for (int i = 0; i < depth; i++) { |
| 2427 | sb.append(getCaller(callStack, i)).append(" "); |
| 2428 | } |
| 2429 | return sb.toString(); |
| 2430 | } |
| 2431 | |
| 2432 | /** |
Dianne Hackborn | fd6c7b1 | 2013-10-03 10:42:26 -0700 | [diff] [blame] | 2433 | * Return a string consisting of methods and locations at multiple call stack levels. |
| 2434 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2435 | * @return a string describing the call stack. |
| 2436 | * {@hide} |
| 2437 | */ |
| 2438 | public static String getCallers(final int start, int depth) { |
| 2439 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2440 | StringBuffer sb = new StringBuffer(); |
| 2441 | depth += start; |
| 2442 | for (int i = start; i < depth; i++) { |
| 2443 | sb.append(getCaller(callStack, i)).append(" "); |
| 2444 | } |
| 2445 | return sb.toString(); |
| 2446 | } |
| 2447 | |
| 2448 | /** |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 2449 | * Like {@link #getCallers(int)}, but each location is append to the string |
| 2450 | * as a new line with <var>linePrefix</var> in front of it. |
| 2451 | * @param depth the number of levels to return, starting with the immediate caller. |
| 2452 | * @param linePrefix prefix to put in front of each location. |
| 2453 | * @return a string describing the call stack. |
| 2454 | * {@hide} |
| 2455 | */ |
| 2456 | public static String getCallers(final int depth, String linePrefix) { |
| 2457 | final StackTraceElement[] callStack = Thread.currentThread().getStackTrace(); |
| 2458 | StringBuffer sb = new StringBuffer(); |
| 2459 | for (int i = 0; i < depth; i++) { |
| 2460 | sb.append(linePrefix).append(getCaller(callStack, i)).append("\n"); |
| 2461 | } |
| 2462 | return sb.toString(); |
| 2463 | } |
| 2464 | |
| 2465 | /** |
Ian Rogers | fe067a4 | 2013-02-22 19:59:23 -0800 | [diff] [blame] | 2466 | * @return a String describing the immediate caller of the calling method. |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2467 | * {@hide} |
| 2468 | */ |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 2469 | @UnsupportedAppUsage |
Craig Mautner | a51a956 | 2012-04-17 17:05:26 -0700 | [diff] [blame] | 2470 | public static String getCaller() { |
| 2471 | return getCaller(Thread.currentThread().getStackTrace(), 0); |
| 2472 | } |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2473 | |
| 2474 | /** |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2475 | * Attach a library as a jvmti agent to the current runtime, with the given classloader |
| 2476 | * determining the library search path. |
| 2477 | * <p> |
| 2478 | * Note: agents may only be attached to debuggable apps. Otherwise, this function will |
| 2479 | * throw a SecurityException. |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2480 | * |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2481 | * @param library the library containing the agent. |
| 2482 | * @param options the options passed to the agent. |
| 2483 | * @param classLoader the classloader determining the library search path. |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2484 | * |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2485 | * @throws IOException if the agent could not be attached. |
| 2486 | * @throws SecurityException if the app is not debuggable. |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2487 | */ |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2488 | public static void attachJvmtiAgent(@NonNull String library, @Nullable String options, |
| 2489 | @Nullable ClassLoader classLoader) throws IOException { |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2490 | Preconditions.checkNotNull(library); |
| 2491 | Preconditions.checkArgument(!library.contains("=")); |
| 2492 | |
| 2493 | if (options == null) { |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2494 | VMDebug.attachAgent(library, classLoader); |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2495 | } else { |
Andreas Gampe | 571b700 | 2018-01-16 15:11:29 -0800 | [diff] [blame] | 2496 | VMDebug.attachAgent(library + "=" + options, classLoader); |
Philip P. Moltmann | fd8ed85 | 2017-11-01 15:22:02 -0700 | [diff] [blame] | 2497 | } |
| 2498 | } |
Ben Murdoch | fdc5593 | 2019-01-30 10:43:15 +0000 | [diff] [blame] | 2499 | |
| 2500 | /** |
| 2501 | * Return the current free ZRAM usage in kilobytes. |
| 2502 | * |
| 2503 | * @hide |
| 2504 | */ |
| 2505 | public static native long getZramFreeKb(); |
Suren Baghdasaryan | 5911b9ef | 2019-11-25 19:24:46 -0800 | [diff] [blame] | 2506 | |
| 2507 | /** |
| 2508 | * Return memory size in kilobytes allocated for ION heaps. |
| 2509 | * |
| 2510 | * @hide |
| 2511 | */ |
| 2512 | public static native long getIonHeapsSizeKb(); |
| 2513 | |
| 2514 | /** |
| 2515 | * Return memory size in kilobytes allocated for ION pools. |
| 2516 | * |
| 2517 | * @hide |
| 2518 | */ |
| 2519 | public static native long getIonPoolsSizeKb(); |
| 2520 | |
| 2521 | /** |
| 2522 | * Return ION memory mapped by processes in kB. |
| 2523 | * Notes: |
| 2524 | * * Warning: Might impact performance as it reads /proc/<pid>/maps files for each process. |
| 2525 | * |
| 2526 | * @hide |
| 2527 | */ |
| 2528 | public static native long getIonMappedSizeKb(); |
Suren Baghdasaryan | 2018bf0 | 2019-12-18 09:52:42 -0800 | [diff] [blame^] | 2529 | |
| 2530 | /** |
| 2531 | * Return whether virtually-mapped kernel stacks are enabled (CONFIG_VMAP_STACK). |
| 2532 | * Note: caller needs config_gz read sepolicy permission |
| 2533 | * |
| 2534 | * @hide |
| 2535 | */ |
| 2536 | public static native boolean isVmapStack(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | } |