OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, 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 25 matching lines...) Expand all Loading... | |
36 #include "V8Node.h" | 36 #include "V8Node.h" |
37 #include "bindings/v8/RetainedDOMInfo.h" | 37 #include "bindings/v8/RetainedDOMInfo.h" |
38 #include "bindings/v8/ScriptObject.h" | 38 #include "bindings/v8/ScriptObject.h" |
39 #include "bindings/v8/V8Binding.h" | 39 #include "bindings/v8/V8Binding.h" |
40 #include "bindings/v8/V8DOMWrapper.h" | 40 #include "bindings/v8/V8DOMWrapper.h" |
41 #include "bindings/v8/WrapperTypeInfo.h" | 41 #include "bindings/v8/WrapperTypeInfo.h" |
42 #include "core/dom/WebCoreMemoryInstrumentation.h" | 42 #include "core/dom/WebCoreMemoryInstrumentation.h" |
43 #include "core/inspector/BindingVisitors.h" | 43 #include "core/inspector/BindingVisitors.h" |
44 | 44 |
45 #include <v8-profiler.h> | 45 #include <v8-profiler.h> |
46 #include <v8.h> | |
46 | 47 |
47 #include "wtf/ThreadSpecific.h" | 48 #include "wtf/ThreadSpecific.h" |
48 | 49 |
49 namespace WebCore { | 50 namespace WebCore { |
50 | 51 |
51 typedef HashMap<String, double> ProfileNameIdleTimeMap; | 52 typedef HashMap<String, double> ProfileNameIdleTimeMap; |
52 | 53 |
53 void ScriptProfiler::start(ScriptState* state, const String& title) | 54 void ScriptProfiler::start(ScriptState* state, const String& title) |
54 { | 55 { |
55 ProfileNameIdleTimeMap* profileNameIdleTimeMap = ScriptProfiler::currentProf ileNameIdleTimeMap(); | 56 ProfileNameIdleTimeMap* profileNameIdleTimeMap = ScriptProfiler::currentProf ileNameIdleTimeMap(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } | 193 } |
193 return 0; | 194 return 0; |
194 } | 195 } |
195 | 196 |
196 private: | 197 private: |
197 Vector<CString> m_strings; | 198 Vector<CString> m_strings; |
198 }; | 199 }; |
199 | 200 |
200 } // namespace | 201 } // namespace |
201 | 202 |
203 void ScriptProfiler::startTrackingHeapObjects() | |
204 { | |
205 v8::Isolate::GetCurrent()->GetHeapProfiler()->StartTrackingHeapObjects(); | |
206 } | |
207 | |
208 namespace { | |
209 | |
210 class HeapStatsStream : public v8::OutputStream { | |
211 public: | |
212 HeapStatsStream(ScriptProfiler::OutputStream* stream) : m_stream(stream) { } | |
213 virtual void EndOfStream() OVERRIDE { } | |
214 | |
215 virtual WriteResult WriteAsciiChunk(char* data, int size) OVERRIDE | |
216 { | |
217 ASSERT(false); | |
218 return kAbort; | |
219 } | |
220 | |
221 virtual WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count) OVERRIDE | |
222 { | |
223 Vector<uint32_t> rawData(count * 3); | |
224 for (int i = 0; i < count; ++i) { | |
225 int offset = i * 3; | |
226 rawData[offset] = updateData[i].index; | |
227 rawData[offset + 1] = updateData[i].count; | |
228 rawData[offset + 2] = updateData[i].size; | |
229 } | |
230 m_stream->write(rawData.data(), count * 3); | |
yurys
2013/04/25 12:23:15
count * 3 -> rawData.size()
loislo
2013/04/25 13:33:56
Done.
| |
231 return kContinue; | |
232 } | |
233 | |
234 private: | |
235 ScriptProfiler::OutputStream* m_stream; | |
236 }; | |
237 | |
238 } | |
239 | |
240 unsigned ScriptProfiler::requestHeapStatsUpdate(ScriptProfiler::OutputStream* st ream) | |
241 { | |
242 HeapStatsStream heapStatsStream(stream); | |
243 return v8::Isolate::GetCurrent()->GetHeapProfiler()->GetHeapStats(&heapStats Stream); | |
244 } | |
245 | |
246 void ScriptProfiler::stopTrackingHeapObjects() | |
247 { | |
248 v8::Isolate::GetCurrent()->GetHeapProfiler()->StopTrackingHeapObjects(); | |
249 } | |
250 | |
202 // FIXME: This method should receive a ScriptState, from which we should retriev e an Isolate. | 251 // FIXME: This method should receive a ScriptState, from which we should retriev e an Isolate. |
203 PassRefPtr<ScriptHeapSnapshot> ScriptProfiler::takeHeapSnapshot(const String& ti tle, HeapSnapshotProgress* control) | 252 PassRefPtr<ScriptHeapSnapshot> ScriptProfiler::takeHeapSnapshot(const String& ti tle, HeapSnapshotProgress* control) |
204 { | 253 { |
205 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 254 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
206 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 255 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
207 if (!profiler) | 256 if (!profiler) |
208 return 0; | 257 return 0; |
209 v8::HandleScope handleScope(isolate); | 258 v8::HandleScope handleScope(isolate); |
210 ASSERT(control); | 259 ASSERT(control); |
211 ActivityControlAdapter adapter(control); | 260 ActivityControlAdapter adapter(control); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 362 } |
314 | 363 |
315 ProfileNameIdleTimeMap* ScriptProfiler::currentProfileNameIdleTimeMap() | 364 ProfileNameIdleTimeMap* ScriptProfiler::currentProfileNameIdleTimeMap() |
316 { | 365 { |
317 AtomicallyInitializedStatic(WTF::ThreadSpecific<ProfileNameIdleTimeMap>*, ma p = new WTF::ThreadSpecific<ProfileNameIdleTimeMap>); | 366 AtomicallyInitializedStatic(WTF::ThreadSpecific<ProfileNameIdleTimeMap>*, ma p = new WTF::ThreadSpecific<ProfileNameIdleTimeMap>); |
318 return *map; | 367 return *map; |
319 } | 368 } |
320 | 369 |
321 } // namespace WebCore | 370 } // namespace WebCore |
322 | 371 |
OLD | NEW |