我们致力于为开发者解决应用性能问题,分析问题的瓶颈,实时追踪用户的真实体验并统计使用状况。
最近android版的SDK开发完成,发布后用户增长速度没有达到预期的要求,让我们很苦恼。
我们内部猜测,可能是用户不太会用我们的产品(安装、部署确实不容易),为此我们开发了一个Demo并开放源码,供各位朋友试用,玩耍。
Demo主要有五个功能组成:
1.json相关事务的执行情况
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
setContentView(R.layout.show_content_layout);
TextView tvTitle = (TextView) findViewById(R.id.title);
TextView tvContent = (TextView) findViewById(R.id.content);
tvTitle.setText(R.string.title_Loadjson);
try {
String ret = NetWorkOperaction.requestByHttpGet("http://tongdianer.com/out.json");
NetWorkOperaction.WeatherModel m = NetWorkOperaction.WeatherModel.parse(ret);
String content=getResources().getString(R.string.content_Loadjson);
tvContent.setText(content+m.weather1);
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(this, R.string.ToastLoadjson, 1).show();
e.printStackTrace();
}
}
2.数据库操作的执行时间
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_content_layout);
TextView tvTitle = (TextView) findViewById(R.id.title);
final TextView tvContent = (TextView) findViewById(R.id.content);
tvTitle.setText(R.string.databaseTitle);
progressDialog = CustomProgressDialog.createDialog(this);
progressDialog.setMessage(R.string.processDialog);
progressDialog.setCanceledOnTouchOutside(true);
progressDialog.show();
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
progressDialog.dismiss();
}
});
new Thread(){
public void run(){
Test.testDatabase(DatabaseDemo.this);
DatabaseDemo.this.runOnUiThread(new Runnable(){
@Override
public void run() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
tvContent.setText(R.string.databaseContent);
}
});
};
}.start();
}
3.图片加载和UI渲染时间
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_content_layout);
progressDialog = CustomProgressDialog.createDialog(this);
progressDialog.setMessage(R.string.processDialog);
progressDialog.setCanceledOnTouchOutside(true);
progressDialog.show();
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
progressDialog.dismiss();
}
});
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
TextView tvTitle = (TextView) findViewById(R.id.title);
final TextView tvContent = (TextView) findViewById(R.id.content);
tvTitle.setText(R.string.title_ViewLoading);
new Thread(new Runnable() {
@Override
public void run() {
try {
String url = "http://i.imgur.com/CdjPpmi.jpg";
NetWorkOperaction.requestByHttpGet(url);
NetWorkOperaction.requestByHttpGet(url);
NetWorkOperaction.requestByHttpGet(url);
ViewLoading.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (progressDialog != null&& progressDialog.isShowing()) {
progressDialog.dismiss();
}
tvContent.setText(R.string.content_ViewLoading);
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(ViewLoading.this,R.string.ToastViewLoading, 1).show();
e.printStackTrace();
}
}
}).start();
}
4.crash报告和分析
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DbHelper.testSql();
}
5.解析图片的执行时间
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.test_load_image);
progressDialog = CustomProgressDialog.createDialog(this);
progressDialog.setMessage(R.string.processDialog);
progressDialog.setCanceledOnTouchOutside(true);
progressDialog.show();
progressDialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
progressDialog.dismiss();
}
});
//测试加载一个远程的图片,并decode
new Thread(new Runnable() {
@Override
public void run() {
final ImageView img = (ImageView) findViewById(R.id.iamgeView);
try {
final Bitmap bitmap = ImageFetchOp.getImage("http://i.imgur.com/CdjPpmi.jpg");
if(bitmap!=null){
LoadImgActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
img.setImageBitmap(bitmap);
}
});
}
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(LoadImgActivity.this, R.string.ToastImg, 1).show();
e.printStackTrace();
}
}
}).start();
}
完整源码地址:
https://github.com/terrygl/oneapm_mobile_demo 注意:要使用以上功能,请务必安装android SDK,安装方法如下
安装说明:
请参看:
http://oneapm.com/features/android.html DEMO登陆地址:
https://user.oneapm.com/account/login.do 用户名:
mobile@oneapm.com 密码:123456
朋友们最好注册一个账号,部署测试探针,听说成功部署后有礼品相送哦!!!
注册地址:
https://user.oneapm.com/account/register.do 请各位朋友试用后,多提宝贵意见。
最后唠叨一句:OneAPM的活动还在进行中,还没领取礼物的小伙伴还在等什么?
活动链接:
http://www.v2ex.com/t/129351