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

Side by Side Diff: src/core/SkVarAlloc.cpp

Issue 730193003: SkVarAlloc::approxBytesAllocated (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Skip Android instead. Created 6 years, 1 month 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
« no previous file with comments | « src/core/SkVarAlloc.h ('k') | tests/VarAllocTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "SkVarAlloc.h" 1 #include "SkVarAlloc.h"
2 2
3 // We use non-standard malloc diagnostic methods to make sure our allocations ar e sized well. 3 // We use non-standard malloc diagnostic methods to make sure our allocations ar e sized well.
4 #if defined(SK_BUILD_FOR_MAC) 4 #if defined(SK_BUILD_FOR_MAC)
5 #include <malloc/malloc.h> 5 #include <malloc/malloc.h>
6 #elif defined(SK_BUILD_FOR_LINUX) 6 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32)
7 #include <malloc.h> 7 #include <malloc.h>
8 #endif 8 #endif
9 9
10 enum { 10 enum {
11 kMinLgSize = 4, // The smallest block we'd ever want to allocate is 16B, 11 kMinLgSize = 4, // The smallest block we'd ever want to allocate is 16B,
12 kMaxLgSize = 16, // and we see no benefit allocating blocks larger than 64K . 12 kMaxLgSize = 16, // and we see no benefit allocating blocks larger than 64K .
13 }; 13 };
14 14
15 struct SkVarAlloc::Block { 15 struct SkVarAlloc::Block {
16 Block* prev; 16 Block* prev;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 fBlock = Block::Alloc(fBlock, alloc, flags); 49 fBlock = Block::Alloc(fBlock, alloc, flags);
50 fByte = fBlock->data(); 50 fByte = fBlock->data();
51 fRemaining = alloc - sizeof(Block); 51 fRemaining = alloc - sizeof(Block);
52 52
53 if (fLgSize < kMaxLgSize) { 53 if (fLgSize < kMaxLgSize) {
54 fLgSize++; 54 fLgSize++;
55 } 55 }
56 56
57 #if defined(SK_BUILD_FOR_MAC) 57 #if defined(SK_BUILD_FOR_MAC)
58 SkASSERT(alloc == malloc_good_size(alloc)); 58 SkASSERT(alloc == malloc_good_size(alloc));
59 #elif defined(SK_BUILD_FOR_LINUX) 59 #elif defined(SK_BUILD_FOR_UNIX)
60 SkASSERT(alloc == malloc_usable_size(fByte - sizeof(Block))); 60 // TODO(mtklein): tune so we can assert something like this
61 //SkASSERT(alloc == malloc_usable_size(fBlock));
61 #endif 62 #endif
62 } 63 }
64
65 static size_t heap_size(void* p) {
66 #if defined(SK_BUILD_FOR_MAC)
67 return malloc_size(p);
68 #elif defined(SK_BUILD_FOR_UNIX)
69 return malloc_usable_size(p);
70 #elif defined(SK_BUILD_FOR_WIN32)
71 return _msize(p);
72 #else
73 return 0; // Tough luck.
74 #endif
75 }
76
77 size_t SkVarAlloc::approxBytesAllocated() const {
78 size_t sum = 0;
79 for (Block* b = fBlock; b; b = b->prev) {
80 sum += heap_size(b);
81 }
82 return sum;
83 }
OLDNEW
« no previous file with comments | « src/core/SkVarAlloc.h ('k') | tests/VarAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698