BlockCanary原始碼解析

2021-09-27 08:26:42 字數 1939 閱讀 4086

隨著**複雜度越來越大,我們越來越難定位到ui卡頓的問題,所以需要用到blockcanary來定位卡頓的原因

implementation 'com.github.markzhai:blockcanary-android:1.5.0'
blockcanary.install(this,new blockcanarycontext()).start();
public static blockcanary install(context context, blockcanarycontext blockcanarycontext) 

static void init(context context, blockcanarycontext blockcanarycontext)

public static blockcanary get()

}}

blockcanary 中會建立乙個blockcanaryinternals 這個方法很重要日誌的列印和cpu的列印都是在這裡的出現的
public blockcanaryinternals() }}

}}, getcontext().provideblockthreshold(), getcontext().stopwhendebugging()));

logwriter.cleanobsolete();

}

public void println(string x) 

if (!mprintingstarted) else

stopdump();

}}

private void startdump() 

if (null != blockcanaryinternals.getinstance().cpusampler)

}private void stopdump()

if (null != blockcanaryinternals.getinstance().cpusampler)

}

我們看到 blockcanaryinternals.getinstance().stacksampler.start();
abstract class abstractsampler 

}};、

其實就是兩個執行緒 最後呼叫到dosample()方法我們看到dosample方法
protected void dosample() 

if (mpid == 0)

pidreader = new bufferedreader(new inputstreamreader(

new fileinputstream("/proc/" + mpid + "/stat")), buffer_size);

string pidcpurate = pidreader.readline();

if (pidcpurate == null)

parse(cpurate, pidcpurate);

} catch (throwable throwable) finally

if (pidreader != null)

} catch (ioexception exception)

}}

cpu的dosample方法就是把資料列印到檔案中

stacksampler 的dosample 就是把卡頓的資訊通過linkedhashmap列印出來

protected void dosample() 

synchronized (sstackmap)

sstackmap.put(system.currenttimemillis(), stringbuilder.tostring());

}}

azkaban web server原始碼解析

azkaban主要用於hadoop相關job任務的排程,但也可以應用任何需要排程管理的任務,可以完全代替crontab。azkaban主要分為web server 任務上傳,管理,排程 executor server 接受web server的排程指令,進行任務執行 1.資料表 projects 工...

JDK LinkedHashMap原始碼解析

今天來分析一下jdk linkedhashmap的源 public class linkedhashmapextends hashmapimplements map可以看到,linkedhashmap繼承自hashmap,並且也實現了map介面,所以linkedhashmap沿用了hashmap的大...

Redux原始碼createStore解讀常用方法

const store createstore reducer,preloadedstate enhancer 直接返回當前currentstate,獲取state值,return state 我覺得應該深轉殖乙個新的物件返回,不然有可能會被外部修改 function getstate consol...