本文整理汇总了Java中android.os.Debug.getNativeHeapAllocatedSize方法的典型用法代码示例。如果您正苦于以下问题:Java Debug.getNativeHeapAllocatedSize方法的具体用法?Java Debug.getNativeHeapAllocatedSize怎么用?Java Debug.getNativeHeapAllocatedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Debug
的用法示例。
在下文中一共展示了Debug.getNativeHeapAllocatedSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBitmapMemoryUsage
import android.os.Debug; //导入方法依赖的package包/类
public static double getBitmapMemoryUsage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return getMemoryUsage();
}
long max = Runtime.getRuntime().maxMemory();
long used = Debug.getNativeHeapAllocatedSize();
return (double) used / (double) max;
}
示例2: nativePrintMemory
import android.os.Debug; //导入方法依赖的package包/类
/**
* 打印native内存占用情况
*
* @param info 相关信息
*/
public static void nativePrintMemory(String info) {
if ( !DEBUG_MEMORY) {
return;
}
long totalNativeMemory = Debug.getNativeHeapAllocatedSize();
long freeNativeMemory = Debug.getNativeHeapFreeSize();
long nativeMemory = Debug.getNativeHeapSize();
String content =
info + "-->totalNativeMemory:" + (totalNativeMemory >> 10) + ",freeNativeMemory:" + (freeNativeMemory >> 10) + ",nativeMemory:" + (nativeMemory >> 10) + "\n";
Log.d(
content);
}
示例3: showMemoryStats
import android.os.Debug; //导入方法依赖的package包/类
public static void showMemoryStats(String message) {
Log.i("memory", message
+ "----------------------------------------------------------------------------------------");
double nativeUsage = Debug.getNativeHeapAllocatedSize();
Log.i("memory", "nativeUsage: " + (nativeUsage / 1048576d));
// current heap size
double heapSize = Runtime.getRuntime().totalMemory();
// Log.i("memory", "heapSize: " + (heapSize / 1048576d));
// amount available in heap
double heapRemaining = Runtime.getRuntime().freeMemory();
// Log.i("memory", "heapRemaining: " + (heapRemaining / 1048576d));
double memoryAvailable = Runtime.getRuntime().maxMemory() - (heapSize - heapRemaining) - nativeUsage;
Log.i("memory", "memoryAvailable: " + (memoryAvailable / 1048576d));
if (first) {
initavail = memoryAvailable;
first = false;
}
if (lastavail > 0) {
Log.i("memory", "consumed since last: " + ((lastavail - memoryAvailable) / 1048576d));
}
Log.i("memory", "consumed total: " + ((initavail - memoryAvailable) / 1048576d));
lastavail = memoryAvailable;
Log.i("memory",
"-----------------------------------------------------------------------------------------------");
}
示例4: getFreeMemorySize
import android.os.Debug; //导入方法依赖的package包/类
public static long getFreeMemorySize() {
long max = Runtime.getRuntime().maxMemory();
long heapSize = Runtime.getRuntime().totalMemory();
long heapRemaining = Runtime.getRuntime().freeMemory();
long nativeUsage = Debug.getNativeHeapAllocatedSize();
return (max - heapSize - nativeUsage) + heapRemaining;
}
示例5: detectDebugPreference
import android.os.Debug; //导入方法依赖的package包/类
private void detectDebugPreference() {
Preference debugPreferenceCategory = (PreferenceCategory) findPreference(DEBUG_INFO);
Preference debugPreference = findPreference(SettingActivity.DEBUG_MEM_INFO);
Preference crashPreferenceCategory = findPreference(SettingActivity.CRASH);
if (SettingUtils.isBlackMagicEnabled()) {
Runtime rt = Runtime.getRuntime();
long vmAlloc = rt.totalMemory() - rt.freeMemory();
long nativeAlloc = Debug.getNativeHeapAllocatedSize();
String vmAllocStr = "VM Allocated " + formatMemoryText(vmAlloc);
String nativeAllocStr = "Native Allocated " + formatMemoryText(nativeAlloc);
ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
int memoryClass = am.getMemoryClass();
String result = "VM Max " + Integer.toString(memoryClass) + "MB";
debugPreference.setSummary(vmAllocStr + "," + nativeAllocStr + "," + result);
crashPreferenceCategory.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
throw new IllegalArgumentException("about -> crash test");
}
});
} else {
PreferenceScreen screen = getPreferenceScreen();
screen.removePreference(debugPreferenceCategory);
}
}
示例6: logHeap
import android.os.Debug; //导入方法依赖的package包/类
public static void logHeap() {
Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
Log.d("tag", "debug. =================================");
Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
}
示例7: checkBitmapFitsInMemory
import android.os.Debug; //导入方法依赖的package包/类
/**
* Checks if a bitmap with the specified size fits in memory
* Source: https://stackoverflow.com/a/6893818
*
* @param bmpwidth Bitmap width
* @param bmpheight Bitmap height
* @param bmpdensity Bitmap bpp (use 2 as default)
* @return true if the bitmap fits in memory false otherwise
*/
private static boolean checkBitmapFitsInMemory(long bmpwidth, long bmpheight, int bmpdensity) {
long reqsize = bmpwidth * bmpheight * bmpdensity;
long allocNativeHeap = Debug.getNativeHeapAllocatedSize();
final long heapPad = (long) Math.max(4 * 1024 * 1024, Runtime.getRuntime().maxMemory() * 0.1);
if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory()) {
return false;
}
return true;
}
示例8: getHeapNative
import android.os.Debug; //导入方法依赖的package包/类
public static long[] getHeapNative() {
long[] value = new long[2];
value[0] = Debug.getNativeHeapSize() >> 10;
value[1] = Debug.getNativeHeapAllocatedSize() >> 10;
return value;
}
示例9: getNativeHeapAllocatedSize
import android.os.Debug; //导入方法依赖的package包/类
/** 已获得 堆内存, 单位 MB */
public static long getNativeHeapAllocatedSize() {
return Debug.getNativeHeapAllocatedSize() / 1024 / 1024;
}
示例10: getNativeHeap
import android.os.Debug; //导入方法依赖的package包/类
@Override
public long getNativeHeap () {
return Debug.getNativeHeapAllocatedSize();
}
示例11: getNativeHeap
import android.os.Debug; //导入方法依赖的package包/类
@Override
public long getNativeHeap() {
return Debug.getNativeHeapAllocatedSize();
}
示例12: getNativeHeapAllocatedSize
import android.os.Debug; //导入方法依赖的package包/类
public static long getNativeHeapAllocatedSize() {
return Debug.getNativeHeapAllocatedSize() / DataConstants.BYTES_PER_KILOBYTE;
}