导航:首页 > 操作系统 > android获取可用内存

android获取可用内存

发布时间:2023-09-14 01:27:59

1. android 高通cpu怎么用adb查看mem

.一、利用Android API函数查看
1.1 ActivityManager查看可用内存。
ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(outInfo);
outInfo.availMem即为可用空闲凯亩睁内存。
1.2、android.os.Debug查询PSS,VSS,USS等单个进程使用内存信息
MemoryInfo[] memoryInfoArray = am.getProcessMemoryInfo(pids);
MemoryInfo pidMemoryInfo=memoryInfoArray[0];
pidMemoryInfo.getTotalPrivateDirty();

getTotalPrivateDirty()
Return total private dirty memory usage in kB. USS

getTotalPss()
Return total PSS memory usage in kB.
PSS
getTotalSharedDirty()
Return total shared dirty memory usage in kB. RSS

二、直接对Android文件进行解析查询,
/proc/cpuinfo系统CPU的类型等多种信息。
/proc/meminfo 系统内存使用信息

/proc/meminfo
MemTotal: 16344972 kB
MemFree: 13634064 kB
Buffers: 3656 kB
Cached: 1195708 kB
我们查看机器内存时,会发现MemFree的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。
所以 空闲内存=free+buffers+cached=total-used
通过读取文件/proc/meminfo的信息获取Memory的总量。
ActivityManager. getMemoryInfo(ActivityManager.MemoryInfo)获取当前的可用Memory量。

三、通过Android系统提供的Runtime类,执行adb 命令(top,procrank,ps...等命令)查询
通过对执行结果的标准控制台输出进行解析。这样大大的扩展了Android查询功能.例如:
final Process m_process = Runtime.getRuntime().exec("/system/bin/top -n 1");
final StringBuilder sbread = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(m_process.getInputStream()), 8192);

# procrank
Runtime.getRuntime().exec("/system/xbin/procrank");
内存耗用:VSS/RSS/PSS/USS
Terms
• VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的耐孝内存)
• RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
• PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
• USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
一般来说内存占用大小有盯岁如下规律:VSS >= RSS >= PSS >= USS
USS is the total private memory for a process, i.e. that memory that is completely unique to that process.USS is an extremely useful number because it indicates the true incremental cost of running a particular process. When a process is killed, the USS is the total memory that is actually returned to the system. USS is the best number to watch when initially suspicious of memory leaks in a process.
转载

2. android 怎样获取当前apk所占用的内存

这个方法有很多,常用的是 adb shell mpsys meminfo <package_name> 这可以看到比较全面的信息,由于Android是有内存共享的,所以通常有 VSS,RSS,PSS,USS等不同的内存表述,比较常用的是PSS,会将共享库按照比例分配给当前内存

3. Android获取系统cpu信息,内存,版本,电量等信息

1、CPU频率,CPU信息:/proc/cpuinfo和/proc/stat

通过读取文件/proc/cpuinfo系统CPU的类型等多种信息。

读取/proc/stat 所有CPU活动的信息来计算CPU使用率

下面我们就来讲讲如何通过代码来获取CPU频率:

复制代码 代码如下:

package com.orange.cpu;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

public class CpuManager {

// 获取CPU最大频率(单位KHZ)

// "/system/bin/cat" 命令行

// "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的.路径

public static String getMaxCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };

cmd = new ProcessBuilder(args);

Process process = cmd.start();

InputStream in = process.getInputStream();

byte[] re = new byte[24];

while (in.read(re) != -1) {

result = result + new String(re);

}

in.close();

} catch (IOException ex) {

ex.printStackTrace();

result = "N/A";

}

return result.trim();

}

// 获取CPU最小频率(单位KHZ)

public static String getMinCpuFreq() {

String result = "";

ProcessBuilder cmd;

try {

String[] args = { "/system/bin/cat",

"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" };

cmd = new ProcessBuilder(args);

Process process = cmd.start();

InputStream in = process.getInputStream();

byte[] re = new byte[24];

while (in.read(re) != -1) {

result = result + new String(re);

}

in.close();

} catch (IOException ex) {

ex.printStackTrace();

result = "N/A";

}

return result.trim();

}

// 实时获取CPU当前频率(单位KHZ)

public static String getCurCpuFreq() {

String result = "N/A";

try {

FileReader fr = new FileReader(

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");

BufferedReader br = new BufferedReader(fr);

String text = br.readLine();

result = text.trim();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return result;

}

// 获取CPU名字

public static String getCpuName() {

try {

FileReader fr = new FileReader("/proc/cpuinfo");

BufferedReader br = new BufferedReader(fr);

String text = br.readLine();

String[] array = text.split(":s+", 2);

for (int i = 0; i < array.length; i++) {

}

return array[1];

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

}

2、内存:/proc/meminfo

复制代码 代码如下:

public void getTotalMemory() {

String str1 = "/proc/meminfo";

String str2="";

try {

FileReader fr = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(fr, 8192);

while ((str2 = localBufferedReader.readLine()) != null) {

Log.i(TAG, "---" + str2);

}

} catch (IOException e) {

}

}

3、Rom大小

复制代码 代码如下:

public long[] getRomMemroy() {

long[] romInfo = new long[2];

//Total rom memory

romInfo[0] = getTotalInternalMemorySize();

//Available rom memory

File path = Environment.getDataDirectory();

StatFs stat = new StatFs(path.getPath());

long blockSize = stat.getBlockSize();

long availableBlocks = stat.getAvailableBlocks();

romInfo[1] = blockSize * availableBlocks;

getVersion();

return romInfo;

}

public long getTotalInternalMemorySize() {

File path = Environment.getDataDirectory();

StatFs stat = new StatFs(path.getPath());

long blockSize = stat.getBlockSize();

long totalBlocks = stat.getBlockCount();

return totalBlocks * blockSize;

}

4、sdCard大小

复制代码 代码如下:

public long[] getSDCardMemory() {

long[] sdCardInfo=new long[2];

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {

File sdcardDir = Environment.getExternalStorageDirectory();

StatFs sf = new StatFs(sdcardDir.getPath());

long bSize = sf.getBlockSize();

long bCount = sf.getBlockCount();

long availBlocks = sf.getAvailableBlocks();

sdCardInfo[0] = bSize * bCount;//总大小

sdCardInfo[1] = bSize * availBlocks;//可用大小

}

return sdCardInfo;

}

5、电池电量

复制代码 代码如下:

private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){

@Override

public void onReceive(Context context, Intent intent) {

int level = intent.getIntExtra("level", 0);

// level加%就是当前电量了

}

};

registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

6、系统的版本信息

复制代码 代码如下:

public String[] getVersion(){

String[] version={"null","null","null","null"};

String str1 = "/proc/version";

String str2;

String[] arrayOfString;

try {

FileReader localFileReader = new FileReader(str1);

BufferedReader localBufferedReader = new BufferedReader(

localFileReader, 8192);

str2 = localBufferedReader.readLine();

arrayOfString = str2.split("s+");

version[0]=arrayOfString[2];//KernelVersion

localBufferedReader.close();

} catch (IOException e) {

}

version[1] = Build.VERSION.RELEASE;// firmware version

version[2]=Build.MODEL;//model

version[3]=Build.DISPLAY;//system version

return version;

}

7、mac地址和开机时间

复制代码 代码如下:

public String[] getOtherInfo(){

String[] other={"null","null"};

WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

if(wifiInfo.getMacAddress()!=null){

other[0]=wifiInfo.getMacAddress();

} else {

other[0] = "Fail";

}

other[1] = getTimes();

return other;

}

private String getTimes() {

long ut = SystemClock.elapsedRealtime() / 1000;

if (ut == 0) {

ut = 1;

}

int m = (int) ((ut / 60) % 60);

int h = (int) ((ut / 3600));

return h + " " + mContext.getString(R.string.info_times_hour) + m + " "

+ mContext.getString(R.string.info_times_minute);

}

4. 如何查看Android手机的内存

打开手机找到设置点击进入

阅读全文

与android获取可用内存相关的资料

热点内容
oppor系列如何解除应用加密 浏览:599
程序员那么可爱姜逸城初恋 浏览:496
modbustcp编程 浏览:491
实况为什么安卓看不了 浏览:129
Java多线程Queue 浏览:95
云服务器499元三年 浏览:980
nbd源码 浏览:847
x86在arm上编译 浏览:8
linux怎么配置网络 浏览:307
程序员想要的小礼物 浏览:187
java获取网页url 浏览:625
怎么做解压神器泡泡版 浏览:967
自己动手做一个c编译器 浏览:930
手机如何链接谷歌服务器地址 浏览:137
废掉一个程序员的武功 浏览:249
java树形算法 浏览:642
通达信加锁指标源码怎么看 浏览:755
将同名文件移动到部分同名文件夹 浏览:404
摆荡指标加压力线源码 浏览:916
新一代单片机特征 浏览:770