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 | |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 17 | #define LOG_TAG "android.os.Debug" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | #include "JNIHelp.h" |
| 19 | #include "jni.h" |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 20 | #include <utils/String8.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include "utils/misc.h" |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 22 | #include "cutils/debugger.h" |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 23 | #include <memtrack/memtrack.h> |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 24 | #include <memunreachable/memunreachable.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 26 | #include <cutils/log.h> |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 27 | #include <fcntl.h> |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 28 | #include <inttypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <unistd.h> |
| 33 | #include <time.h> |
| 34 | #include <sys/time.h> |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 35 | #include <errno.h> |
| 36 | #include <assert.h> |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 37 | #include <ctype.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | #include <malloc.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 40 | #include <iomanip> |
| 41 | #include <string> |
| 42 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | namespace android |
| 44 | { |
| 45 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 46 | enum { |
| 47 | HEAP_UNKNOWN, |
| 48 | HEAP_DALVIK, |
| 49 | HEAP_NATIVE, |
Dianne Hackborn | 1842930 | 2014-11-03 13:58:11 -0800 | [diff] [blame] | 50 | |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 51 | HEAP_DALVIK_OTHER, |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 52 | HEAP_STACK, |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 53 | HEAP_CURSOR, |
| 54 | HEAP_ASHMEM, |
Dianne Hackborn | 1842930 | 2014-11-03 13:58:11 -0800 | [diff] [blame] | 55 | HEAP_GL_DEV, |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 56 | HEAP_UNKNOWN_DEV, |
| 57 | HEAP_SO, |
| 58 | HEAP_JAR, |
| 59 | HEAP_APK, |
| 60 | HEAP_TTF, |
| 61 | HEAP_DEX, |
Anwar Ghuloum | 8884ef4 | 2013-03-15 12:56:59 -0700 | [diff] [blame] | 62 | HEAP_OAT, |
Anwar Ghuloum | 88887d0 | 2013-03-19 15:30:12 -0700 | [diff] [blame] | 63 | HEAP_ART, |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 64 | HEAP_UNKNOWN_MAP, |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 65 | HEAP_GRAPHICS, |
| 66 | HEAP_GL, |
| 67 | HEAP_OTHER_MEMTRACK, |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 68 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 69 | HEAP_DALVIK_NORMAL, |
| 70 | HEAP_DALVIK_LARGE, |
| 71 | HEAP_DALVIK_LINEARALLOC, |
| 72 | HEAP_DALVIK_ACCOUNTING, |
| 73 | HEAP_DALVIK_CODE_CACHE, |
Mathieu Chartier | 25c5e2b | 2014-12-08 16:20:26 -0800 | [diff] [blame] | 74 | HEAP_DALVIK_ZYGOTE, |
| 75 | HEAP_DALVIK_NON_MOVING, |
| 76 | HEAP_DALVIK_INDIRECT_REFERENCE_TABLE, |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 77 | |
| 78 | _NUM_HEAP, |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 79 | _NUM_EXCLUSIVE_HEAP = HEAP_OTHER_MEMTRACK+1, |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 80 | _NUM_CORE_HEAP = HEAP_NATIVE+1 |
| 81 | }; |
| 82 | |
| 83 | struct stat_fields { |
| 84 | jfieldID pss_field; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 85 | jfieldID pssSwappable_field; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 86 | jfieldID privateDirty_field; |
| 87 | jfieldID sharedDirty_field; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 88 | jfieldID privateClean_field; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 89 | jfieldID sharedClean_field; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 90 | jfieldID swappedOut_field; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 91 | jfieldID swappedOutPss_field; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct stat_field_names { |
| 95 | const char* pss_name; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 96 | const char* pssSwappable_name; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 97 | const char* privateDirty_name; |
| 98 | const char* sharedDirty_name; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 99 | const char* privateClean_name; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 100 | const char* sharedClean_name; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 101 | const char* swappedOut_name; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 102 | const char* swappedOutPss_name; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static stat_fields stat_fields[_NUM_CORE_HEAP]; |
| 106 | |
| 107 | static stat_field_names stat_field_names[_NUM_CORE_HEAP] = { |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 108 | { "otherPss", "otherSwappablePss", "otherPrivateDirty", "otherSharedDirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 109 | "otherPrivateClean", "otherSharedClean", "otherSwappedOut", "otherSwappedOutPss" }, |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 110 | { "dalvikPss", "dalvikSwappablePss", "dalvikPrivateDirty", "dalvikSharedDirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 111 | "dalvikPrivateClean", "dalvikSharedClean", "dalvikSwappedOut", "dalvikSwappedOutPss" }, |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 112 | { "nativePss", "nativeSwappablePss", "nativePrivateDirty", "nativeSharedDirty", |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 113 | "nativePrivateClean", "nativeSharedClean", "nativeSwappedOut", "nativeSwappedOutPss" } |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | jfieldID otherStats_field; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 117 | jfieldID hasSwappedOutPss_field; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 119 | static bool memtrackLoaded; |
| 120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | struct stats_t { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 122 | int pss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 123 | int swappablePss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 124 | int privateDirty; |
| 125 | int sharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 126 | int privateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 127 | int sharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 128 | int swappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 129 | int swappedOutPss; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | #define BINDER_STATS "/proc/binder/stats" |
| 133 | |
| 134 | static jlong android_os_Debug_getNativeHeapSize(JNIEnv *env, jobject clazz) |
| 135 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | struct mallinfo info = mallinfo(); |
| 137 | return (jlong) info.usmblks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static jlong android_os_Debug_getNativeHeapAllocatedSize(JNIEnv *env, jobject clazz) |
| 141 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | struct mallinfo info = mallinfo(); |
| 143 | return (jlong) info.uordblks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static jlong android_os_Debug_getNativeHeapFreeSize(JNIEnv *env, jobject clazz) |
| 147 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | struct mallinfo info = mallinfo(); |
| 149 | return (jlong) info.fordblks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 152 | // Container used to retrieve graphics memory pss |
| 153 | struct graphics_memory_pss |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 154 | { |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 155 | int graphics; |
| 156 | int gl; |
| 157 | int other; |
| 158 | }; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 159 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 160 | /* |
| 161 | * Uses libmemtrack to retrieve graphics memory that the process is using. |
| 162 | * Any graphics memory reported in /proc/pid/smaps is not included here. |
| 163 | */ |
Dianne Hackborn | cb42855 | 2013-09-26 11:07:17 -0700 | [diff] [blame] | 164 | static int read_memtrack_memory(struct memtrack_proc* p, int pid, |
| 165 | struct graphics_memory_pss* graphics_mem) |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 166 | { |
| 167 | int err = memtrack_proc_get(p, pid); |
| 168 | if (err != 0) { |
Dianne Hackborn | cb42855 | 2013-09-26 11:07:17 -0700 | [diff] [blame] | 169 | ALOGW("failed to get memory consumption info: %d", err); |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 170 | return err; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 173 | ssize_t pss = memtrack_proc_graphics_pss(p); |
| 174 | if (pss < 0) { |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 175 | ALOGW("failed to get graphics pss: %zd", pss); |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 176 | return pss; |
| 177 | } |
| 178 | graphics_mem->graphics = pss / 1024; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 179 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 180 | pss = memtrack_proc_gl_pss(p); |
| 181 | if (pss < 0) { |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 182 | ALOGW("failed to get gl pss: %zd", pss); |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 183 | return pss; |
| 184 | } |
| 185 | graphics_mem->gl = pss / 1024; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 186 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 187 | pss = memtrack_proc_other_pss(p); |
| 188 | if (pss < 0) { |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 189 | ALOGW("failed to get other pss: %zd", pss); |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 190 | return pss; |
| 191 | } |
| 192 | graphics_mem->other = pss / 1024; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 193 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 194 | return 0; |
| 195 | } |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 196 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 197 | /* |
| 198 | * Retrieves the graphics memory that is unaccounted for in /proc/pid/smaps. |
| 199 | */ |
| 200 | static int read_memtrack_memory(int pid, struct graphics_memory_pss* graphics_mem) |
| 201 | { |
| 202 | if (!memtrackLoaded) { |
| 203 | return -1; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 206 | struct memtrack_proc* p = memtrack_proc_new(); |
| 207 | if (p == NULL) { |
Dianne Hackborn | cb42855 | 2013-09-26 11:07:17 -0700 | [diff] [blame] | 208 | ALOGW("failed to create memtrack_proc"); |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 209 | return -1; |
| 210 | } |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 211 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 212 | int err = read_memtrack_memory(p, pid, graphics_mem); |
| 213 | memtrack_proc_destroy(p); |
| 214 | return err; |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 217 | static void read_mapinfo(FILE *fp, stats_t* stats, bool* foundSwapPss) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | { |
| 219 | char line[1024]; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 220 | int len, nameLen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | bool skip, done = false; |
| 222 | |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 223 | unsigned pss = 0, swappable_pss = 0; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 224 | float sharing_proportion = 0.0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | unsigned shared_clean = 0, shared_dirty = 0; |
| 226 | unsigned private_clean = 0, private_dirty = 0; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 227 | unsigned swapped_out = 0, swapped_out_pss = 0; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 228 | bool is_swappable = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | unsigned temp; |
| 230 | |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 231 | uint64_t start; |
| 232 | uint64_t end = 0; |
| 233 | uint64_t prevEnd = 0; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 234 | char* name; |
| 235 | int name_pos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 237 | int whichHeap = HEAP_UNKNOWN; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 238 | int subHeap = HEAP_UNKNOWN; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 239 | int prevHeap = HEAP_UNKNOWN; |
| 240 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 241 | *foundSwapPss = false; |
| 242 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 243 | if(fgets(line, sizeof(line), fp) == 0) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | |
| 245 | while (!done) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 246 | prevHeap = whichHeap; |
| 247 | prevEnd = end; |
| 248 | whichHeap = HEAP_UNKNOWN; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 249 | subHeap = HEAP_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | skip = false; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 251 | is_swappable = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | |
| 253 | len = strlen(line); |
| 254 | if (len < 1) return; |
| 255 | line[--len] = 0; |
| 256 | |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 257 | if (sscanf(line, "%" SCNx64 "-%" SCNx64 " %*s %*x %*x:%*x %*d%n", &start, &end, &name_pos) != 2) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 258 | skip = true; |
| 259 | } else { |
| 260 | while (isspace(line[name_pos])) { |
| 261 | name_pos += 1; |
| 262 | } |
| 263 | name = line + name_pos; |
| 264 | nameLen = strlen(name); |
Mathieu Chartier | d47cbea | 2016-03-03 10:59:33 -0800 | [diff] [blame^] | 265 | // Trim the end of the line if it is " (deleted)". |
| 266 | const char* deleted_str = " (deleted)"; |
| 267 | if (nameLen > (int)strlen(deleted_str) && |
| 268 | strcmp(name+nameLen-strlen(deleted_str), deleted_str) == 0) { |
| 269 | nameLen -= strlen(deleted_str); |
| 270 | name[nameLen] = '\0'; |
| 271 | } |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 272 | if ((strstr(name, "[heap]") == name)) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 273 | whichHeap = HEAP_NATIVE; |
Colin Cross | cb4728f | 2013-08-09 13:23:46 -0700 | [diff] [blame] | 274 | } else if (strncmp(name, "[anon:libc_malloc]", 18) == 0) { |
| 275 | whichHeap = HEAP_NATIVE; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 276 | } else if (strncmp(name, "[stack", 6) == 0) { |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 277 | whichHeap = HEAP_STACK; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 278 | } else if (nameLen > 3 && strcmp(name+nameLen-3, ".so") == 0) { |
| 279 | whichHeap = HEAP_SO; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 280 | is_swappable = true; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 281 | } else if (nameLen > 4 && strcmp(name+nameLen-4, ".jar") == 0) { |
| 282 | whichHeap = HEAP_JAR; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 283 | is_swappable = true; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 284 | } else if (nameLen > 4 && strcmp(name+nameLen-4, ".apk") == 0) { |
| 285 | whichHeap = HEAP_APK; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 286 | is_swappable = true; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 287 | } else if (nameLen > 4 && strcmp(name+nameLen-4, ".ttf") == 0) { |
| 288 | whichHeap = HEAP_TTF; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 289 | is_swappable = true; |
Mathieu Chartier | 9308462 | 2015-05-01 11:30:22 -0700 | [diff] [blame] | 290 | } else if ((nameLen > 4 && strstr(name, ".dex") != NULL) || |
Ian Rogers | 9f8589c | 2013-02-22 20:35:06 -0800 | [diff] [blame] | 291 | (nameLen > 5 && strcmp(name+nameLen-5, ".odex") == 0)) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 292 | whichHeap = HEAP_DEX; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 293 | is_swappable = true; |
Anwar Ghuloum | 8884ef4 | 2013-03-15 12:56:59 -0700 | [diff] [blame] | 294 | } else if (nameLen > 4 && strcmp(name+nameLen-4, ".oat") == 0) { |
| 295 | whichHeap = HEAP_OAT; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 296 | is_swappable = true; |
Anwar Ghuloum | 88887d0 | 2013-03-19 15:30:12 -0700 | [diff] [blame] | 297 | } else if (nameLen > 4 && strcmp(name+nameLen-4, ".art") == 0) { |
| 298 | whichHeap = HEAP_ART; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 299 | is_swappable = true; |
Mathieu Chartier | 9308462 | 2015-05-01 11:30:22 -0700 | [diff] [blame] | 300 | } else if (strncmp(name, "/dev/", 5) == 0) { |
| 301 | if (strncmp(name, "/dev/kgsl-3d0", 13) == 0) { |
| 302 | whichHeap = HEAP_GL_DEV; |
| 303 | } else if (strncmp(name, "/dev/ashmem", 11) == 0) { |
| 304 | if (strncmp(name, "/dev/ashmem/dalvik-", 19) == 0) { |
| 305 | whichHeap = HEAP_DALVIK_OTHER; |
| 306 | if (strstr(name, "/dev/ashmem/dalvik-LinearAlloc") == name) { |
| 307 | subHeap = HEAP_DALVIK_LINEARALLOC; |
| 308 | } else if ((strstr(name, "/dev/ashmem/dalvik-alloc space") == name) || |
| 309 | (strstr(name, "/dev/ashmem/dalvik-main space") == name)) { |
| 310 | // This is the regular Dalvik heap. |
| 311 | whichHeap = HEAP_DALVIK; |
| 312 | subHeap = HEAP_DALVIK_NORMAL; |
Mathieu Chartier | 2e2069d | 2015-10-19 13:48:34 -0700 | [diff] [blame] | 313 | } else if (strstr(name, "/dev/ashmem/dalvik-large object space") == name || |
| 314 | strstr(name, "/dev/ashmem/dalvik-free list large object space") |
| 315 | == name) { |
Mathieu Chartier | 9308462 | 2015-05-01 11:30:22 -0700 | [diff] [blame] | 316 | whichHeap = HEAP_DALVIK; |
| 317 | subHeap = HEAP_DALVIK_LARGE; |
| 318 | } else if (strstr(name, "/dev/ashmem/dalvik-non moving space") == name) { |
| 319 | whichHeap = HEAP_DALVIK; |
| 320 | subHeap = HEAP_DALVIK_NON_MOVING; |
| 321 | } else if (strstr(name, "/dev/ashmem/dalvik-zygote space") == name) { |
| 322 | whichHeap = HEAP_DALVIK; |
| 323 | subHeap = HEAP_DALVIK_ZYGOTE; |
| 324 | } else if (strstr(name, "/dev/ashmem/dalvik-indirect ref") == name) { |
| 325 | subHeap = HEAP_DALVIK_INDIRECT_REFERENCE_TABLE; |
| 326 | } else if (strstr(name, "/dev/ashmem/dalvik-jit-code-cache") == name) { |
| 327 | subHeap = HEAP_DALVIK_CODE_CACHE; |
| 328 | } else { |
| 329 | subHeap = HEAP_DALVIK_ACCOUNTING; // Default to accounting. |
| 330 | } |
| 331 | } else if (strncmp(name, "/dev/ashmem/CursorWindow", 24) == 0) { |
| 332 | whichHeap = HEAP_CURSOR; |
| 333 | } else if (strncmp(name, "/dev/ashmem/libc malloc", 23) == 0) { |
| 334 | whichHeap = HEAP_NATIVE; |
| 335 | } else { |
| 336 | whichHeap = HEAP_ASHMEM; |
| 337 | } |
| 338 | } else { |
| 339 | whichHeap = HEAP_UNKNOWN_DEV; |
| 340 | } |
Colin Cross | cb4728f | 2013-08-09 13:23:46 -0700 | [diff] [blame] | 341 | } else if (strncmp(name, "[anon:", 6) == 0) { |
| 342 | whichHeap = HEAP_UNKNOWN; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 343 | } else if (nameLen > 0) { |
| 344 | whichHeap = HEAP_UNKNOWN_MAP; |
| 345 | } else if (start == prevEnd && prevHeap == HEAP_SO) { |
| 346 | // bss section of a shared library. |
| 347 | whichHeap = HEAP_SO; |
| 348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 351 | //ALOGI("native=%d dalvik=%d sqlite=%d: %s\n", isNativeHeap, isDalvikHeap, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | // isSqliteHeap, line); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 353 | |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 354 | shared_clean = 0; |
| 355 | shared_dirty = 0; |
| 356 | private_clean = 0; |
| 357 | private_dirty = 0; |
| 358 | swapped_out = 0; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 359 | swapped_out_pss = 0; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | while (true) { |
| 362 | if (fgets(line, 1024, fp) == 0) { |
| 363 | done = true; |
| 364 | break; |
| 365 | } |
| 366 | |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 367 | if (line[0] == 'S' && sscanf(line, "Size: %d kB", &temp) == 1) { |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 368 | /* size = temp; */ |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 369 | } else if (line[0] == 'R' && sscanf(line, "Rss: %d kB", &temp) == 1) { |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 370 | /* resident = temp; */ |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 371 | } else if (line[0] == 'P' && sscanf(line, "Pss: %d kB", &temp) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | pss = temp; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 373 | } else if (line[0] == 'S' && sscanf(line, "Shared_Clean: %d kB", &temp) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | shared_clean = temp; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 375 | } else if (line[0] == 'S' && sscanf(line, "Shared_Dirty: %d kB", &temp) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | shared_dirty = temp; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 377 | } else if (line[0] == 'P' && sscanf(line, "Private_Clean: %d kB", &temp) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | private_clean = temp; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 379 | } else if (line[0] == 'P' && sscanf(line, "Private_Dirty: %d kB", &temp) == 1) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | private_dirty = temp; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 381 | } else if (line[0] == 'R' && sscanf(line, "Referenced: %d kB", &temp) == 1) { |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 382 | /* referenced = temp; */ |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 383 | } else if (line[0] == 'S' && sscanf(line, "Swap: %d kB", &temp) == 1) { |
| 384 | swapped_out = temp; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 385 | } else if (line[0] == 'S' && sscanf(line, "SwapPss: %d kB", &temp) == 1) { |
| 386 | *foundSwapPss = true; |
| 387 | swapped_out_pss = temp; |
Colin Cross | 0c6bc73 | 2014-06-17 15:18:07 -0700 | [diff] [blame] | 388 | } else if (sscanf(line, "%" SCNx64 "-%" SCNx64 " %*s %*x %*x:%*x %*d", &start, &end) == 2) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | // looks like a new mapping |
Grace Kloba | bd51116 | 2009-07-08 23:32:25 -0700 | [diff] [blame] | 390 | // example: "10000000-10001000 ---p 10000000 00:00 0" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | break; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | if (!skip) { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 396 | if (is_swappable && (pss > 0)) { |
| 397 | sharing_proportion = 0.0; |
| 398 | if ((shared_clean > 0) || (shared_dirty > 0)) { |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 399 | sharing_proportion = (pss - private_clean |
| 400 | - private_dirty)/(shared_clean+shared_dirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 401 | } |
| 402 | swappable_pss = (sharing_proportion*shared_clean) + private_clean; |
| 403 | } else |
| 404 | swappable_pss = 0; |
| 405 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 406 | stats[whichHeap].pss += pss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 407 | stats[whichHeap].swappablePss += swappable_pss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 408 | stats[whichHeap].privateDirty += private_dirty; |
| 409 | stats[whichHeap].sharedDirty += shared_dirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 410 | stats[whichHeap].privateClean += private_clean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 411 | stats[whichHeap].sharedClean += shared_clean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 412 | stats[whichHeap].swappedOut += swapped_out; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 413 | stats[whichHeap].swappedOutPss += swapped_out_pss; |
Dianne Hackborn | 64770d1 | 2013-05-23 17:51:19 -0700 | [diff] [blame] | 414 | if (whichHeap == HEAP_DALVIK || whichHeap == HEAP_DALVIK_OTHER) { |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 415 | stats[subHeap].pss += pss; |
| 416 | stats[subHeap].swappablePss += swappable_pss; |
| 417 | stats[subHeap].privateDirty += private_dirty; |
| 418 | stats[subHeap].sharedDirty += shared_dirty; |
| 419 | stats[subHeap].privateClean += private_clean; |
| 420 | stats[subHeap].sharedClean += shared_clean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 421 | stats[subHeap].swappedOut += swapped_out; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 422 | stats[subHeap].swappedOutPss += swapped_out_pss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 423 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 428 | static void load_maps(int pid, stats_t* stats, bool* foundSwapPss) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | { |
| 430 | char tmp[128]; |
| 431 | FILE *fp; |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | sprintf(tmp, "/proc/%d/smaps", pid); |
| 434 | fp = fopen(tmp, "r"); |
| 435 | if (fp == 0) return; |
| 436 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 437 | read_mapinfo(fp, stats, foundSwapPss); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | fclose(fp); |
| 439 | } |
| 440 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 441 | static void android_os_Debug_getDirtyPagesPid(JNIEnv *env, jobject clazz, |
| 442 | jint pid, jobject object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | { |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 444 | bool foundSwapPss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 445 | stats_t stats[_NUM_HEAP]; |
| 446 | memset(&stats, 0, sizeof(stats)); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 447 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 448 | load_maps(pid, stats, &foundSwapPss); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 450 | struct graphics_memory_pss graphics_mem; |
| 451 | if (read_memtrack_memory(pid, &graphics_mem) == 0) { |
| 452 | stats[HEAP_GRAPHICS].pss = graphics_mem.graphics; |
| 453 | stats[HEAP_GRAPHICS].privateDirty = graphics_mem.graphics; |
| 454 | stats[HEAP_GL].pss = graphics_mem.gl; |
| 455 | stats[HEAP_GL].privateDirty = graphics_mem.gl; |
| 456 | stats[HEAP_OTHER_MEMTRACK].pss = graphics_mem.other; |
| 457 | stats[HEAP_OTHER_MEMTRACK].privateDirty = graphics_mem.other; |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 458 | } |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 459 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 460 | for (int i=_NUM_CORE_HEAP; i<_NUM_EXCLUSIVE_HEAP; i++) { |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 461 | stats[HEAP_UNKNOWN].pss += stats[i].pss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 462 | stats[HEAP_UNKNOWN].swappablePss += stats[i].swappablePss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 463 | stats[HEAP_UNKNOWN].privateDirty += stats[i].privateDirty; |
| 464 | stats[HEAP_UNKNOWN].sharedDirty += stats[i].sharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 465 | stats[HEAP_UNKNOWN].privateClean += stats[i].privateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 466 | stats[HEAP_UNKNOWN].sharedClean += stats[i].sharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 467 | stats[HEAP_UNKNOWN].swappedOut += stats[i].swappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 468 | stats[HEAP_UNKNOWN].swappedOutPss += stats[i].swappedOutPss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | for (int i=0; i<_NUM_CORE_HEAP; i++) { |
| 472 | env->SetIntField(object, stat_fields[i].pss_field, stats[i].pss); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 473 | env->SetIntField(object, stat_fields[i].pssSwappable_field, stats[i].swappablePss); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 474 | env->SetIntField(object, stat_fields[i].privateDirty_field, stats[i].privateDirty); |
| 475 | env->SetIntField(object, stat_fields[i].sharedDirty_field, stats[i].sharedDirty); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 476 | env->SetIntField(object, stat_fields[i].privateClean_field, stats[i].privateClean); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 477 | env->SetIntField(object, stat_fields[i].sharedClean_field, stats[i].sharedClean); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 478 | env->SetIntField(object, stat_fields[i].swappedOut_field, stats[i].swappedOut); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 479 | env->SetIntField(object, stat_fields[i].swappedOutPss_field, stats[i].swappedOutPss); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 480 | } |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 481 | |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 482 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 483 | env->SetBooleanField(object, hasSwappedOutPss_field, foundSwapPss); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 484 | jintArray otherIntArray = (jintArray)env->GetObjectField(object, otherStats_field); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 485 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 486 | jint* otherArray = (jint*)env->GetPrimitiveArrayCritical(otherIntArray, 0); |
| 487 | if (otherArray == NULL) { |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | int j=0; |
| 492 | for (int i=_NUM_CORE_HEAP; i<_NUM_HEAP; i++) { |
| 493 | otherArray[j++] = stats[i].pss; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 494 | otherArray[j++] = stats[i].swappablePss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 495 | otherArray[j++] = stats[i].privateDirty; |
| 496 | otherArray[j++] = stats[i].sharedDirty; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 497 | otherArray[j++] = stats[i].privateClean; |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 498 | otherArray[j++] = stats[i].sharedClean; |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 499 | otherArray[j++] = stats[i].swappedOut; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 500 | otherArray[j++] = stats[i].swappedOutPss; |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | env->ReleasePrimitiveArrayCritical(otherIntArray, otherArray, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 506 | static void android_os_Debug_getDirtyPages(JNIEnv *env, jobject clazz, jobject object) |
| 507 | { |
| 508 | android_os_Debug_getDirtyPagesPid(env, clazz, getpid(), object); |
| 509 | } |
| 510 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 511 | static jlong android_os_Debug_getPssPid(JNIEnv *env, jobject clazz, jint pid, |
| 512 | jlongArray outUssSwapPss, jlongArray outMemtrack) |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 513 | { |
| 514 | char line[1024]; |
| 515 | jlong pss = 0; |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 516 | jlong swapPss = 0; |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 517 | jlong uss = 0; |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 518 | jlong memtrack = 0; |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 519 | |
| 520 | char tmp[128]; |
| 521 | FILE *fp; |
| 522 | |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 523 | struct graphics_memory_pss graphics_mem; |
| 524 | if (read_memtrack_memory(pid, &graphics_mem) == 0) { |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 525 | pss = uss = memtrack = graphics_mem.graphics + graphics_mem.gl + graphics_mem.other; |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 528 | sprintf(tmp, "/proc/%d/smaps", pid); |
| 529 | fp = fopen(tmp, "r"); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 530 | |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 531 | if (fp != 0) { |
| 532 | while (true) { |
| 533 | if (fgets(line, 1024, fp) == NULL) { |
| 534 | break; |
| 535 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 536 | |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 537 | if (line[0] == 'P') { |
| 538 | if (strncmp(line, "Pss:", 4) == 0) { |
| 539 | char* c = line + 4; |
| 540 | while (*c != 0 && (*c < '0' || *c > '9')) { |
| 541 | c++; |
| 542 | } |
| 543 | pss += atoi(c); |
Iliyan Malchev | 45838de | 2014-12-11 14:29:36 -0800 | [diff] [blame] | 544 | } else if (strncmp(line, "Private_Clean:", 14) == 0 |
| 545 | || strncmp(line, "Private_Dirty:", 14) == 0) { |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 546 | char* c = line + 14; |
| 547 | while (*c != 0 && (*c < '0' || *c > '9')) { |
| 548 | c++; |
| 549 | } |
| 550 | uss += atoi(c); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 551 | } |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 552 | } else if (line[0] == 'S' && strncmp(line, "SwapPss:", 8) == 0) { |
| 553 | char* c = line + 8; |
| 554 | jlong lSwapPss; |
| 555 | while (*c != 0 && (*c < '0' || *c > '9')) { |
| 556 | c++; |
| 557 | } |
| 558 | lSwapPss = atoi(c); |
| 559 | swapPss += lSwapPss; |
| 560 | pss += lSwapPss; // Also in swap, those pages would be accounted as Pss without SWAP |
Dianne Hackborn | cfc837f | 2013-06-27 18:32:07 -0700 | [diff] [blame] | 561 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 562 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | 37c9943 | 2013-09-05 19:34:57 -0700 | [diff] [blame] | 564 | fclose(fp); |
| 565 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 566 | |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 567 | if (outUssSwapPss != NULL) { |
| 568 | if (env->GetArrayLength(outUssSwapPss) >= 1) { |
| 569 | jlong* outUssSwapPssArray = env->GetLongArrayElements(outUssSwapPss, 0); |
| 570 | if (outUssSwapPssArray != NULL) { |
| 571 | outUssSwapPssArray[0] = uss; |
| 572 | if (env->GetArrayLength(outUssSwapPss) >= 2) { |
| 573 | outUssSwapPssArray[1] = swapPss; |
| 574 | } |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 575 | } |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 576 | env->ReleaseLongArrayElements(outUssSwapPss, outUssSwapPssArray, 0); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 579 | |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 580 | if (outMemtrack != NULL) { |
| 581 | if (env->GetArrayLength(outMemtrack) >= 1) { |
| 582 | jlong* outMemtrackArray = env->GetLongArrayElements(outMemtrack, 0); |
| 583 | if (outMemtrackArray != NULL) { |
| 584 | outMemtrackArray[0] = memtrack; |
| 585 | } |
| 586 | env->ReleaseLongArrayElements(outMemtrack, outMemtrackArray, 0); |
| 587 | } |
| 588 | } |
| 589 | |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 590 | return pss; |
| 591 | } |
| 592 | |
| 593 | static jlong android_os_Debug_getPss(JNIEnv *env, jobject clazz) |
| 594 | { |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 595 | return android_os_Debug_getPssPid(env, clazz, getpid(), NULL, NULL); |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 598 | static long get_allocated_vmalloc_memory() { |
| 599 | char line[1024]; |
| 600 | long size, vmalloc_allocated_size = 0; |
| 601 | FILE* fp = fopen("/proc/vmallocinfo", "r"); |
| 602 | if (fp == NULL) { |
| 603 | return 0; |
| 604 | } |
| 605 | while (true) { |
| 606 | if (fgets(line, 1024, fp) == NULL) { |
| 607 | break; |
| 608 | } |
| 609 | |
Martijn Coenen | ab3576e | 2015-05-22 09:16:45 +0200 | [diff] [blame] | 610 | if (!strstr(line, "ioremap") && !strstr(line, "map_lowmem")) { |
| 611 | // Ignore ioremap and map_lowmem regions, since they don't actually consume memory |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 612 | if (sscanf(line, "%*x-%*x %ld", &size) == 1) { |
| 613 | vmalloc_allocated_size += size; |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | fclose(fp); |
| 618 | return vmalloc_allocated_size; |
| 619 | } |
| 620 | |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 621 | enum { |
| 622 | MEMINFO_TOTAL, |
| 623 | MEMINFO_FREE, |
| 624 | MEMINFO_BUFFERS, |
| 625 | MEMINFO_CACHED, |
| 626 | MEMINFO_SHMEM, |
| 627 | MEMINFO_SLAB, |
| 628 | MEMINFO_SWAP_TOTAL, |
| 629 | MEMINFO_SWAP_FREE, |
| 630 | MEMINFO_ZRAM_TOTAL, |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 631 | MEMINFO_MAPPED, |
| 632 | MEMINFO_VMALLOC_USED, |
| 633 | MEMINFO_PAGE_TABLES, |
| 634 | MEMINFO_KERNEL_STACK, |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 635 | MEMINFO_COUNT |
| 636 | }; |
| 637 | |
Greg Hackmann | 228fa5f | 2015-12-09 16:36:08 -0800 | [diff] [blame] | 638 | static long long get_zram_mem_used() |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 639 | { |
| 640 | #define ZRAM_SYSFS "/sys/block/zram0/" |
| 641 | FILE *f = fopen(ZRAM_SYSFS "mm_stat", "r"); |
| 642 | if (f) { |
Greg Hackmann | 228fa5f | 2015-12-09 16:36:08 -0800 | [diff] [blame] | 643 | long long mem_used_total = 0; |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 644 | |
Greg Hackmann | 228fa5f | 2015-12-09 16:36:08 -0800 | [diff] [blame] | 645 | int matched = fscanf(f, "%*d %*d %lld %*d %*d %*d %*d", &mem_used_total); |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 646 | if (matched != 1) |
| 647 | ALOGW("failed to parse " ZRAM_SYSFS "mm_stat"); |
| 648 | |
| 649 | fclose(f); |
| 650 | return mem_used_total; |
| 651 | } |
| 652 | |
| 653 | f = fopen(ZRAM_SYSFS "mem_used_total", "r"); |
| 654 | if (f) { |
Greg Hackmann | 228fa5f | 2015-12-09 16:36:08 -0800 | [diff] [blame] | 655 | long long mem_used_total = 0; |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 656 | |
Greg Hackmann | 228fa5f | 2015-12-09 16:36:08 -0800 | [diff] [blame] | 657 | int matched = fscanf(f, "%lld", &mem_used_total); |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 658 | if (matched != 1) |
| 659 | ALOGW("failed to parse " ZRAM_SYSFS "mem_used_total"); |
| 660 | |
| 661 | fclose(f); |
| 662 | return mem_used_total; |
| 663 | } |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 668 | static void android_os_Debug_getMemInfo(JNIEnv *env, jobject clazz, jlongArray out) |
| 669 | { |
| 670 | char buffer[1024]; |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 671 | size_t numFound = 0; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 672 | |
| 673 | if (out == NULL) { |
| 674 | jniThrowNullPointerException(env, "out == null"); |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | int fd = open("/proc/meminfo", O_RDONLY); |
| 679 | |
| 680 | if (fd < 0) { |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 681 | ALOGW("Unable to open /proc/meminfo: %s\n", strerror(errno)); |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 685 | int len = read(fd, buffer, sizeof(buffer)-1); |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 686 | close(fd); |
| 687 | |
| 688 | if (len < 0) { |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 689 | ALOGW("Empty /proc/meminfo"); |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 690 | return; |
| 691 | } |
| 692 | buffer[len] = 0; |
| 693 | |
| 694 | static const char* const tags[] = { |
| 695 | "MemTotal:", |
| 696 | "MemFree:", |
| 697 | "Buffers:", |
| 698 | "Cached:", |
| 699 | "Shmem:", |
| 700 | "Slab:", |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 701 | "SwapTotal:", |
| 702 | "SwapFree:", |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 703 | "ZRam:", |
| 704 | "Mapped:", |
| 705 | "VmallocUsed:", |
| 706 | "PageTables:", |
| 707 | "KernelStack:", |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 708 | NULL |
| 709 | }; |
| 710 | static const int tagsLen[] = { |
| 711 | 9, |
| 712 | 8, |
| 713 | 8, |
| 714 | 7, |
| 715 | 6, |
| 716 | 5, |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 717 | 10, |
| 718 | 9, |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 719 | 5, |
| 720 | 7, |
| 721 | 12, |
| 722 | 11, |
| 723 | 12, |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 724 | 0 |
| 725 | }; |
Dianne Hackborn | b3af4ec | 2014-10-17 15:25:13 -0700 | [diff] [blame] | 726 | long mem[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 727 | |
| 728 | char* p = buffer; |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 729 | while (*p && numFound < (sizeof(tagsLen) / sizeof(tagsLen[0]))) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 730 | int i = 0; |
| 731 | while (tags[i]) { |
| 732 | if (strncmp(p, tags[i], tagsLen[i]) == 0) { |
| 733 | p += tagsLen[i]; |
| 734 | while (*p == ' ') p++; |
| 735 | char* num = p; |
| 736 | while (*p >= '0' && *p <= '9') p++; |
| 737 | if (*p != 0) { |
| 738 | *p = 0; |
| 739 | p++; |
| 740 | } |
| 741 | mem[i] = atoll(num); |
| 742 | numFound++; |
| 743 | break; |
| 744 | } |
| 745 | i++; |
| 746 | } |
| 747 | while (*p && *p != '\n') { |
| 748 | p++; |
| 749 | } |
| 750 | if (*p) p++; |
| 751 | } |
| 752 | |
Greg Hackmann | 187a6ae | 2015-12-09 09:36:12 -0800 | [diff] [blame] | 753 | mem[MEMINFO_ZRAM_TOTAL] = get_zram_mem_used() / 1024; |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 754 | // Recompute Vmalloc Used since the value in meminfo |
| 755 | // doesn't account for I/O remapping which doesn't use RAM. |
| 756 | mem[MEMINFO_VMALLOC_USED] = get_allocated_vmalloc_memory() / 1024; |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 757 | |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 758 | int maxNum = env->GetArrayLength(out); |
Dianne Hackborn | cbd9a52 | 2013-09-24 23:10:14 -0700 | [diff] [blame] | 759 | if (maxNum > MEMINFO_COUNT) { |
| 760 | maxNum = MEMINFO_COUNT; |
| 761 | } |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 762 | jlong* outArray = env->GetLongArrayElements(out, 0); |
| 763 | if (outArray != NULL) { |
Dianne Hackborn | cb42855 | 2013-09-26 11:07:17 -0700 | [diff] [blame] | 764 | for (int i=0; i<maxNum; i++) { |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 765 | outArray[i] = mem[i]; |
| 766 | } |
| 767 | } |
| 768 | env->ReleaseLongArrayElements(out, outArray, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Martijn Coenen | 398e24e | 2015-04-23 21:55:58 +0200 | [diff] [blame] | 771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | static jint read_binder_stat(const char* stat) |
| 773 | { |
| 774 | FILE* fp = fopen(BINDER_STATS, "r"); |
| 775 | if (fp == NULL) { |
| 776 | return -1; |
| 777 | } |
| 778 | |
| 779 | char line[1024]; |
| 780 | |
| 781 | char compare[128]; |
| 782 | int len = snprintf(compare, 128, "proc %d", getpid()); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | // loop until we have the block that represents this process |
| 785 | do { |
| 786 | if (fgets(line, 1024, fp) == 0) { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 787 | fclose(fp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | return -1; |
| 789 | } |
| 790 | } while (strncmp(compare, line, len)); |
| 791 | |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 792 | // now that we have this process, read until we find the stat that we are looking for |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | len = snprintf(compare, 128, " %s: ", stat); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | do { |
| 796 | if (fgets(line, 1024, fp) == 0) { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 797 | fclose(fp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | return -1; |
| 799 | } |
| 800 | } while (strncmp(compare, line, len)); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | // we have the line, now increment the line ptr to the value |
| 803 | char* ptr = line + len; |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 804 | jint result = atoi(ptr); |
| 805 | fclose(fp); |
| 806 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | static jint android_os_Debug_getBinderSentTransactions(JNIEnv *env, jobject clazz) |
| 810 | { |
| 811 | return read_binder_stat("bcTRANSACTION"); |
| 812 | } |
| 813 | |
| 814 | static jint android_os_getBinderReceivedTransactions(JNIEnv *env, jobject clazz) |
| 815 | { |
| 816 | return read_binder_stat("brTRANSACTION"); |
| 817 | } |
| 818 | |
| 819 | // these are implemented in android_util_Binder.cpp |
| 820 | jint android_os_Debug_getLocalObjectCount(JNIEnv* env, jobject clazz); |
| 821 | jint android_os_Debug_getProxyObjectCount(JNIEnv* env, jobject clazz); |
| 822 | jint android_os_Debug_getDeathObjectCount(JNIEnv* env, jobject clazz); |
| 823 | |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 824 | |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 825 | /* pulled out of bionic */ |
| 826 | extern "C" void get_malloc_leak_info(uint8_t** info, size_t* overallSize, |
| 827 | size_t* infoSize, size_t* totalMemory, size_t* backtraceSize); |
| 828 | extern "C" void free_malloc_leak_info(uint8_t* info); |
| 829 | #define SIZE_FLAG_ZYGOTE_CHILD (1<<31) |
| 830 | #define BACKTRACE_SIZE 32 |
| 831 | |
| 832 | /* |
| 833 | * This is a qsort() callback. |
| 834 | * |
| 835 | * See dumpNativeHeap() for comments about the data format and sort order. |
| 836 | */ |
| 837 | static int compareHeapRecords(const void* vrec1, const void* vrec2) |
| 838 | { |
| 839 | const size_t* rec1 = (const size_t*) vrec1; |
| 840 | const size_t* rec2 = (const size_t*) vrec2; |
| 841 | size_t size1 = *rec1; |
| 842 | size_t size2 = *rec2; |
| 843 | |
| 844 | if (size1 < size2) { |
| 845 | return 1; |
| 846 | } else if (size1 > size2) { |
| 847 | return -1; |
| 848 | } |
| 849 | |
| 850 | intptr_t* bt1 = (intptr_t*)(rec1 + 2); |
| 851 | intptr_t* bt2 = (intptr_t*)(rec2 + 2); |
| 852 | for (size_t idx = 0; idx < BACKTRACE_SIZE; idx++) { |
| 853 | intptr_t addr1 = bt1[idx]; |
| 854 | intptr_t addr2 = bt2[idx]; |
| 855 | if (addr1 == addr2) { |
| 856 | if (addr1 == 0) |
| 857 | break; |
| 858 | continue; |
| 859 | } |
| 860 | if (addr1 < addr2) { |
| 861 | return -1; |
| 862 | } else if (addr1 > addr2) { |
| 863 | return 1; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | /* |
| 871 | * The get_malloc_leak_info() call returns an array of structs that |
| 872 | * look like this: |
| 873 | * |
| 874 | * size_t size |
| 875 | * size_t allocations |
| 876 | * intptr_t backtrace[32] |
| 877 | * |
| 878 | * "size" is the size of the allocation, "backtrace" is a fixed-size |
| 879 | * array of function pointers, and "allocations" is the number of |
| 880 | * allocations with the exact same size and backtrace. |
| 881 | * |
| 882 | * The entries are sorted by descending total size (i.e. size*allocations) |
| 883 | * then allocation count. For best results with "diff" we'd like to sort |
| 884 | * primarily by individual size then stack trace. Since the entries are |
| 885 | * fixed-size, and we're allowed (by the current implementation) to mangle |
| 886 | * them, we can do this in place. |
| 887 | */ |
| 888 | static void dumpNativeHeap(FILE* fp) |
| 889 | { |
| 890 | uint8_t* info = NULL; |
| 891 | size_t overallSize, infoSize, totalMemory, backtraceSize; |
| 892 | |
| 893 | get_malloc_leak_info(&info, &overallSize, &infoSize, &totalMemory, |
| 894 | &backtraceSize); |
| 895 | if (info == NULL) { |
| 896 | fprintf(fp, "Native heap dump not available. To enable, run these" |
| 897 | " commands (requires root):\n"); |
| 898 | fprintf(fp, "$ adb shell setprop libc.debug.malloc 1\n"); |
| 899 | fprintf(fp, "$ adb shell stop\n"); |
| 900 | fprintf(fp, "$ adb shell start\n"); |
| 901 | return; |
| 902 | } |
| 903 | assert(infoSize != 0); |
| 904 | assert(overallSize % infoSize == 0); |
| 905 | |
| 906 | fprintf(fp, "Android Native Heap Dump v1.0\n\n"); |
| 907 | |
| 908 | size_t recordCount = overallSize / infoSize; |
| 909 | fprintf(fp, "Total memory: %zu\n", totalMemory); |
| 910 | fprintf(fp, "Allocation records: %zd\n", recordCount); |
| 911 | if (backtraceSize != BACKTRACE_SIZE) { |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 912 | fprintf(fp, "WARNING: mismatched backtrace sizes (%zu vs. %d)\n", |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 913 | backtraceSize, BACKTRACE_SIZE); |
| 914 | } |
| 915 | fprintf(fp, "\n"); |
| 916 | |
| 917 | /* re-sort the entries */ |
| 918 | qsort(info, recordCount, infoSize, compareHeapRecords); |
| 919 | |
| 920 | /* dump the entries to the file */ |
| 921 | const uint8_t* ptr = info; |
| 922 | for (size_t idx = 0; idx < recordCount; idx++) { |
| 923 | size_t size = *(size_t*) ptr; |
| 924 | size_t allocations = *(size_t*) (ptr + sizeof(size_t)); |
| 925 | intptr_t* backtrace = (intptr_t*) (ptr + sizeof(size_t) * 2); |
| 926 | |
| 927 | fprintf(fp, "z %d sz %8zu num %4zu bt", |
| 928 | (size & SIZE_FLAG_ZYGOTE_CHILD) != 0, |
| 929 | size & ~SIZE_FLAG_ZYGOTE_CHILD, |
| 930 | allocations); |
| 931 | for (size_t bt = 0; bt < backtraceSize; bt++) { |
| 932 | if (backtrace[bt] == 0) { |
| 933 | break; |
| 934 | } else { |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 935 | #ifdef __LP64__ |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 936 | fprintf(fp, " %016" PRIxPTR, backtrace[bt]); |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 937 | #else |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 938 | fprintf(fp, " %08" PRIxPTR, backtrace[bt]); |
Ashok Bhat | f5df700 | 2014-03-25 20:51:35 +0000 | [diff] [blame] | 939 | #endif |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | fprintf(fp, "\n"); |
| 943 | |
| 944 | ptr += infoSize; |
| 945 | } |
| 946 | |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 947 | free_malloc_leak_info(info); |
Brian Carlstrom | 393b84c1 | 2010-10-17 23:40:43 -0700 | [diff] [blame] | 948 | |
| 949 | fprintf(fp, "MAPS\n"); |
| 950 | const char* maps = "/proc/self/maps"; |
| 951 | FILE* in = fopen(maps, "r"); |
| 952 | if (in == NULL) { |
| 953 | fprintf(fp, "Could not open %s\n", maps); |
| 954 | return; |
| 955 | } |
| 956 | char buf[BUFSIZ]; |
| 957 | while (size_t n = fread(buf, sizeof(char), BUFSIZ, in)) { |
| 958 | fwrite(buf, sizeof(char), n, fp); |
| 959 | } |
| 960 | fclose(in); |
| 961 | |
| 962 | fprintf(fp, "END\n"); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 963 | } |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 964 | |
| 965 | /* |
| 966 | * Dump the native heap, writing human-readable output to the specified |
| 967 | * file descriptor. |
| 968 | */ |
| 969 | static void android_os_Debug_dumpNativeHeap(JNIEnv* env, jobject clazz, |
| 970 | jobject fileDescriptor) |
| 971 | { |
| 972 | if (fileDescriptor == NULL) { |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 973 | jniThrowNullPointerException(env, "fd == null"); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 974 | return; |
| 975 | } |
| 976 | int origFd = jniGetFDFromFileDescriptor(env, fileDescriptor); |
| 977 | if (origFd < 0) { |
| 978 | jniThrowRuntimeException(env, "Invalid file descriptor"); |
| 979 | return; |
| 980 | } |
| 981 | |
| 982 | /* dup() the descriptor so we don't close the original with fclose() */ |
| 983 | int fd = dup(origFd); |
| 984 | if (fd < 0) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 985 | ALOGW("dup(%d) failed: %s\n", origFd, strerror(errno)); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 986 | jniThrowRuntimeException(env, "dup() failed"); |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | FILE* fp = fdopen(fd, "w"); |
| 991 | if (fp == NULL) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 992 | ALOGW("fdopen(%d) failed: %s\n", fd, strerror(errno)); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 993 | close(fd); |
| 994 | jniThrowRuntimeException(env, "fdopen() failed"); |
| 995 | return; |
| 996 | } |
| 997 | |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 998 | ALOGD("Native heap dump starting...\n"); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 999 | dumpNativeHeap(fp); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 1000 | ALOGD("Native heap dump complete.\n"); |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1001 | |
| 1002 | fclose(fp); |
| 1003 | } |
| 1004 | |
| 1005 | |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1006 | static void android_os_Debug_dumpNativeBacktraceToFile(JNIEnv* env, jobject clazz, |
| 1007 | jint pid, jstring fileName) |
| 1008 | { |
| 1009 | if (fileName == NULL) { |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1010 | jniThrowNullPointerException(env, "file == null"); |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1011 | return; |
| 1012 | } |
| 1013 | const jchar* str = env->GetStringCritical(fileName, 0); |
| 1014 | String8 fileName8; |
| 1015 | if (str) { |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 1016 | fileName8 = String8(reinterpret_cast<const char16_t*>(str), |
| 1017 | env->GetStringLength(fileName)); |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1018 | env->ReleaseStringCritical(fileName, str); |
| 1019 | } |
| 1020 | |
| 1021 | int fd = open(fileName8.string(), O_CREAT | O_WRONLY | O_NOFOLLOW, 0666); /* -rw-rw-rw- */ |
| 1022 | if (fd < 0) { |
| 1023 | fprintf(stderr, "Can't open %s: %s\n", fileName8.string(), strerror(errno)); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | if (lseek(fd, 0, SEEK_END) < 0) { |
| 1028 | fprintf(stderr, "lseek: %s\n", strerror(errno)); |
| 1029 | } else { |
| 1030 | dump_backtrace_to_file(pid, fd); |
| 1031 | } |
| 1032 | |
| 1033 | close(fd); |
| 1034 | } |
| 1035 | |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1036 | static jstring android_os_Debug_getUnreachableMemory(JNIEnv* env, jobject clazz, |
| 1037 | jint limit, jboolean contents) |
| 1038 | { |
| 1039 | std::string s = GetUnreachableMemoryString(contents, limit); |
| 1040 | return env->NewStringUTF(s.c_str()); |
| 1041 | } |
| 1042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | /* |
| 1044 | * JNI registration. |
| 1045 | */ |
| 1046 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1047 | static const JNINativeMethod gMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | { "getNativeHeapSize", "()J", |
| 1049 | (void*) android_os_Debug_getNativeHeapSize }, |
| 1050 | { "getNativeHeapAllocatedSize", "()J", |
| 1051 | (void*) android_os_Debug_getNativeHeapAllocatedSize }, |
| 1052 | { "getNativeHeapFreeSize", "()J", |
| 1053 | (void*) android_os_Debug_getNativeHeapFreeSize }, |
| 1054 | { "getMemoryInfo", "(Landroid/os/Debug$MemoryInfo;)V", |
| 1055 | (void*) android_os_Debug_getDirtyPages }, |
Dianne Hackborn | 3025ef3 | 2009-08-31 21:31:47 -0700 | [diff] [blame] | 1056 | { "getMemoryInfo", "(ILandroid/os/Debug$MemoryInfo;)V", |
| 1057 | (void*) android_os_Debug_getDirtyPagesPid }, |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1058 | { "getPss", "()J", |
| 1059 | (void*) android_os_Debug_getPss }, |
Dianne Hackborn | 1a4b5a4 | 2014-12-08 17:43:31 -0800 | [diff] [blame] | 1060 | { "getPss", "(I[J[J)J", |
Dianne Hackborn | b437e09 | 2011-08-05 17:50:29 -0700 | [diff] [blame] | 1061 | (void*) android_os_Debug_getPssPid }, |
Dianne Hackborn | 8e69257 | 2013-09-10 19:06:15 -0700 | [diff] [blame] | 1062 | { "getMemInfo", "([J)V", |
| 1063 | (void*) android_os_Debug_getMemInfo }, |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1064 | { "dumpNativeHeap", "(Ljava/io/FileDescriptor;)V", |
| 1065 | (void*) android_os_Debug_dumpNativeHeap }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | { "getBinderSentTransactions", "()I", |
| 1067 | (void*) android_os_Debug_getBinderSentTransactions }, |
| 1068 | { "getBinderReceivedTransactions", "()I", |
| 1069 | (void*) android_os_getBinderReceivedTransactions }, |
| 1070 | { "getBinderLocalObjectCount", "()I", |
| 1071 | (void*)android_os_Debug_getLocalObjectCount }, |
| 1072 | { "getBinderProxyObjectCount", "()I", |
| 1073 | (void*)android_os_Debug_getProxyObjectCount }, |
| 1074 | { "getBinderDeathObjectCount", "()I", |
| 1075 | (void*)android_os_Debug_getDeathObjectCount }, |
Dianne Hackborn | f72467a | 2012-06-08 17:23:59 -0700 | [diff] [blame] | 1076 | { "dumpNativeBacktraceToFile", "(ILjava/lang/String;)V", |
| 1077 | (void*)android_os_Debug_dumpNativeBacktraceToFile }, |
Colin Cross | c4fb5f9 | 2016-02-02 16:51:15 -0800 | [diff] [blame] | 1078 | { "getUnreachableMemory", "(IZ)Ljava/lang/String;", |
| 1079 | (void*)android_os_Debug_getUnreachableMemory }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | int register_android_os_Debug(JNIEnv *env) |
| 1083 | { |
Adam Lesinski | 5b4ef81 | 2013-09-23 10:06:09 -0700 | [diff] [blame] | 1084 | int err = memtrack_init(); |
| 1085 | if (err != 0) { |
| 1086 | memtrackLoaded = false; |
| 1087 | ALOGE("failed to load memtrack module: %d", err); |
| 1088 | } else { |
| 1089 | memtrackLoaded = true; |
| 1090 | } |
| 1091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | jclass clazz = env->FindClass("android/os/Debug$MemoryInfo"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1094 | // Sanity check the number of other statistics expected in Java matches here. |
| 1095 | jfieldID numOtherStats_field = env->GetStaticFieldID(clazz, "NUM_OTHER_STATS", "I"); |
| 1096 | jint numOtherStats = env->GetStaticIntField(clazz, numOtherStats_field); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1097 | jfieldID numDvkStats_field = env->GetStaticFieldID(clazz, "NUM_DVK_STATS", "I"); |
| 1098 | jint numDvkStats = env->GetStaticIntField(clazz, numDvkStats_field); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1099 | int expectedNumOtherStats = _NUM_HEAP - _NUM_CORE_HEAP; |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1100 | if ((numOtherStats + numDvkStats) != expectedNumOtherStats) { |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1101 | jniThrowExceptionFmt(env, "java/lang/RuntimeException", |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1102 | "android.os.Debug.Meminfo.NUM_OTHER_STATS+android.os.Debug.Meminfo.NUM_DVK_STATS=%d expected %d", |
| 1103 | numOtherStats+numDvkStats, expectedNumOtherStats); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1104 | return JNI_ERR; |
| 1105 | } |
| 1106 | |
| 1107 | otherStats_field = env->GetFieldID(clazz, "otherStats", "[I"); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 1108 | hasSwappedOutPss_field = env->GetFieldID(clazz, "hasSwappedOutPss", "Z"); |
Ian Rogers | 7c9f30b | 2013-02-27 10:57:13 -0800 | [diff] [blame] | 1109 | |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1110 | for (int i=0; i<_NUM_CORE_HEAP; i++) { |
| 1111 | stat_fields[i].pss_field = |
| 1112 | env->GetFieldID(clazz, stat_field_names[i].pss_name, "I"); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1113 | stat_fields[i].pssSwappable_field = |
| 1114 | env->GetFieldID(clazz, stat_field_names[i].pssSwappable_name, "I"); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1115 | stat_fields[i].privateDirty_field = |
| 1116 | env->GetFieldID(clazz, stat_field_names[i].privateDirty_name, "I"); |
| 1117 | stat_fields[i].sharedDirty_field = |
| 1118 | env->GetFieldID(clazz, stat_field_names[i].sharedDirty_name, "I"); |
Anwar Ghuloum | 3c61506 | 2013-05-13 14:18:02 -0700 | [diff] [blame] | 1119 | stat_fields[i].privateClean_field = |
| 1120 | env->GetFieldID(clazz, stat_field_names[i].privateClean_name, "I"); |
Anwar Ghuloum | 3a8ce1b | 2013-04-26 16:18:28 -0700 | [diff] [blame] | 1121 | stat_fields[i].sharedClean_field = |
| 1122 | env->GetFieldID(clazz, stat_field_names[i].sharedClean_name, "I"); |
Dianne Hackborn | 8883ced | 2013-10-02 16:58:06 -0700 | [diff] [blame] | 1123 | stat_fields[i].swappedOut_field = |
| 1124 | env->GetFieldID(clazz, stat_field_names[i].swappedOut_name, "I"); |
Martijn Coenen | e076485 | 2016-01-07 17:04:22 -0800 | [diff] [blame] | 1125 | stat_fields[i].swappedOutPss_field = |
| 1126 | env->GetFieldID(clazz, stat_field_names[i].swappedOutPss_name, "I"); |
Dianne Hackborn | 0e3328f | 2011-07-17 13:31:17 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | return jniRegisterNativeMethods(env, "android/os/Debug", gMethods, NELEM(gMethods)); |
| 1130 | } |
| 1131 | |
Andy McFadden | 06a6b55 | 2010-07-13 16:28:09 -0700 | [diff] [blame] | 1132 | }; // namespace android |