zoukankan      html  css  js  c++  java
  • Android中如何查看内存(下)

    Android中如何查看内存(下)

    实例1

        int cnt=0;

        final static int kBufferMinSize=1000;

        final static int kBufferMaxSize=2000;

        StringBuffer strBuffer=new StringBuffer(kBufferMinSize);

        StringBuffer strBuffer2=new StringBuffer(kBufferMinSize);

        StringBuffer strBuffer3=new StringBuffer(kBufferMinSize);

        StringBuffer strBufferNativePss=new StringBuffer(kBufferMinSize);

        StringBuffer strBufferDalvikPss=new StringBuffer(kBufferMinSize);

        StringBuffer strBufferOtherPss=new StringBuffer(kBufferMinSize);

        Debug.MemoryInfo memoryInfo=new Debug.MemoryInfo();

        final static String tag="robin";

        void printMemory()

        {

         long totalMemory=Runtime.getRuntime().totalMemory();

              long freeMemory=Runtime.getRuntime().freeMemory();

              long usedMemory=(totalMemory-freeMemory)>>10;

              totalMemory=totalMemory>>10;

              freeMemory=freeMemory>>10;

              if(strBuffer.length()>kBufferMaxSize)

              {

                    strBuffer.delete(0,strBuffer.length());

                    strBuffer2.delete(0,strBuffer2.length());

                    strBuffer3.delete(0,strBuffer3.length());

                    strBufferNativePss.delete(0,strBufferNativePss.length());

                    strBufferDalvikPss.delete(0,strBufferDalvikPss.length());

              }

              strBuffer.append(usedMemory+",");

              strBuffer2.append(totalMemory+",");

              strBuffer3.append((Debug.getNativeHeapSize()>>10)+",");

              Debug.getMemoryInfo(memoryInfo);

              strBufferNativePss.append((memoryInfo.nativePss)+",");

              strBufferDalvikPss.append((memoryInfo.dalvikPss)+",");

              if(cnt++%10==0)

              {

                    Log.i(tag,"usedMemory:"+strBuffer.toString());

                    Log.i(tag,"totalMemory:"+strBuffer2.toString());

                    Log.i(tag,"NativeHeapSize:"+strBuffer3.toString());

                    Log.i(tag,"Native PSS:"+strBufferNativePss.toString());

                    Log.i(tag,"Dalvik PSS:"+strBufferDalvikPss.toString());

              }    

        }

    注意,对于输出的内存信息日志,我们稍作编辑就可以用于在excel产中图表,比便更直观的进行分析
  • 相关阅读:
    C# 网络编程之基于SMTP发送电子邮件
    C#实现邮件发送的功能
    Java发邮件基础篇
    java发送邮件高级篇
    Windows下bat脚本自动发邮件
    Python发送QQ邮件
    信息系统项目管理师EV、PV、AC、BAC、CV、SV、EAC、ETC、CPI、SPI概念说明
    DOS命令整理
    JAVA对时间的操作
    JAVA 调用HTTP接口POST或GET实现方式(转)
  • 原文地址:https://www.cnblogs.com/qingchen1984/p/4971440.html
Copyright © 2011-2022 走看看