List of usage examples for android.os Debug getNativeHeapAllocatedSize
public static native long getNativeHeapAllocatedSize();
From source file:Main.java
/**Returns max memory for app * @return current max memory size for app *//*from w ww . ja va2 s .c o m*/ private static long calcAvailableMemory() { long value = Runtime.getRuntime().maxMemory(); //String type = ""; if (Build.VERSION.SDK_INT >= 11) { value = (value / 1024) - (Runtime.getRuntime().totalMemory() / 1024); //type = "JAVA"; } else { value = (value / 1024) - (Debug.getNativeHeapAllocatedSize() / 1024); //type = "NATIVE"; } return value; }
From source file:Main.java
public static long[] getHeapNative() { int Native_HeapSize = 0; int Native_HeapAlloc = 1; long[] value = new long[2]; value[Native_HeapSize] = Debug.getNativeHeapSize() >> 10; value[Native_HeapAlloc] = Debug.getNativeHeapAllocatedSize() >> 10; return value; }
From source file:Main.java
public static long[] getVM() { long[] value = new long[5]; value[0] = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 10; value[1] = Runtime.getRuntime().totalMemory() >> 10; value[2] = Debug.getNativeHeapAllocatedSize() >> 10; value[3] = Debug.getNativeHeapSize() >> 10; value[4] = Debug.getGlobalAllocSize() >> 10; return value; }
From source file:com.pongme.utils.ImageDownloader.java
public void showUsedMegs() { int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L); String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs); Log.i(LOG_TAG, usedMegsString);//from w ww . j av a 2 s .co m }
From source file:com.midisheetmusicmemo.ChooseSongActivity.java
public static void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize()) / new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize()) / 1048576.0f; Double free = new Double(Debug.getNativeHeapFreeSize()) / 1048576.0f; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);/* w w w. ja v a 2s .c om*/ df.setMinimumFractionDigits(2); Log.d("blah", "debug. ================================="); Log.d("blah", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)"); Log.d("blah", "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)"); System.gc(); System.gc(); }
From source file:com.hippo.ehviewer.EhApplication.java
private void debugPrint() { new Runnable() { @Override/* w w w . j a v a2 s.co m*/ public void run() { if (DEBUG_PRINT_NATIVE_MEMORY) { Log.i(TAG, "Native memory: " + FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false)); } if (DEBUG_PRINT_IMAGE_COUNT) { Log.i(TAG, "Image count: " + Image.getImageCount()); } SimpleHandler.getInstance().postDelayed(this, DEBUG_PRINT_INTERVAL); } }.run(); }
From source file:net.microtrash.clapcamera.Preview.java
/** * find the best resolution for both: picture and preview size by following * rules ISSUES: 1. on each device you have several different camera picture * sizes and camera preview sizes 2. the picture size and the camera size * have to match in terms of their width to height relation (=aspect ratio) * 3. we want to make sure the area of the display is used as efficient as * possible, therefore we should try to match the aspect ratios of display * and image as well 4. you never know how much RAM you will have available, * once the user switches the app and returnes, memory might not be enough * anymore//w w w.j a v a 2 s. c o m * * VERY NEW: 1. find all preview sizes which match a image size (same aspect * ratio) -> resolution-settings 2. preselect the highest * resolution-settings which fits twice into memory 3. generate UI for * selecting other resolutions-settings-> let the user decide which * resolution fits best for his/her device * * NEW: 1. calculate targetRato = device display aspect ratio 2. find a * matching preview image size and set it as bestPictureSize (matching: the * picture and preview aspect ratios have to match) 3. if a another * pictureSize-previewSize match is found, which has a better targetRatio * match and the picture size > bestPictureSize - 20% -> set this one as * bestPictureSize 4. try to find a downscaling factor which allows us to * keep 2-3 layers (bitmap instances) of that resolution in memory * * OLD: 1. try to find the best matching picture resolution for targetRatio * 2. only allow resolutions above 800px width 3. look for an exactly * matching preview resolution. if not found: 4. try to find the second best * matching picture resolution for targetRatio and start all over again 5. * if nothing matching was found: use first picture and first preview * resolution * * @param targetRatio */ private void calculateOptimalPictureAndPreviewSizes() { /* * double fullWidth = (double) cameraActivity.display.getWidth(); double * fullHeight = (double) cameraActivity.display.getHeight(); */ double targetRatio = (fullWidth - 2 * (double) padding) / (fullHeight - 2 * (double) padding); Log.v(TAG, "calculateOptimalPictureAndPreviewSizes() width targetRatio: " + targetRatio + " fullWidth:" + fullWidth + " fullHeight:" + fullHeight); if (bestPreviewSize == null) { allResolutions = ""; List<Size> pictureSizes = this.camera.getParameters().getSupportedPictureSizes(); List<Size> previewSizes = this.camera.getParameters().getSupportedPreviewSizes(); Collections.sort(pictureSizes, new Comparator<Size>() { public int compare(Size s1, Size s2) { return s2.width - s1.width; } }); Collections.sort(previewSizes, new Comparator<Size>() { public int compare(Size s1, Size s2) { return s2.width - s1.width; } }); allResolutions += "picture sizes:\n"; for (Size size : pictureSizes) { allResolutions += String.valueOf(size.width) + 'x' + String.valueOf(size.height) + ", ratio: " + ((double) size.width / (double) size.height) + ";\n"; } allResolutions += "preview sizes:\n"; for (Size size : previewSizes) { allResolutions += String.valueOf(size.width) + 'x' + String.valueOf(size.height) + ", ratio: " + ((double) size.width / (double) size.height) + ";\n"; } Log.v(TAG, "allResolutions: \n" + allResolutions); double bestRatio = 0; boolean matchingFinished = false; Log.v(TAG, "start matching picture and preview size..."); for (Size pictureSize : pictureSizes) { double pictureRatio = (double) pictureSize.width / (double) pictureSize.height; Log.v(TAG, "size: " + pictureSize.width + "x" + pictureSize.height + " " + pictureRatio); double previewRatio; for (Size previewSize : previewSizes) { previewRatio = (double) previewSize.width / (double) previewSize.height; if (previewRatio == pictureRatio) { if (bestPreviewSize == null) { bestPreviewSize = previewSize; bestPictureSize = pictureSize; bestRatio = pictureRatio; Log.v(TAG, "found picture size:" + bestPictureSize.width + "x" + bestPictureSize.height + " ratio: " + ((double) bestPictureSize.width / (double) bestPictureSize.height)); Log.v(TAG, "...continue searching..."); break; } else { Log.v(TAG, " pixels: " + pictureSize.width * pictureSize.height); Log.v(TAG, " thresh: " + (double) bestPictureSize.width * (double) bestPictureSize.height * 0.75D); if (Math.abs(targetRatio - bestRatio) > Math.abs(targetRatio - pictureRatio) && pictureSize.width * pictureSize.height > (double) bestPictureSize.width * (double) bestPictureSize.height * 0.75D) { bestPreviewSize = previewSize; bestPictureSize = pictureSize; bestRatio = pictureRatio; matchingFinished = true; Log.v(TAG, "found even better match:" + bestPictureSize.width + "x" + bestPictureSize.height + " ratio: " + ((double) bestPictureSize.width / (double) bestPictureSize.height)); } } } } if (matchingFinished) { break; } } if (bestPreviewSize == null) { bestPictureSize = pictureSizes.get(0); bestPreviewSize = previewSizes.get(0); Log.v(TAG, "no match found!"); } downscalingFactor = Tools.getDownscalingFactor(bestPictureSize.width, bestPictureSize.height); Log.v(TAG, "choosen picture size:" + bestPictureSize.width + "x" + bestPictureSize.height + " ratio: " + ((double) bestPictureSize.width / (double) bestPictureSize.height)); Log.v(TAG, "choosen preview size:" + bestPreviewSize.width + "x" + bestPreviewSize.height + " ratio: " + ((double) bestPreviewSize.width / (double) bestPreviewSize.height)); Log.v(TAG, "choosen downScalingFactor: " + downscalingFactor); // instantiate metadata json object JSONObject metadata = new JSONObject(); MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); final long mb = 1024L * 1024L; try { metadata.put("totalMemory", Runtime.getRuntime().totalMemory() / mb); metadata.put("freeMemory", Runtime.getRuntime().freeMemory() / mb); metadata.put("maxMemory", Runtime.getRuntime().maxMemory() / mb); metadata.put("availableMemory", mi.availMem / mb); metadata.put("nativeHeapAllocatedSize", Debug.getNativeHeapAllocatedSize() / mb); metadata.put("heapPad", Tools.getHeapPad() / mb); metadata.put("bestPictureSize", bestPictureSize.width + "x" + bestPictureSize.height); metadata.put("bestPreviewSize", bestPreviewSize.width + "x" + bestPreviewSize.height); metadata.put("workingPictureSize", (int) bestPictureSize.width / downscalingFactor + "x" + (int) bestPictureSize.height / downscalingFactor); metadata.put("downscalingFactor", downscalingFactor); metadata.put("requiredSize", (bestPictureSize.width / downscalingFactor) * (bestPictureSize.height / downscalingFactor) * 4 * 2 / mb); // 4 channels * 2 layers } catch (JSONException e) { e.printStackTrace(); } Crittercism.setMetadata(metadata); } }
From source file:com.aujur.ebookreader.Configuration.java
public static double getBitmapMemoryUsage() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { return getMemoryUsage(); }/*from ww w . j a va 2s . c o m*/ long max = Runtime.getRuntime().maxMemory(); long used = Debug.getNativeHeapAllocatedSize(); return (double) used / (double) max; }
From source file:com.zoffcc.applications.zanavi.Navit.java
public static String logHeap(Class clazz) { Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576)); Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0)); Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0)); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);//from w w w . ja va 2 s . c o m df.setMinimumFractionDigits(2); // Log.d("Navit", "MemMem:DEBUG: ================================="); Log.d("Navit", "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]"); Log.d("Navit", "MemMem:DEBUG:java memory: allc: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum=" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)"); calcAvailableMemory(); String mem_type = "NATIVE"; try { if (android.os.Build.VERSION.SDK_INT >= 11) { mem_type = "JAVA"; } } catch (Exception e) { } return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type); }
From source file:com.zoffcc.applications.zanavi.Navit.java
public static String logHeap_for_batch(Class clazz) { try {/* w w w. j a v a 2s . c o m*/ Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576)); Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0)); Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0)); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); // Log.d("Navit", "MemMem:DEBUG: ================================="); Log.d("Navit", "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]"); Log.d("Navit", "MemMem:DEBUG:java memory: allc: " + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum=" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB (" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)"); // calcAvailableMemory(); String mem_type = "NATIVE"; try { if (android.os.Build.VERSION.SDK_INT >= 11) { mem_type = "JAVA"; } } catch (Exception e) { } // return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":" + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/" + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "(" + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type); return ("==MEM==:" + "J:" + (Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + ":" + (Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + ",N:" + allocated + ":" + sum_size); } catch (Exception e2) { return ("==MEM==:ERROR"); } }