OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/memory_usage.h" |
| 6 |
| 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_LINUX) |
| 10 #include <malloc.h> |
| 11 #endif |
| 12 |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process_util.h" |
| 15 |
| 16 #if defined(OS_LINUX) |
| 17 #include "v8/include/v8.h" |
| 18 #endif |
| 19 |
| 20 namespace webkit_glue { |
| 21 |
| 22 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 23 size_t memoryUsageKB() { |
| 24 struct mallinfo minfo = mallinfo(); |
| 25 uint64_t mem_usage = |
| 26 #if defined(USE_TCMALLOC) |
| 27 minfo.uordblks |
| 28 #else |
| 29 (minfo.hblkhd + minfo.arena) |
| 30 #endif |
| 31 >> 10; |
| 32 |
| 33 v8::HeapStatistics stat; |
| 34 v8::V8::GetHeapStatistics(&stat); |
| 35 return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 10); |
| 36 } |
| 37 #elif defined(OS_MACOSX) |
| 38 size_t memoryUsageKB() { |
| 39 scoped_ptr<ProcessMetrics> process_metrics( |
| 40 // The default port provider is sufficient to get data for the current |
| 41 // process. |
| 42 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), |
| 43 NULL)); |
| 44 return process_metrics.GetWorkingSetSize() >> 10; |
| 45 } |
| 46 #else |
| 47 size_t memoryUsageKB() { |
| 48 scoped_ptr<ProcessMetrics> process_metrics( |
| 49 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle())); |
| 50 return process_metrics.GetPagefileUsage() >> 10; |
| 51 } |
| 52 #endif |
| 53 |
| 54 } // namespace webkit_glue |
OLD | NEW |