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

Side by Side Diff: content/common/discardable_shared_memory_heap.h

Issue 1100073004: Adding discardable memory dump provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ 5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ 6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
7 7
8 #include <vector>
9
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
10 #include "base/containers/linked_list.h" 12 #include "base/containers/linked_list.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
13 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
14 16
15 namespace base { 17 namespace base {
16 class DiscardableSharedMemory; 18 class DiscardableSharedMemory;
17 } 19 }
(...skipping 19 matching lines...) Expand all
37 size_t start, 39 size_t start,
38 size_t length); 40 size_t length);
39 41
40 base::DiscardableSharedMemory* shared_memory_; 42 base::DiscardableSharedMemory* shared_memory_;
41 size_t start_; 43 size_t start_;
42 size_t length_; 44 size_t length_;
43 45
44 DISALLOW_COPY_AND_ASSIGN(Span); 46 DISALLOW_COPY_AND_ASSIGN(Span);
45 }; 47 };
46 48
49 class CONTENT_EXPORT MemoryStatistics {
Primiano Tucci (use gerrit) 2015/04/23 16:11:55 do you really need CONTENT_EXPORT here?
ssid 2015/04/24 11:23:04 No, removed.
50 public:
51 class SegmentStatistics {
Primiano Tucci (use gerrit) 2015/04/23 16:11:55 make this a struct and remove public:
ssid 2015/04/24 11:23:04 Changed.
52 public:
53 size_t size;
54 size_t num_of_objects;
55 size_t used_size;
56 };
57
58 MemoryStatistics();
59 ~MemoryStatistics();
60
61 size_t block_size;
62 size_t total_size;
63 size_t total_objects;
64 size_t total_used_size;
65 std::vector<SegmentStatistics> segments_stats;
66 };
67
47 explicit DiscardableSharedMemoryHeap(size_t block_size); 68 explicit DiscardableSharedMemoryHeap(size_t block_size);
48 ~DiscardableSharedMemoryHeap(); 69 ~DiscardableSharedMemoryHeap();
49 70
50 // Grow heap using |shared_memory| and return a span for this new memory. 71 // Grow heap using |shared_memory| and return a span for this new memory.
51 // |shared_memory| must be aligned to the block size and |size| must be a 72 // |shared_memory| must be aligned to the block size and |size| must be a
52 // multiple of the block size. |deleted_callback| is called when 73 // multiple of the block size. |deleted_callback| is called when
53 // |shared_memory| has been deleted. 74 // |shared_memory| has been deleted.
54 scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> shared_memory, 75 scoped_ptr<Span> Grow(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
55 size_t size, 76 size_t size,
56 const base::Closure& deleted_callback); 77 const base::Closure& deleted_callback);
(...skipping 19 matching lines...) Expand all
76 97
77 // Release shared memory segments that have been purged. 98 // Release shared memory segments that have been purged.
78 void ReleasePurgedMemory(); 99 void ReleasePurgedMemory();
79 100
80 // Returns total bytes of memory in heap. 101 // Returns total bytes of memory in heap.
81 size_t GetSize() const; 102 size_t GetSize() const;
82 103
83 // Returns bytes of memory currently in the free lists. 104 // Returns bytes of memory currently in the free lists.
84 size_t GetSizeOfFreeLists() const; 105 size_t GetSizeOfFreeLists() const;
85 106
107 // Fills statistics about memory used.
108 void GetMemoryStatistics(MemoryStatistics* statistics);
reveman 2015/04/23 17:32:30 Why don't we just add "void DumpInto(base::trace_e
ssid 2015/04/23 18:03:07 This sounds like a good idea, since later we would
109
86 private: 110 private:
87 class ScopedMemorySegment { 111 class ScopedMemorySegment {
88 public: 112 public:
89 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap, 113 ScopedMemorySegment(DiscardableSharedMemoryHeap* heap,
90 scoped_ptr<base::DiscardableSharedMemory> shared_memory, 114 scoped_ptr<base::DiscardableSharedMemory> shared_memory,
91 size_t size, 115 size_t size,
92 const base::Closure& deleted_callback); 116 const base::Closure& deleted_callback);
93 ~ScopedMemorySegment(); 117 ~ScopedMemorySegment();
94 118
95 bool IsUsed() const; 119 bool IsUsed() const;
96 bool IsResident() const; 120 bool IsResident() const;
97 121
122 void GetStatistics(MemoryStatistics::SegmentStatistics* segment_stats);
123
98 private: 124 private:
99 DiscardableSharedMemoryHeap* const heap_; 125 DiscardableSharedMemoryHeap* const heap_;
100 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; 126 scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
101 const size_t size_; 127 const size_t size_;
102 const base::Closure deleted_callback_; 128 const base::Closure deleted_callback_;
103 129
104 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment); 130 DISALLOW_COPY_AND_ASSIGN(ScopedMemorySegment);
105 }; 131 };
106 132
107 void InsertIntoFreeList(scoped_ptr<Span> span); 133 void InsertIntoFreeList(scoped_ptr<Span> span);
(...skipping 23 matching lines...) Expand all
131 // is a free list of runs that consist of k blocks. The 256th entry is a 157 // is a free list of runs that consist of k blocks. The 256th entry is a
132 // free list of runs that have length >= 256 blocks. 158 // free list of runs that have length >= 256 blocks.
133 base::LinkedList<Span> free_spans_[256]; 159 base::LinkedList<Span> free_spans_[256];
134 160
135 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); 161 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap);
136 }; 162 };
137 163
138 } // namespace content 164 } // namespace content
139 165
140 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ 166 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698