Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(656)

Side by Side Diff: Source/core/timing/MemoryInfo.cpp

Issue 106353005: Expose performance.memory in workers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@Perf-Memory-SharedWorker
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 "core/dom/Document.h"
35 #include "core/frame/Frame.h" 35 #include "core/frame/Frame.h"
36 #include "core/frame/Settings.h" 36 #include "core/frame/Settings.h"
37 #include "core/workers/WorkerGlobalScope.h"
37 #include "wtf/CurrentTime.h" 38 #include "wtf/CurrentTime.h"
38 #include "wtf/MainThread.h" 39 #include "wtf/MainThread.h"
39 #include "wtf/MathExtras.h" 40 #include "wtf/MathExtras.h"
41 #include <limits>
40 42
41 namespace WebCore { 43 namespace WebCore {
42 44
43 DEFINE_GC_INFO(MemoryInfo); 45 DEFINE_GC_INFO(MemoryInfo);
44 46
45 class HeapSizeCache { 47 class HeapSizeCache {
46 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED; 48 WTF_MAKE_NONCOPYABLE(HeapSizeCache); WTF_MAKE_FAST_ALLOCATED;
47 public: 49 public:
48 HeapSizeCache() 50 HeapSizeCache()
49 : m_lastUpdateTime(0) 51 : m_lastUpdateTime(0)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 128
127 for (int i = 0; i < numberOfBuckets; ++i) { 129 for (int i = 0; i < numberOfBuckets; ++i) {
128 if (size <= bucketSizeList[i]) 130 if (size <= bucketSizeList[i])
129 return bucketSizeList[i]; 131 return bucketSizeList[i];
130 } 132 }
131 133
132 return bucketSizeList[numberOfBuckets - 1]; 134 return bucketSizeList[numberOfBuckets - 1];
133 } 135 }
134 136
135 137
136 MemoryInfo::MemoryInfo(Frame* frame) 138 MemoryInfo::MemoryInfo(ExecutionContext* context)
137 { 139 {
138 ScriptWrappable::init(this); 140 ScriptWrappable::init(this);
139 if (!frame || !frame->settings()) 141
142 if (!context)
140 return; 143 return;
141 144
142 if (frame->settings()->memoryInfoEnabled()) { 145 if (context->isDocument()) {
146 Frame* frame = toDocument(context)->frame();
147 if (!frame || !frame->settings())
148 return;
149 loadMemoryInfo(frame->settings()->memoryInfoEnabled());
150 }
151
152 if (context->isWorkerGlobalScope()) {
153 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
154 if (!workerGlobalScope)
155 return;
156 loadMemoryInfo(workerGlobalScope->settings()->memoryInfoEnabled());
157 }
158 }
159
160 void MemoryInfo::loadMemoryInfo(bool memoryInfoEnabled)
161 {
162 if (memoryInfoEnabled) {
143 ScriptGCEvent::getHeapSize(m_info); 163 ScriptGCEvent::getHeapSize(m_info);
144 } else { 164 } else {
145 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ()); 165 DEFINE_STATIC_LOCAL(HeapSizeCache, heapSizeCache, ());
146 heapSizeCache.getCachedHeapSize(m_info); 166 heapSizeCache.getCachedHeapSize(m_info);
147 } 167 }
148 } 168 }
149 169
150 } // namespace WebCore 170 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698