| 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 20 matching lines...) Expand all Loading... |
| 31 #include "sky/engine/config.h" | 31 #include "sky/engine/config.h" |
| 32 #include "sky/engine/bindings/core/v8/ScriptProfiler.h" | 32 #include "sky/engine/bindings/core/v8/ScriptProfiler.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/V8Node.h" | 34 #include "bindings/core/v8/V8Node.h" |
| 35 #include "bindings/core/v8/V8Window.h" | 35 #include "bindings/core/v8/V8Window.h" |
| 36 #include "sky/engine/bindings/core/v8/RetainedDOMInfo.h" | 36 #include "sky/engine/bindings/core/v8/RetainedDOMInfo.h" |
| 37 #include "sky/engine/bindings/core/v8/ScriptValue.h" | 37 #include "sky/engine/bindings/core/v8/ScriptValue.h" |
| 38 #include "sky/engine/bindings/core/v8/V8Binding.h" | 38 #include "sky/engine/bindings/core/v8/V8Binding.h" |
| 39 #include "sky/engine/bindings/core/v8/WrapperTypeInfo.h" | 39 #include "sky/engine/bindings/core/v8/WrapperTypeInfo.h" |
| 40 #include "sky/engine/core/dom/Document.h" | 40 #include "sky/engine/core/dom/Document.h" |
| 41 #include "sky/engine/core/inspector/BindingVisitors.h" | |
| 42 #include "sky/engine/wtf/ThreadSpecific.h" | 41 #include "sky/engine/wtf/ThreadSpecific.h" |
| 43 #include "v8/include/v8-profiler.h" | 42 #include "v8/include/v8-profiler.h" |
| 44 #include "v8/include/v8.h" | 43 #include "v8/include/v8.h" |
| 45 | 44 |
| 46 namespace blink { | 45 namespace blink { |
| 47 | 46 |
| 48 typedef HashMap<String, double> ProfileNameIdleTimeMap; | 47 typedef HashMap<String, double> ProfileNameIdleTimeMap; |
| 49 | 48 |
| 50 void ScriptProfiler::setSamplingInterval(int intervalUs) | 49 void ScriptProfiler::setSamplingInterval(int intervalUs) |
| 51 { | 50 { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 250 } |
| 252 | 251 |
| 253 void ScriptProfiler::initialize() | 252 void ScriptProfiler::initialize() |
| 254 { | 253 { |
| 255 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 254 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 256 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 255 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
| 257 if (profiler) | 256 if (profiler) |
| 258 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &ret
ainedDOMInfo); | 257 profiler->SetWrapperClassInfoProvider(WrapperTypeInfo::NodeClassId, &ret
ainedDOMInfo); |
| 259 } | 258 } |
| 260 | 259 |
| 261 void ScriptProfiler::visitNodeWrappers(WrappedNodeVisitor* visitor) | |
| 262 { | |
| 263 // visitNodeWrappers() should receive a ScriptState and retrieve an Isolate | |
| 264 // from the ScriptState. | |
| 265 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 266 v8::HandleScope handleScope(isolate); | |
| 267 | |
| 268 class DOMNodeWrapperVisitor : public v8::PersistentHandleVisitor { | |
| 269 public: | |
| 270 DOMNodeWrapperVisitor(WrappedNodeVisitor* visitor, v8::Isolate* isolate) | |
| 271 : m_visitor(visitor) | |
| 272 , m_isolate(isolate) | |
| 273 { | |
| 274 } | |
| 275 | |
| 276 virtual void VisitPersistentHandle(v8::Persistent<v8::Value>* value, uin
t16_t classId) override | |
| 277 { | |
| 278 if (classId != WrapperTypeInfo::NodeClassId) | |
| 279 return; | |
| 280 // Casting to Handle is safe here, since the Persistent cannot get | |
| 281 // GCd during visiting. | |
| 282 v8::Handle<v8::Object>* wrapper = reinterpret_cast<v8::Handle<v8::Ob
ject>*>(value); | |
| 283 ASSERT_UNUSED(m_isolate, V8Node::hasInstance(*wrapper, m_isolate)); | |
| 284 ASSERT((*wrapper)->IsObject()); | |
| 285 m_visitor->visitNode(V8Node::toNative(*wrapper)); | |
| 286 } | |
| 287 | |
| 288 private: | |
| 289 WrappedNodeVisitor* m_visitor; | |
| 290 v8::Isolate* m_isolate; | |
| 291 } wrapperVisitor(visitor, isolate); | |
| 292 | |
| 293 v8::V8::VisitHandlesWithClassIds(&wrapperVisitor); | |
| 294 } | |
| 295 | |
| 296 ProfileNameIdleTimeMap* ScriptProfiler::currentProfileNameIdleTimeMap() | 260 ProfileNameIdleTimeMap* ScriptProfiler::currentProfileNameIdleTimeMap() |
| 297 { | 261 { |
| 298 AtomicallyInitializedStatic(WTF::ThreadSpecific<ProfileNameIdleTimeMap>*, ma
p = new WTF::ThreadSpecific<ProfileNameIdleTimeMap>); | 262 AtomicallyInitializedStatic(WTF::ThreadSpecific<ProfileNameIdleTimeMap>*, ma
p = new WTF::ThreadSpecific<ProfileNameIdleTimeMap>); |
| 299 return *map; | 263 return *map; |
| 300 } | 264 } |
| 301 | 265 |
| 302 void ScriptProfiler::setIdle(bool isIdle) | 266 void ScriptProfiler::setIdle(bool isIdle) |
| 303 { | 267 { |
| 304 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 268 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 305 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) | 269 if (v8::CpuProfiler* profiler = isolate->GetCpuProfiler()) |
| 306 profiler->SetIdle(isIdle); | 270 profiler->SetIdle(isIdle); |
| 307 } | 271 } |
| 308 | 272 |
| 309 } // namespace blink | 273 } // namespace blink |
| OLD | NEW |