【问题标题】:Active memory of Mobile - android手机的主动内存 - android
【发布时间】:2012-06-16 13:09:13
【问题描述】:

大家好,希望你们都做得很好, 伙计们,我有一个问题,如果我们使用 adb shell cat /proc/meminfo 来获取 Ram 大小,我们如何获得 android 设备的活动、非活动和有线内存使用情况,我得到一个大字符串活跃和不活跃的记忆 这是相同的代码

    ProcessBuilder cmd;

    StringBuffer strMemory = new StringBuffer();
    // final ActivityManager activityManager =(ActivityManager)
    // context.getSystemService(Context.ACTIVITY_SERVICE);

    ActivityManager actvityManager = (ActivityManager) this
            .getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo();
    actvityManager.getMemoryInfo(mInfo);

    strMemory.append("Available Memory : ");
    strMemory.append(mInfo.availMem / 1048576L);
    strMemory.append("\n");
    strMemory.append("\n");

    String result = strMemory.toString();

    try {
        String[] args = { "/system/bin/cat", "/proc/meminfo" };
        cmd = new ProcessBuilder(args);

        Process process = cmd.start();
        InputStream in = process.getInputStream();
        byte[] re = new byte[1024];
        while (in.read(re) != -1) {
            // System.out.println("itthhe   ====  ---   >>>>    "+new
            // String(re));
            String str = new String(re);
            // int a = Integer.parseInt(str);
            System.out.println("oiiidd str 11111111111 --->>>   " +     str);
            // Long aa = Long.parseLong(str)/1048576L;
            String st = "Active";
            System.out.println("oii0--->>>>   "+st.substring(0,2));
            int l1 = st.length();

            if (l1 > 3) { l1 = 4; }

            System.out.println("oiiidd str  --->>>   " + str);
            if (str.startsWith(st.substring(0,l1))) 
            {
                System.out.println(str+"      -------------------printed dude ");
             // do something..
            }

            result = result + new String(re);
        }
        in.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return result;

现在从这里我得到大字符串

MemTotal:         256556 kB
MemFree:           93576 kB
Buffers:            1036 kB
Cached:            70064 kB
SwapCached:            0 kB
Active:            97496 kB
Inactive:          48828 kB
Active(anon):      79884 kB
Inactive(anon):        0 kB
Active(file):      17612 kB
Inactive(file):    48828 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         75244 kB
Mapped:            36340 kB
Slab:               4528 kB
SReclaimable:       1448 kB
SUnreclaim:         3080 kB
PageTables:         6864 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      128276 kB
Committed_AS:    1084956 kB
VmallocTotal:     712704 kB
VmallocUsed:       22596 kB
VmallocChunk:     684036 kB

现在我如何解析活动和非活动数据,

还有没有其他方法可以找到或者这是找到这些数据的唯一方法`

【问题讨论】:

  • 首先,你不需要(也不应该使用)cat,你应该直接读取文件。其次,java在String类中有常用的各种方法,查一下,你应该会发现一些想法(也有更高级的解析系统,但你几乎不需要)
  • 谢谢 Chris Stratton,我试过了,但我找不到有线内存,你知道我们如何获得有线内存吗?我不知道如何找到这个,任何提前感谢您的帮助,非常感谢您的宝贵回复
  • 什么是“有线”内存?实际上,任何物理存在但内核不可用的内存都不应该被第 3 方应用程序开发人员所关注——它可能是为无线电固件或类似的东西保留的。

标签: android memory ram


【解决方案1】:

【讨论】:

  • DDMS 是一个主机工具,发布者似乎试图在设备上运行的应用程序中做某事。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 2012-06-25
  • 1970-01-01
  • 2013-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多