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

Side by Side Diff: Source/wtf/Partitions.cpp

Issue 1053793004: Add a UseCounter that measures the amount of memory used in PartitionAlloc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 15 matching lines...) Expand all
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 "wtf/Partitions.h" 32 #include "wtf/Partitions.h"
33 33
34 #include "wtf/DefaultAllocator.h" 34 #include "wtf/DefaultAllocator.h"
35 #include "wtf/FastMalloc.h" 35 #include "wtf/FastMalloc.h"
36 #include "wtf/MainThread.h"
36 37
37 namespace WTF { 38 namespace WTF {
38 39
39 bool Partitions::s_initialized; 40 bool Partitions::s_initialized;
40 41
41 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; 42 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator;
42 PartitionAllocatorGeneric Partitions::m_bufferAllocator; 43 PartitionAllocatorGeneric Partitions::m_bufferAllocator;
43 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator; 44 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator;
44 SizeSpecificPartitionAllocator<1024> Partitions::m_renderingAllocator; 45 SizeSpecificPartitionAllocator<1024> Partitions::m_renderingAllocator;
46 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr;
45 47
46 void Partitions::initialize() 48 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration)
47 { 49 {
48 static int lock = 0; 50 static int lock = 0;
49 // Guard against two threads hitting here in parallel. 51 // Guard against two threads hitting here in parallel.
50 spinLockLock(&lock); 52 spinLockLock(&lock);
51 if (!s_initialized) { 53 if (!s_initialized) {
52 m_fastMallocAllocator.init(); 54 m_fastMallocAllocator.init(Partitions::notifyCommittedMemoryChanged);
53 m_bufferAllocator.init(); 55 m_bufferAllocator.init(Partitions::notifyCommittedMemoryChanged);
54 m_objectModelAllocator.init(); 56 m_objectModelAllocator.init(Partitions::notifyCommittedMemoryChanged);
55 m_renderingAllocator.init(); 57 m_renderingAllocator.init(Partitions::notifyCommittedMemoryChanged);
58 m_histogramEnumeration = histogramEnumeration;
56 s_initialized = true; 59 s_initialized = true;
57 } 60 }
58 spinLockUnlock(&lock); 61 spinLockUnlock(&lock);
59 } 62 }
60 63
61 void Partitions::shutdown() 64 void Partitions::shutdown()
62 { 65 {
63 // We could ASSERT here for a memory leak within the partition, but it leads 66 // We could ASSERT here for a memory leak within the partition, but it leads
64 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for 67 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for
65 // the valgrind and heapcheck bots, which run without partitions. 68 // the valgrind and heapcheck bots, which run without partitions.
66 (void) m_renderingAllocator.shutdown(); 69 (void) m_renderingAllocator.shutdown();
67 (void) m_objectModelAllocator.shutdown(); 70 (void) m_objectModelAllocator.shutdown();
68 (void) m_bufferAllocator.shutdown(); 71 (void) m_bufferAllocator.shutdown();
69 (void) m_fastMallocAllocator.shutdown(); 72 (void) m_fastMallocAllocator.shutdown();
70 } 73 }
71 74
75 void Partitions::notifyCommittedMemoryChanged()
76 {
77 static size_t supportedMaxSizeInMB = 4 * 1024;
78 static size_t observedMaxSizeInMB = 0;
79
80 if (!m_histogramEnumeration)
81 return;
82 // We only report the memory in the main thread.
83 if (!isMainThread())
84 return;
85 // +1 is for rounding up the sizeInMB.
86 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1;
87 if (sizeInMB >= supportedMaxSizeInMB)
88 sizeInMB = supportedMaxSizeInMB - 1;
89 if (sizeInMB > observedMaxSizeInMB) {
90 // Send a UseCounter only when we see the highest memory usage
91 // we've ever seen.
92 m_histogramEnumeration("PartitionAlloc.CommittedSize", sizeInMB, support edMaxSizeInMB);
Chris Evans 2015/04/06 04:39:53 Hmm! Can we be sure that this histogram enumeratio
haraken 2015/04/06 06:14:14 It can potentially be re-entered, but is it really
93 observedMaxSizeInMB = sizeInMB;
94 }
95 }
96
72 } // namespace WTF 97 } // namespace WTF
OLDNEW
« Source/wtf/PartitionAlloc.cpp ('K') | « Source/wtf/Partitions.h ('k') | Source/wtf/WTF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698