eclipse 用adb shell ps 命令检测某个应用的资源占用
2017-04-01 19:37
330 查看
最近学习monkey的时候,了解了一下关于内存溢出的知识,可惜用eclipse的DDMS只能获取到debug调试的进程,所以就写了一个简单的获取某个包占用内存的方法,分享出来,供大家参考。
for(int i=0;i<500;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
execCmd("cmd /c adb shell ps");
}
execCmd的方法改了一下,也可以用参数来控制查询的报名。
public static void execCmd(String cmd) {
System.out.println("----execCmd: " + cmd);
try {
Process p = Runtime.getRuntime().exec(cmd);
// 正确输出流
InputStream input = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = "";
while ((line = reader.readLine()) != null) {
if (line.contains("gaotu")) {
System.out.println(line);
}
// System.out.println(line);
saveToFile(line, "runlog.log", false);
}
// 错误输出流
InputStream errorInput = p.getErrorStream();
BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorInput));
String eline = "";
while ((eline = errorReader.readLine()) != null) {
System.out.println(eline);
saveToFile(eline, "runlog.log", false);
}
} catch (IOException e) {
e.printStackTrace();
}
}saveToFile的方法如下
public static void saveToFile(String text, String path, boolean isClose) {
File file = new File("runlog.log");
BufferedWriter bf = null;
try {
FileOutputStream outputStream = new FileOutputStream(file, true);
OutputStreamWriter outWriter = new OutputStreamWriter(outputStream);
bf = new BufferedWriter(outWriter);
bf.append(text);
bf.newLine();
bf.flush();
if (isClose) {
bf.close();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
for(int i=0;i<500;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
execCmd("cmd /c adb shell ps");
}
execCmd的方法改了一下,也可以用参数来控制查询的报名。
public static void execCmd(String cmd) {
System.out.println("----execCmd: " + cmd);
try {
Process p = Runtime.getRuntime().exec(cmd);
// 正确输出流
InputStream input = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = "";
while ((line = reader.readLine()) != null) {
if (line.contains("gaotu")) {
System.out.println(line);
}
// System.out.println(line);
saveToFile(line, "runlog.log", false);
}
// 错误输出流
InputStream errorInput = p.getErrorStream();
BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorInput));
String eline = "";
while ((eline = errorReader.readLine()) != null) {
System.out.println(eline);
saveToFile(eline, "runlog.log", false);
}
} catch (IOException e) {
e.printStackTrace();
}
}saveToFile的方法如下
public static void saveToFile(String text, String path, boolean isClose) {
File file = new File("runlog.log");
BufferedWriter bf = null;
try {
FileOutputStream outputStream = new FileOutputStream(file, true);
OutputStreamWriter outWriter = new OutputStreamWriter(outputStream);
bf = new BufferedWriter(outWriter);
bf.append(text);
bf.newLine();
bf.flush();
if (isClose) {
bf.close();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
相关文章推荐
- 在adb命令与ddms中能检测设备,但在eclipse中Run Configurations中检测不到真机
- 通过 adb shell dumpsys 命令获取当前应用的 component
- 通过adb shell dumpsys命令获取当前应用的component
- adb的adb shell pm list packages命令用来查看当前设备app应用包
- adb shell 命令操作应用数据文件
- adb shell ps命令
- adb shell命令查看Andriod手机上应用的包名及报错解决方案(win10)
- 【原创】Android开发之ADB及ADB SHELl命令的应用
- 用PS命令查看系统资源占用
- adb shell pm命令初识, 禁止应用开机自启动命令
- linux下采用ps、jstack命令排查命中java应用中占用CPU高的代码
- adb shell 命令获取手机中的运行资源,内存,CPU,dump信息等等
- 使用 adb shell am start-W 命令查看应用启动时间的注意事项
- 【安卓基础四】adb命令使用Heap检测和分析Android应用内存
- linux下采用ps、jstack命令排查命中java应用中占用CPU高的代码
- Linux/shell命令的实际应用——查看Port占用 netstat
- 使用shell命令安装系统级应用以及adb配置环境变量
- Linux入职基础-5.17_ulimit限制shell启动进程所占用资源(应用实战1)
- Linux/shell命令的实际应用——netstat查看Port占用
- adb的adb shell pm list packages命令用来查看当前设备app应用包