• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2009, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef TIME_COUNTER_H
27 #define TIME_COUNTER_H
28 
29 #ifdef ANDROID_INSTRUMENT
30 
31 #include "hardware_legacy/qemu_tracing.h"
32 #include <wtf/CurrentTime.h>
33 
34 namespace WebCore {
35 
36 class KURL;
37 
38 }
39 
40 namespace android {
41 
42 class TimeCounter {
43 public:
44     enum Type {
45         // function base counters
46         CSSParseTimeCounter,
47         JavaScriptTimeCounter,
48         JavaScriptInitTimeCounter,
49         JavaScriptParseTimeCounter,
50         JavaScriptExecuteTimeCounter,
51         CalculateStyleTimeCounter,
52         JavaCallbackTimeCounter,
53         ParsingTimeCounter,
54         LayoutTimeCounter,
55         // file base counters
56         NativeCallbackTimeCounter,  // WebCoreFrameBridge.cpp
57         ResourceTimeCounter,        // WebCoreResourceLoader.cpp
58         SharedTimerTimeCounter,     // JavaBridge.cpp
59         WebViewCoreBuildNavTimeCounter,
60         WebViewCoreRecordTimeCounter,
61         WebViewCoreTimeCounter,     // WebViewCore.cpp
62         WebViewUIDrawTimeCounter,
63         TotalTimeCounterCount
64     };
65 
66     static void record(enum Type type, const char* functionName);
67     static void recordNoCounter(enum Type type, const char* functionName);
68     static void report(const WebCore::KURL& , int live, int dead, size_t arenaSize);
69     static void reportNow();
70     static void reset();
71     static void start(enum Type type);
72 private:
73     static uint32_t sStartWebCoreThreadTime;
74     static uint32_t sEndWebCoreThreadTime;
75     static bool sRecordWebCoreTime;
76     static uint32_t sTotalTimeUsed[TotalTimeCounterCount];
77     static uint32_t sLastTimeUsed[TotalTimeCounterCount];
78     static uint32_t sCounter[TotalTimeCounterCount];
79     static uint32_t sLastCounter[TotalTimeCounterCount];
80     static uint32_t sStartTime[TotalTimeCounterCount];
81     friend class TimeCounterAuto;
82 };
83 
84 class TimeCounterAuto {
85 public:
TimeCounterAuto(TimeCounter::Type type)86     TimeCounterAuto(TimeCounter::Type type) :
87         m_type(type), m_startTime(WTF::get_thread_msec()) {}
~TimeCounterAuto()88     ~TimeCounterAuto() {
89         uint32_t time = WTF::get_thread_msec();
90         TimeCounter::sEndWebCoreThreadTime = time;
91         TimeCounter::sTotalTimeUsed[m_type] += time - m_startTime;
92         TimeCounter::sCounter[m_type]++;
93     }
94 private:
95     TimeCounter::Type m_type;
96     uint32_t m_startTime;
97 };
98 
99 class QemuTracerAuto {
100 public:
QemuTracerAuto()101     QemuTracerAuto() {
102         if (!reentry_count)
103             qemu_start_tracing();
104         reentry_count++;
105     }
106 
~QemuTracerAuto()107     ~QemuTracerAuto() {
108         reentry_count--;
109         if (!reentry_count)
110             qemu_stop_tracing();
111     }
112 private:
113     static int reentry_count;
114 };
115 
116 }
117 #endif
118 
119 #endif
120