V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
blueware
V2EX  ›  程序员

OneAPM 开源 Demo 代码,亲身感受 mobile APM。

  •  
  •   blueware · 2014-08-27 18:47:45 +08:00 · 4922 次点击
    这是一个创建于 3829 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我们致力于为开发者解决应用性能问题,分析问题的瓶颈,实时追踪用户的真实体验并统计使用状况。

    最近android版的SDK开发完成,发布后用户增长速度没有达到预期的要求,让我们很苦恼。

    我们内部猜测,可能是用户不太会用我们的产品(安装、部署确实不容易),为此我们开发了一个Demo并开放源码,供各位朋友试用,玩耍。



    Demo主要有五个功能组成:

    1.json相关事务的执行情况

    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();
    }
    }
    view raw gistfile1.java hosted with ❤ by GitHub


    2.数据库操作的执行时间

    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();
    }
    view raw gistfile1.java hosted with ❤ by GitHub


    3.图片加载和UI渲染时间

    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();
    }
    view raw gistfile1.java hosted with ❤ by GitHub


    4.crash报告和分析

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DbHelper.testSql();
    }
    view raw gistfile1.java hosted with ❤ by GitHub


    5.解析图片的执行时间

    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();
    }
    view raw gistfile1.java hosted with ❤ by GitHub


    完整源码地址:

    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

    4 条回复    2014-08-28 09:37:00 +08:00
    stupil
        1
    stupil  
       2014-08-27 21:15:51 +08:00
    我的奖品呢。。。
    blueware
        2
    blueware  
    OP
       2014-08-28 00:13:39 +08:00
    @stupil 还没发货那么快,毕竟不是淘宝店啊亲~
    stupil
        3
    stupil  
       2014-08-28 00:41:34 +08:00
    @blueware
    其实貌似我没中奖。。。

    在哪里看中奖名单呢。。
    blueware
        4
    blueware  
    OP
       2014-08-28 09:37:00 +08:00
    @stupil .....
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1045 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:32 · PVG 03:32 · LAX 11:32 · JFK 14:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.