OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef TraceEventDispatcher_h | 31 #ifndef TraceEventDispatcher_h |
32 #define TraceEventDispatcher_h | 32 #define TraceEventDispatcher_h |
33 | 33 |
34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
| 35 #include "platform/heap/Handle.h" |
35 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
36 #include "wtf/Threading.h" | 37 #include "wtf/Threading.h" |
37 #include "wtf/ThreadingPrimitives.h" | 38 #include "wtf/ThreadingPrimitives.h" |
38 #include "wtf/Vector.h" | 39 #include "wtf/Vector.h" |
| 40 #include "wtf/text/StringHash.h" |
39 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
40 | 42 |
41 namespace WebCore { | 43 namespace WebCore { |
42 | 44 |
43 class InspectorClient; | 45 class InspectorClient; |
44 | 46 |
45 struct TraceEventTargetBase { | |
46 virtual ~TraceEventTargetBase() { } | |
47 }; | |
48 | |
49 template<typename C> struct TraceEventTarget; | |
50 | |
51 class TraceEventDispatcher { | 47 class TraceEventDispatcher { |
52 WTF_MAKE_NONCOPYABLE(TraceEventDispatcher); | 48 WTF_MAKE_NONCOPYABLE(TraceEventDispatcher); |
53 public: | 49 public: |
54 class TraceEvent { | 50 class TraceEvent { |
55 public: | 51 public: |
56 TraceEvent() | 52 TraceEvent() |
57 : m_name(0) | 53 : m_name(0) |
58 , m_argumentCount(0) | 54 , m_argumentCount(0) |
59 { | 55 { |
60 } | 56 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 int m_argumentCount; | 129 int m_argumentCount; |
134 const char* m_argumentNames[MaxArguments]; | 130 const char* m_argumentNames[MaxArguments]; |
135 unsigned char m_argumentTypes[MaxArguments]; | 131 unsigned char m_argumentTypes[MaxArguments]; |
136 WebCore::TraceEvent::TraceValueUnion m_argumentValues[MaxArguments]; | 132 WebCore::TraceEvent::TraceValueUnion m_argumentValues[MaxArguments]; |
137 // These are only used as buffers for TRACE_VALUE_TYPE_COPY_STRING. | 133 // These are only used as buffers for TRACE_VALUE_TYPE_COPY_STRING. |
138 // Consider allocating the entire vector of buffered trace events and th
eir copied arguments out of a special arena | 134 // Consider allocating the entire vector of buffered trace events and th
eir copied arguments out of a special arena |
139 // to make things more compact. | 135 // to make things more compact. |
140 String m_stringArguments[MaxArguments]; | 136 String m_stringArguments[MaxArguments]; |
141 }; | 137 }; |
142 | 138 |
143 typedef void (TraceEventTargetBase::*TraceEventHandlerMethod)(const TraceEve
nt&); | 139 class TraceEventListener : public NoBaseWillBeGarbageCollected<TraceEventLis
tener> { |
| 140 public: |
| 141 #if !ENABLE(OILPAN) |
| 142 virtual ~TraceEventListener() { } |
| 143 #endif |
| 144 virtual void call(const TraceEventDispatcher::TraceEvent&) = 0; |
| 145 virtual void* target() = 0; |
| 146 virtual void trace(Visitor*) { } |
| 147 }; |
144 | 148 |
145 static TraceEventDispatcher* instance() | 149 static TraceEventDispatcher* instance() |
146 { | 150 { |
147 DEFINE_STATIC_LOCAL(TraceEventDispatcher, instance, ()); | 151 DEFINE_STATIC_LOCAL(TraceEventDispatcher, instance, ()); |
148 return &instance; | 152 return &instance; |
149 } | 153 } |
150 | 154 |
151 template<typename ListenerClass> | 155 void addListener(const char* name, char phase, PassOwnPtrWillBeRawPtr<TraceE
ventListener>, InspectorClient*); |
152 void addListener(const char* name, char phase, ListenerClass* instance, type
name TraceEventTarget<ListenerClass>::TraceEventHandler handler, InspectorClient
* client) | |
153 { | |
154 innerAddListener(name, phase, instance, static_cast<TraceEventHandlerMet
hod>(handler), client); | |
155 } | |
156 | 156 |
157 void removeAllListeners(TraceEventTargetBase*, InspectorClient*); | 157 void removeAllListeners(void*, InspectorClient*); |
158 void processBackgroundEvents(); | 158 void processBackgroundEvents(); |
159 | 159 |
160 private: | 160 private: |
161 struct BoundTraceEventHandler { | |
162 TraceEventTargetBase* instance; | |
163 TraceEventHandlerMethod method; | |
164 | |
165 BoundTraceEventHandler() : instance(0), method(0) { } | |
166 BoundTraceEventHandler(TraceEventTargetBase* instance, TraceEventHandler
Method method) | |
167 : instance(instance) | |
168 , method(method) | |
169 { | |
170 } | |
171 }; | |
172 typedef std::pair<String, int> EventSelector; | 161 typedef std::pair<String, int> EventSelector; |
173 typedef HashMap<EventSelector, Vector<BoundTraceEventHandler> > HandlersMap; | 162 typedef WillBeHeapHashMap<EventSelector, OwnPtrWillBeMember<WillBeHeapVector
<OwnPtrWillBeMember<TraceEventListener> > > > ListenersMap; |
174 | 163 |
175 TraceEventDispatcher() | 164 TraceEventDispatcher() |
176 : m_processEventsTaskInFlight(false) | 165 : m_listeners(adoptPtrWillBeNoop(new ListenersMap())) |
| 166 , m_processEventsTaskInFlight(false) |
177 , m_lastEventProcessingTime(0) | 167 , m_lastEventProcessingTime(0) |
178 { | 168 { |
179 } | 169 } |
180 | 170 |
181 static void dispatchEventOnAnyThread(char phase, const unsigned char*, const
char* name, unsigned long long id, | 171 static void dispatchEventOnAnyThread(char phase, const unsigned char*, const
char* name, unsigned long long id, |
182 int numArgs, const char* const* argNames, const unsigned char* argTypes,
const unsigned long long* argValues, | 172 int numArgs, const char* const* argNames, const unsigned char* argTypes,
const unsigned long long* argValues, |
183 unsigned char flags, double timestamp); | 173 unsigned char flags, double timestamp); |
184 | 174 |
185 void enqueueEvent(const TraceEvent&); | 175 void enqueueEvent(const TraceEvent&); |
186 void innerAddListener(const char* name, char phase, TraceEventTargetBase*, T
raceEventHandlerMethod, InspectorClient*); | |
187 void processBackgroundEventsTask(); | 176 void processBackgroundEventsTask(); |
188 | 177 |
189 Mutex m_mutex; | 178 Mutex m_mutex; |
190 HandlersMap m_handlers; | 179 OwnPtrWillBePersistent<ListenersMap> m_listeners; |
191 Vector<TraceEvent> m_backgroundEvents; | 180 Vector<TraceEvent> m_backgroundEvents; |
192 bool m_processEventsTaskInFlight; | 181 bool m_processEventsTaskInFlight; |
193 double m_lastEventProcessingTime; | 182 double m_lastEventProcessingTime; |
194 }; | 183 }; |
195 | 184 |
196 template<typename C> struct TraceEventTarget : public TraceEventTargetBase { | |
197 typedef void (C::*TraceEventHandler)(const TraceEventDispatcher::TraceEvent&
); | |
198 }; | |
199 | |
200 } // namespace WebCore | 185 } // namespace WebCore |
201 | 186 |
202 #endif // TraceEventDispatcher_h | 187 #endif // TraceEventDispatcher_h |
OLD | NEW |