Loading core/java/android/app/ActivityThread.java +8 −0 Original line number Diff line number Diff line Loading @@ -1701,6 +1701,14 @@ public final class ActivityThread { printRow(pw, TWO_COUNT_COLUMNS, "numPagers:", stats.numPagers, "inactivePageKB:", (stats.totalBytes - stats.referencedBytes) / 1024); printRow(pw, ONE_COUNT_COLUMN, "activePageKB:", stats.referencedBytes / 1024); // Asset details. String assetAlloc = AssetManager.getAssetAllocations(); if (assetAlloc != null) { pw.println(" "); pw.println(" Asset Allocations"); pw.print(assetAlloc); } } private void printRow(PrintWriter pw, String format, Object...objs) { Loading core/java/android/content/res/AssetManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -664,6 +664,11 @@ public final class AssetManager { */ public native static final int getGlobalAssetCount(); /** * {@hide} */ public native static final String getAssetAllocations(); /** * {@hide} */ Loading core/jni/android_util_AssetManager.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -1536,6 +1536,22 @@ static jint android_content_AssetManager_getGlobalAssetCount(JNIEnv* env, jobjec return Asset::getGlobalCount(); } static jobject android_content_AssetManager_getAssetAllocations(JNIEnv* env, jobject clazz) { String8 alloc = Asset::getAssetAllocations(); if (alloc.length() <= 0) { return NULL; } jstring str = env->NewStringUTF(alloc.string()); if (str == NULL) { doThrow(env, "java/lang/OutOfMemoryError"); return NULL; } return str; } static jint android_content_AssetManager_getGlobalAssetManagerCount(JNIEnv* env, jobject clazz) { return AssetManager::getGlobalCount(); Loading Loading @@ -1646,6 +1662,8 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_destroy }, { "getGlobalAssetCount", "()I", (void*) android_content_AssetManager_getGlobalAssetCount }, { "getAssetAllocations", "()Ljava/lang/String;", (void*) android_content_AssetManager_getAssetAllocations }, { "getGlobalAssetManagerCount", "()I", (void*) android_content_AssetManager_getGlobalAssetCount }, }; Loading include/utils/Asset.h +12 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: virtual ~Asset(void); static int32_t getGlobalCount(); static String8 getAssetAllocations(); /* used when opening an asset */ typedef enum AccessMode { Loading Loading @@ -109,6 +110,12 @@ public: */ virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const = 0; /* * Return whether this asset's buffer is allocated in RAM (not mmapped). * Note: not virtual so it is safe to call even when being destroyed. */ virtual bool isAllocated(void) const { return false; } /* * Get a string identifying the asset's source. This might be a full * path, it might be a colon-separated list of identifiers. Loading Loading @@ -197,6 +204,9 @@ private: AccessMode mAccessMode; // how the asset was opened String8 mAssetSource; // debug string Asset* mNext; // linked list. Asset* mPrev; }; Loading Loading @@ -239,6 +249,7 @@ public: virtual off_t getLength(void) const { return mLength; } virtual off_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const; virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // absolute file offset of start of chunk Loading Loading @@ -295,6 +306,7 @@ public: virtual off_t getLength(void) const { return mUncompressedLen; } virtual off_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const { return -1; } virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // offset to start of compressed data Loading libs/utils/Asset.cpp +53 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <utils/ZipUtils.h> #include <utils/ZipFileRO.h> #include <utils/Log.h> #include <utils/threads.h> #include <string.h> #include <memory.h> Loading @@ -40,24 +41,71 @@ using namespace android; # define O_BINARY 0 #endif static volatile int32_t gCount = 0; static Mutex gAssetLock; static int32_t gCount = 0; static Asset* gHead = NULL; static Asset* gTail = NULL; int32_t Asset::getGlobalCount() { AutoMutex _l(gAssetLock); return gCount; } String8 Asset::getAssetAllocations() { AutoMutex _l(gAssetLock); String8 res; Asset* cur = gHead; while (cur != NULL) { if (cur->isAllocated()) { res.append(" "); res.append(cur->getAssetSource()); off_t size = (cur->getLength()+512)/1024; char buf[64]; sprintf(buf, ": %dK\n", (int)size); res.append(buf); } cur = cur->mNext; } return res; } Asset::Asset(void) : mAccessMode(ACCESS_UNKNOWN) { int count = android_atomic_inc(&gCount)+1; //LOGI("Creating Asset %p #%d\n", this, count); AutoMutex _l(gAssetLock); gCount++; mNext = mPrev = NULL; if (gTail == NULL) { gHead = gTail = this; } else { mPrev = gTail; gTail->mNext = this; gTail = this; } //LOGI("Creating Asset %p #%d\n", this, gCount); } Asset::~Asset(void) { int count = android_atomic_dec(&gCount); //LOGI("Destroying Asset in %p #%d\n", this, count); AutoMutex _l(gAssetLock); gCount--; if (gHead == this) { gHead = mNext; } if (gTail == this) { gTail = mPrev; } if (mNext != NULL) { mNext->mPrev = mPrev; } if (mPrev != NULL) { mPrev->mNext = mNext; } mNext = mPrev = NULL; //LOGI("Destroying Asset in %p #%d\n", this, gCount); } /* Loading Loading
core/java/android/app/ActivityThread.java +8 −0 Original line number Diff line number Diff line Loading @@ -1701,6 +1701,14 @@ public final class ActivityThread { printRow(pw, TWO_COUNT_COLUMNS, "numPagers:", stats.numPagers, "inactivePageKB:", (stats.totalBytes - stats.referencedBytes) / 1024); printRow(pw, ONE_COUNT_COLUMN, "activePageKB:", stats.referencedBytes / 1024); // Asset details. String assetAlloc = AssetManager.getAssetAllocations(); if (assetAlloc != null) { pw.println(" "); pw.println(" Asset Allocations"); pw.print(assetAlloc); } } private void printRow(PrintWriter pw, String format, Object...objs) { Loading
core/java/android/content/res/AssetManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -664,6 +664,11 @@ public final class AssetManager { */ public native static final int getGlobalAssetCount(); /** * {@hide} */ public native static final String getAssetAllocations(); /** * {@hide} */ Loading
core/jni/android_util_AssetManager.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -1536,6 +1536,22 @@ static jint android_content_AssetManager_getGlobalAssetCount(JNIEnv* env, jobjec return Asset::getGlobalCount(); } static jobject android_content_AssetManager_getAssetAllocations(JNIEnv* env, jobject clazz) { String8 alloc = Asset::getAssetAllocations(); if (alloc.length() <= 0) { return NULL; } jstring str = env->NewStringUTF(alloc.string()); if (str == NULL) { doThrow(env, "java/lang/OutOfMemoryError"); return NULL; } return str; } static jint android_content_AssetManager_getGlobalAssetManagerCount(JNIEnv* env, jobject clazz) { return AssetManager::getGlobalCount(); Loading Loading @@ -1646,6 +1662,8 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_destroy }, { "getGlobalAssetCount", "()I", (void*) android_content_AssetManager_getGlobalAssetCount }, { "getAssetAllocations", "()Ljava/lang/String;", (void*) android_content_AssetManager_getAssetAllocations }, { "getGlobalAssetManagerCount", "()I", (void*) android_content_AssetManager_getGlobalAssetCount }, }; Loading
include/utils/Asset.h +12 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: virtual ~Asset(void); static int32_t getGlobalCount(); static String8 getAssetAllocations(); /* used when opening an asset */ typedef enum AccessMode { Loading Loading @@ -109,6 +110,12 @@ public: */ virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const = 0; /* * Return whether this asset's buffer is allocated in RAM (not mmapped). * Note: not virtual so it is safe to call even when being destroyed. */ virtual bool isAllocated(void) const { return false; } /* * Get a string identifying the asset's source. This might be a full * path, it might be a colon-separated list of identifiers. Loading Loading @@ -197,6 +204,9 @@ private: AccessMode mAccessMode; // how the asset was opened String8 mAssetSource; // debug string Asset* mNext; // linked list. Asset* mPrev; }; Loading Loading @@ -239,6 +249,7 @@ public: virtual off_t getLength(void) const { return mLength; } virtual off_t getRemainingLength(void) const { return mLength-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const; virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // absolute file offset of start of chunk Loading Loading @@ -295,6 +306,7 @@ public: virtual off_t getLength(void) const { return mUncompressedLen; } virtual off_t getRemainingLength(void) const { return mUncompressedLen-mOffset; } virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const { return -1; } virtual bool isAllocated(void) const { return mBuf != NULL; } private: off_t mStart; // offset to start of compressed data Loading
libs/utils/Asset.cpp +53 −5 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <utils/ZipUtils.h> #include <utils/ZipFileRO.h> #include <utils/Log.h> #include <utils/threads.h> #include <string.h> #include <memory.h> Loading @@ -40,24 +41,71 @@ using namespace android; # define O_BINARY 0 #endif static volatile int32_t gCount = 0; static Mutex gAssetLock; static int32_t gCount = 0; static Asset* gHead = NULL; static Asset* gTail = NULL; int32_t Asset::getGlobalCount() { AutoMutex _l(gAssetLock); return gCount; } String8 Asset::getAssetAllocations() { AutoMutex _l(gAssetLock); String8 res; Asset* cur = gHead; while (cur != NULL) { if (cur->isAllocated()) { res.append(" "); res.append(cur->getAssetSource()); off_t size = (cur->getLength()+512)/1024; char buf[64]; sprintf(buf, ": %dK\n", (int)size); res.append(buf); } cur = cur->mNext; } return res; } Asset::Asset(void) : mAccessMode(ACCESS_UNKNOWN) { int count = android_atomic_inc(&gCount)+1; //LOGI("Creating Asset %p #%d\n", this, count); AutoMutex _l(gAssetLock); gCount++; mNext = mPrev = NULL; if (gTail == NULL) { gHead = gTail = this; } else { mPrev = gTail; gTail->mNext = this; gTail = this; } //LOGI("Creating Asset %p #%d\n", this, gCount); } Asset::~Asset(void) { int count = android_atomic_dec(&gCount); //LOGI("Destroying Asset in %p #%d\n", this, count); AutoMutex _l(gAssetLock); gCount--; if (gHead == this) { gHead = mNext; } if (gTail == this) { gTail = mPrev; } if (mNext != NULL) { mNext->mPrev = mPrev; } if (mPrev != NULL) { mPrev->mNext = mNext; } mNext = mPrev = NULL; //LOGI("Destroying Asset in %p #%d\n", this, gCount); } /* Loading