Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "core/timing/Performance.h" | 32 #include "core/timing/Performance.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptValue.h" | 34 #include "bindings/core/v8/ScriptValue.h" |
| 35 #include "bindings/core/v8/V8ObjectBuilder.h" | 35 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 38 #include "core/inspector/InspectedFrames.h" | |
| 39 #include "core/inspector/InspectorWebPerfAgent.h" | 38 #include "core/inspector/InspectorWebPerfAgent.h" |
| 40 #include "core/loader/DocumentLoader.h" | 39 #include "core/loader/DocumentLoader.h" |
| 41 #include "core/origin_trials/OriginTrials.h" | 40 #include "core/origin_trials/OriginTrials.h" |
| 42 #include "core/timing/PerformanceTiming.h" | 41 #include "core/timing/PerformanceTiming.h" |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 static double toTimeOrigin(LocalFrame* frame) { | 45 static double toTimeOrigin(LocalFrame* frame) { |
| 47 if (!frame) | 46 if (!frame) |
| 48 return 0.0; | 47 return 0.0; |
| 49 | 48 |
| 50 Document* document = frame->document(); | 49 Document* document = frame->document(); |
| 51 if (!document) | 50 if (!document) |
| 52 return 0.0; | 51 return 0.0; |
| 53 | 52 |
| 54 DocumentLoader* loader = document->loader(); | 53 DocumentLoader* loader = document->loader(); |
| 55 if (!loader) | 54 if (!loader) |
| 56 return 0.0; | 55 return 0.0; |
| 57 | 56 |
| 58 return loader->timing().referenceMonotonicTime(); | 57 return loader->timing().referenceMonotonicTime(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 Performance::Performance(LocalFrame* frame) | 60 Performance::Performance(LocalFrame* frame) |
| 62 : PerformanceBase(toTimeOrigin(frame)), DOMWindowProperty(frame) {} | 61 : PerformanceBase(toTimeOrigin(frame)), |
| 62 DOMWindowProperty(frame), | |
| 63 m_observingLongTasks(false) {} | |
| 63 | 64 |
| 64 Performance::~Performance() {} | 65 Performance::~Performance() { |
| 66 LocalFrame* localRoot = frame()->localFrameRoot(); | |
|
krasin1
2016/11/02 20:06:14
For the record, this broke UBSan bots:
https://bui
panickercorp
2016/11/02 20:17:47
Apologies!
Should that have run on presubmit?
I'l
| |
| 67 if (m_observingLongTasks && localRoot) { | |
| 68 m_observingLongTasks = false; | |
| 69 localRoot->disableInspectorWebPerfAgent(this); | |
| 70 } | |
| 71 } | |
| 65 | 72 |
| 66 ExecutionContext* Performance::getExecutionContext() const { | 73 ExecutionContext* Performance::getExecutionContext() const { |
| 67 if (!frame()) | 74 if (!frame()) |
| 68 return nullptr; | 75 return nullptr; |
| 69 return frame()->document(); | 76 return frame()->document(); |
| 70 } | 77 } |
| 71 | 78 |
| 72 MemoryInfo* Performance::memory() { | 79 MemoryInfo* Performance::memory() { |
| 73 return MemoryInfo::create(); | 80 return MemoryInfo::create(); |
| 74 } | 81 } |
| 75 | 82 |
| 76 PerformanceNavigation* Performance::navigation() const { | 83 PerformanceNavigation* Performance::navigation() const { |
| 77 if (!m_navigation) | 84 if (!m_navigation) |
| 78 m_navigation = PerformanceNavigation::create(frame()); | 85 m_navigation = PerformanceNavigation::create(frame()); |
| 79 | 86 |
| 80 return m_navigation.get(); | 87 return m_navigation.get(); |
| 81 } | 88 } |
| 82 | 89 |
| 83 PerformanceTiming* Performance::timing() const { | 90 PerformanceTiming* Performance::timing() const { |
| 84 if (!m_timing) | 91 if (!m_timing) |
| 85 m_timing = PerformanceTiming::create(frame()); | 92 m_timing = PerformanceTiming::create(frame()); |
| 86 | 93 |
| 87 return m_timing.get(); | 94 return m_timing.get(); |
| 88 } | 95 } |
| 89 | 96 |
| 90 void Performance::updateLongTaskInstrumentation() { | 97 void Performance::updateLongTaskInstrumentation() { |
| 91 if (hasObserverFor(PerformanceEntry::LongTask) && !m_longTaskInspectorAgent) { | 98 DCHECK(frame()); |
| 92 if (!frame() || !frame()->document() || | 99 if (!frame()->document() || |
| 93 !OriginTrials::longTaskObserverEnabled(frame()->document())) | 100 !OriginTrials::longTaskObserverEnabled(frame()->document())) |
| 94 return; | 101 return; |
| 95 m_longTaskInspectorAgent = new InspectorWebPerfAgent(frame()); | 102 LocalFrame* localRoot = frame()->localFrameRoot(); |
| 96 m_longTaskInspectorAgent->enable(); | 103 DCHECK(localRoot); |
| 97 } else if (!hasObserverFor(PerformanceEntry::LongTask) && | 104 |
| 98 m_longTaskInspectorAgent) { | 105 if (!m_observingLongTasks && hasObserverFor(PerformanceEntry::LongTask)) { |
| 99 m_longTaskInspectorAgent->disable(); | 106 m_observingLongTasks = true; |
| 100 m_longTaskInspectorAgent = nullptr; | 107 localRoot->enableInspectorWebPerfAgent(this); |
| 108 } else if (m_observingLongTasks && | |
| 109 !hasObserverFor(PerformanceEntry::LongTask)) { | |
| 110 m_observingLongTasks = false; | |
| 111 localRoot->disableInspectorWebPerfAgent(this); | |
| 101 } | 112 } |
| 102 } | 113 } |
| 103 | 114 |
| 104 ScriptValue Performance::toJSONForBinding(ScriptState* scriptState) const { | 115 ScriptValue Performance::toJSONForBinding(ScriptState* scriptState) const { |
| 105 V8ObjectBuilder result(scriptState); | 116 V8ObjectBuilder result(scriptState); |
| 106 result.add("timing", timing()->toJSONForBinding(scriptState)); | 117 result.add("timing", timing()->toJSONForBinding(scriptState)); |
| 107 result.add("navigation", navigation()->toJSONForBinding(scriptState)); | 118 result.add("navigation", navigation()->toJSONForBinding(scriptState)); |
| 108 return result.scriptValue(); | 119 return result.scriptValue(); |
| 109 } | 120 } |
| 110 | 121 |
| 122 bool Performance::observingLongTasks() { | |
| 123 return m_observingLongTasks; | |
| 124 } | |
| 125 | |
| 111 DEFINE_TRACE(Performance) { | 126 DEFINE_TRACE(Performance) { |
| 112 visitor->trace(m_navigation); | 127 visitor->trace(m_navigation); |
| 113 visitor->trace(m_timing); | 128 visitor->trace(m_timing); |
| 114 visitor->trace(m_longTaskInspectorAgent); | |
| 115 DOMWindowProperty::trace(visitor); | 129 DOMWindowProperty::trace(visitor); |
| 116 PerformanceBase::trace(visitor); | 130 PerformanceBase::trace(visitor); |
| 117 } | 131 } |
| 118 | 132 |
| 119 } // namespace blink | 133 } // namespace blink |
| OLD | NEW |