zoukankan      html  css  js  c++  java
  • 慢函数检测

    目的:检测影响主线程执行的慢函数。

    上文讲述了在编译期,会对每个方法的执行体前后添加上MethodBeat.i(int methodId)和MethodBeat.o(int methodId)的方法调用,且methodId是在编译期生成的,在运行时是一个写死的常量。通过编译期的这个操作,就能感知到具体每个方法的进入、退出动作。下面来看下这两个方法的内部实现

    /**
    * hook method when it's called in.
    *
    * @param methodId
    */
    public static void i(int methodId) {
    if (isBackground) {
    return;
    }
    ...
    isRealTrace = true;
    if (isCreated && Thread.currentThread() == sMainThread) {
    ...
    } else if (!isCreated && Thread.currentThread() == sMainThread && sBuffer != null) {
    ..
    }
    }

    /**
    * hook method when it's called out.
    *
    * @param methodId
    */
    public static void o(int methodId) {
    if (isBackground || null == sBuffer) {
    return;
    }
    if (isCreated && Thread.currentThread() == sMainThread) {
    ...
    } else if (!isCreated && Thread.currentThread() == sMainThread) {
    ...
    }
    }
    复制代码
    统计了当应用处于前台时,在主线程执行的方法的进入、退出。这些信息最后存储在MethodBeat的Buffer中。当主线程有疑似慢函数存在时,读取Buffer的数据,分析可能的慢函数,并上报json数据到后端(后端将methodId转换为具体的方法声明)。

    疑似发生慢函数的实际有两个:一个是掉帧的场景,一个是类似ANR这样长时间主线程阻塞UI绘制的场景。

  • 相关阅读:
    在线编辑器fckeditor的使用和配置
    Oracle CHAR,VARCHAR,VARCHAR2类型的区别与使用
    where having 的区别
    软件架构师之我见
    在线编辑器fckeditor的使用和配置
    where having 的区别
    必须掌握的八个【cmd 命令行】
    浅析PHP实现同步远程MysqlPHP编程教程详解
    MSSQL智能感应
    SQL统计表行数
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11295897.html
Copyright © 2011-2022 走看看