Webkit statistics of Android

Introduction

1.Statistics Macro

 "ANDROID_INSTRUMENT"

2.Classes for statistics

a.TimeCounter
b.TimeCounterAuto

3. method for statistics
a. counting the time used for a single function.
b. counting the total time used by a kind of Timer.


TimerCounter
1.TimerCounter type.
One counter type stands for one type of operation.
    "css parsing", 
    "javascript",
    "javascript init",
    "javascript parsing",
    "javascript execution",
    "calculate style", 
    "Java callback (frame bridge)",
    "parsing (may include calcStyle, Java callback or inline script execution)",
    "layout", 
    "native 1 (frame bridge)",
    "native 2 (resource load)", 
    "native 3 (shared timer)", 
    "build nav (webview core)",
    "record content (webview core)",
    "native 4 (webview core)",
    "draw content (webview ui)",
    enum Type {
        // function base counters
        CSSParseTimeCounter,
        JavaScriptTimeCounter,
        JavaScriptInitTimeCounter,
        JavaScriptParseTimeCounter,
        JavaScriptExecuteTimeCounter,
        CalculateStyleTimeCounter,
        JavaCallbackTimeCounter,
        ParsingTimeCounter,
        LayoutTimeCounter,
        // file base counters
        NativeCallbackTimeCounter,  // WebCoreFrameBridge.cpp
        ResourceTimeCounter,        // WebCoreResourceLoader.cpp
        SharedTimerTimeCounter,     // JavaBridge.cpp
        WebViewCoreBuildNavTimeCounter,
        WebViewCoreRecordTimeCounter,
        WebViewCoreTimeCounter,     // WebViewCore.cpp
        WebViewUIDrawTimeCounter,
        TotalTimeCounterCount
    };

2.Array for holding the variables
uint32_t TimeCounter::sTotalTimeUsed[TimeCounter::TotalTimeCounterCount];
//the total time used for the kind of operation.
uint32_t TimeCounter::sLastTimeUsed[TimeCounter::TotalTimeCounterCount];
uint32_t TimeCounter::sCounter[TimeCounter::TotalTimeCounterCount];
//the total times of the kind of operation.
uint32_t TimeCounter::sLastCounter[TimeCounter::TotalTimeCounterCount];
uint32_t TimeCounter::sStartTime[TimeCounter::TotalTimeCounterCount];

3.function of the TimerCounter
a.void TimeCounter::start(enum Type type)
record the current time and store it in the "sStartTime" array.
b.void TimeCounter::record(enum Type type, const char* functionName)
calculate the elapsed time after start, and print it if the elapsed time is more than 1000ms
c.void TimeCounter::report(const KURL& url, int live, int dead, size_t arenaSize)
out put all the result of the statistics.
d.void TimeCounter::reportNow()
compare the current with the last.

4.usage
a.TimeCounter::start() at the start of the function
b.TimeCounter::record() at the end of the function.




TimeCounterAuto
1.variable
it has a membership "uint32_t m_startTime", as it was created, the current time is stored in the variable.
2.function 
a.TimeCounterAuto()
constructure function, store the current time in the "m_startTime".
b.~TimeCounterAuto()
get the elapsed time with the current time and "m_startTime" and record it the 
"sTotalTimeUsed" and "sCounter" as "TimeCounter" does.
3.usage
a.construct a local object of "TimeCounterAuto" at the beginning of the function.
b.the destructure function will be called automaticlly.

posted @ 2012-05-30 23:52  cascais  阅读(291)  评论(3编辑  收藏  举报