aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-18 07:24:14 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-18 07:24:14 -0800
commitf27f1bcce50c8f95aea8469684a70b70c9baee09 (patch)
treeceaedeb444f73bbddc13d09cc783bec800d54444 /src
parent9b1dd15d6d90bf623679f4e9b81b29fe9ab82807 (diff)
SkVarAlloc::approxBytesAllocated()
This is what I was getting at on the other CL. BUG=skia: Review URL: https://codereview.chromium.org/730193003
Diffstat (limited to 'src')
-rw-r--r--src/core/SkVarAlloc.cpp27
-rw-r--r--src/core/SkVarAlloc.h4
2 files changed, 28 insertions, 3 deletions
diff --git a/src/core/SkVarAlloc.cpp b/src/core/SkVarAlloc.cpp
index 6f5b5a18d3..8f84b95743 100644
--- a/src/core/SkVarAlloc.cpp
+++ b/src/core/SkVarAlloc.cpp
@@ -3,7 +3,7 @@
// We use non-standard malloc diagnostic methods to make sure our allocations are sized well.
#if defined(SK_BUILD_FOR_MAC)
#include <malloc/malloc.h>
-#elif defined(SK_BUILD_FOR_LINUX)
+#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32)
#include <malloc.h>
#endif
@@ -56,7 +56,28 @@ void SkVarAlloc::makeSpace(size_t bytes, unsigned flags) {
#if defined(SK_BUILD_FOR_MAC)
SkASSERT(alloc == malloc_good_size(alloc));
-#elif defined(SK_BUILD_FOR_LINUX)
- SkASSERT(alloc == malloc_usable_size(fByte - sizeof(Block)));
+#elif defined(SK_BUILD_FOR_UNIX)
+ // TODO(mtklein): tune so we can assert something like this
+ //SkASSERT(alloc == malloc_usable_size(fBlock));
#endif
}
+
+static size_t heap_size(void* p) {
+#if defined(SK_BUILD_FOR_MAC)
+ return malloc_size(p);
+#elif defined(SK_BUILD_FOR_UNIX)
+ return malloc_usable_size(p);
+#elif defined(SK_BUILD_FOR_WIN32)
+ return _msize(p);
+#else
+ return 0; // Tough luck.
+#endif
+}
+
+size_t SkVarAlloc::approxBytesAllocated() const {
+ size_t sum = 0;
+ for (Block* b = fBlock; b; b = b->prev) {
+ sum += heap_size(b);
+ }
+ return sum;
+}
diff --git a/src/core/SkVarAlloc.h b/src/core/SkVarAlloc.h
index 2b5401b7f0..9eac658828 100644
--- a/src/core/SkVarAlloc.h
+++ b/src/core/SkVarAlloc.h
@@ -23,6 +23,10 @@ public:
return ptr;
}
+ // Returns our best estimate of the number of bytes we've allocated.
+ // (We intentionally do not track this precisely to save space.)
+ size_t approxBytesAllocated() const;
+
private:
void makeSpace(size_t bytes, unsigned flags);