Android性能检测--traceview工具各个参数的意思
9119 点击·0 回帖
![]() | ![]() | |
![]() | Android性能检测 traceview的使用方法 1. 把android-sdk-windows\tools路径加到Path当中 2. 编写测试代码: [java] package com.wwj.traceview; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.os.Debug; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { private List<Integer> list1 = new ArrayList<Integer>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //第一个测试方法 public void test1() { //向List1对象添加10000个数 for(int i = 0; i < 10000; i++) { list1.add(i); } } //第二个测试方法 public void test2() { //依次获得List对象中的元素 for(int i = 0; i < 10000; i++) { list1.get(i); } } public void onClick_Test(View view) { try { /*//获取执行test1方法前的时间点(单位:毫秒) long start1 = System.currentTimeMillis(); test1(); long end1 = System.currentTimeMillis(); //获取执行test2方法前的时间点(单位:毫秒) long start2 = System.currentTimeMillis(); test2(); long end2 = System.currentTimeMillis(); //显示测试结果 Toast.makeText(this, "test1方法的执行时间:" + (end1 - start1) + "毫秒\ntest2方法的执行时间: " + (end2 - start2) + "毫秒", Toast.LENGTH_LONG).show();*/ //获取调用test1方法之前的内存 /*long start1 = Memory.used(); test1(); //获取调用test1方法之后的内存 long end1 = Memory.used(); //获取调用test1方法之前的内存 long start2 = Memory.used(); test2(); //获取调用test1方法之后的内存 long end2 = Memory.used(); Toast.makeText(this, "test1方法占用的内存:" + (end1 - start1) + "字节\ntest2方法占用的内存: " + (end2 - start2) + "字节", Toast.LENGTH_LONG).show(); */ //开始监视方法 Debug.startMethodTracing("wwj_trace"); test1(); test2(); Debug.stopMethodTracing(); } catch (Exception e) { e.printStackTrace(); } } } package com.wwj.traceview; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.os.Debug; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { private List<Integer> list1 = new ArrayList<Integer>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //第一个测试方法 public void test1() { //向List1对象添加10000个数 for(int i = 0; i < 10000; i++) { list1.add(i); } } //第二个测试方法 public void test2() { //依次获得List对象中的元素 for(int i = 0; i < 10000; i++) { list1.get(i); } } public void onClick_Test(View view) { try { /*//获取执行test1方法前的时间点(单位:毫秒) long start1 = System.currentTimeMillis(); test1(); long end1 = System.currentTimeMillis(); //获取执行test2方法前的时间点(单位:毫秒) long start2 = System.currentTimeMillis(); test2(); long end2 = System.currentTimeMillis(); //显示测试结果 Toast.makeText(this, "test1方法的执行时间:" + (end1 - start1) + "毫秒\ntest2方法的执行时间: " + (end2 - start2) + "毫秒", Toast.LENGTH_LONG).show();*/ //获取调用test1方法之前的内存 /*long start1 = Memory.used(); test1(); //获取调用test1方法之后的内存 long end1 = Memory.used(); //获取调用test1方法之前的内存 long start2 = Memory.used(); test2(); //获取调用test1方法之后的内存 long end2 = Memory.used(); Toast.makeText(this, "test1方法占用的内存:" + (end1 - start1) + "字节\ntest2方法占用的内存: " + (end2 - start2) + "字节", Toast.LENGTH_LONG).show(); */ //开始监视方法 Debug.startMethodTracing("wwj_trace"); test1(); test2(); Debug.stopMethodTracing(); } catch (Exception e) { e.printStackTrace(); } } } | |
![]() | ![]() |