| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/timing/MemoryInfo.h" | 32 #include "core/timing/MemoryInfo.h" |
| 33 | 33 |
| 34 #include <limits> | 34 #include <limits> |
| 35 #include "core/dom/Document.h" |
| 35 #include "core/frame/Frame.h" | 36 #include "core/frame/Frame.h" |
| 36 #include "core/frame/Settings.h" | 37 #include "core/frame/Settings.h" |
| 38 #include "core/workers/WorkerGlobalScope.h" |
| 37 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
| 38 #include "wtf/MainThread.h" | 40 #include "wtf/MainThread.h" |
| 39 #include "wtf/MathExtras.h" | 41 #include "wtf/MathExtras.h" |
| 40 | 42 |
| 41 namespace WebCore { | 43 namespace WebCore { |
| 42 | 44 |
| 43 | 45 |
| 44 class HeapSizeCache { | 46 class HeapSizeCache { |
| 45 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED; | 47 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED; |
| 46 public: | 48 public: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 127 |
| 126 for (int i = 0; i < numberOfBuckets; ++i) { | 128 for (int i = 0; i < numberOfBuckets; ++i) { |
| 127 if (size <= bucketSizeList[i]) | 129 if (size <= bucketSizeList[i]) |
| 128 return bucketSizeList[i]; | 130 return bucketSizeList[i]; |
| 129 } | 131 } |
| 130 | 132 |
| 131 return bucketSizeList[numberOfBuckets - 1]; | 133 return bucketSizeList[numberOfBuckets - 1]; |
| 132 } | 134 } |
| 133 | 135 |
| 134 | 136 |
| 135 MemoryInfo::MemoryInfo(Frame* frame) | 137 MemoryInfo::MemoryInfo(ExecutionContext* context) |
| 136 { | 138 { |
| 137 ScriptWrappable::init(this); | 139 ScriptWrappable::init(this); |
| 138 if (!frame || !frame->settings()) | 140 |
| 141 if (!context) |
| 139 return; | 142 return; |
| 140 | 143 |
| 141 if (frame->settings()->memoryInfoEnabled()) { | 144 if (context->isDocument()) { |
| 145 Frame* frame = toDocument(context)->frame(); |
| 146 if (!frame || !frame->settings()) |
| 147 return; |
| 148 loadMemoryInfo(frame->settings()->memoryInfoEnabled()); |
| 149 } |
| 150 |
| 151 if (context->isWorkerGlobalScope()) { |
| 152 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
| 153 if (!workerGlobalScope) |
| 154 return; |
| 155 loadMemoryInfo(workerGlobalScope->memoryInfoEnabled()); |
| 156 } |
| 157 } |
| 158 |
| 159 void MemoryInfo::loadMemoryInfo(bool memoryInfoEnabled) |
| 160 { |
| 161 if (memoryInfoEnabled) { |
| 142 ScriptGCEvent::getHeapSize(m_info); | 162 ScriptGCEvent::getHeapSize(m_info); |
| 143 } else { | 163 } else { |
| 144 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ()); | 164 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ()); |
| 145 heapSizeCache.getCachedHeapSize(m_info); | 165 heapSizeCache.getCachedHeapSize(m_info); |
| 146 } | 166 } |
| 147 } | 167 } |
| 148 | 168 |
| 149 } // namespace WebCore | 169 } // namespace WebCore |
| OLD | NEW |