| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1802 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1803 base::TimeDelta::FromSeconds(15)); | 1803 base::TimeDelta::FromSeconds(15)); |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1806 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| 1807 // when it is possible to run memory-infra without tracing. | 1807 // when it is possible to run memory-infra without tracing. |
| 1808 #if defined(OS_WIN) | 1808 #if defined(OS_WIN) |
| 1809 namespace { | 1809 namespace { |
| 1810 | 1810 |
| 1811 static size_t GetMallocUsage() { | 1811 static size_t GetMallocUsage() { |
| 1812 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); | 1812 // Only checks the default process heap. |
| 1813 if (number_of_heaps <= 0) | 1813 HANDLE heap = ::GetProcessHeap(); |
| 1814 if (heap == NULL) |
| 1814 return 0; | 1815 return 0; |
| 1815 | 1816 if (!::HeapLock(heap)) |
| 1817 return 0 ; |
| 1816 size_t malloc_usage = 0; | 1818 size_t malloc_usage = 0; |
| 1817 std::unique_ptr<HANDLE[]> heaps(new HANDLE[number_of_heaps]); | 1819 PROCESS_HEAP_ENTRY heap_entry; |
| 1818 // If some heaps were gone between the first GetProcessHeaps and here, | 1820 heap_entry.lpData = NULL; |
| 1819 // GetProcessHeaps obtains small number of heaps. | 1821 while (::HeapWalk(heap, &heap_entry) != 0) { |
| 1820 // If some new heaps were available between the first GetProcessHeaps and | 1822 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) |
| 1821 // here, GetProcessHeaps returns larger number than number_of_heaps. | 1823 malloc_usage += heap_entry.cbData; |
| 1822 // So we need to see min(number_of_obtained_heaps, number_of_heaps). | |
| 1823 DWORD number_of_obtained_heaps = | |
| 1824 ::GetProcessHeaps(number_of_heaps, heaps.get()); | |
| 1825 for (size_t i = 0; i < number_of_heaps && i < number_of_obtained_heaps; i++) { | |
| 1826 PROCESS_HEAP_ENTRY heap_entry; | |
| 1827 ::HeapLock(heaps[i]); | |
| 1828 heap_entry.lpData = NULL; | |
| 1829 while (::HeapWalk(heaps[i], &heap_entry) != 0) { | |
| 1830 if (heap_entry.lpData == heaps.get()) | |
| 1831 continue; | |
| 1832 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) | |
| 1833 malloc_usage += heap_entry.cbData; | |
| 1834 } | |
| 1835 ::HeapUnlock(heaps[i]); | |
| 1836 } | 1824 } |
| 1825 ::HeapUnlock(heap); |
| 1837 return malloc_usage; | 1826 return malloc_usage; |
| 1838 } | 1827 } |
| 1839 | 1828 |
| 1840 } // namespace | 1829 } // namespace |
| 1841 #elif defined(OS_MACOSX) || defined(OS_IOS) | 1830 #elif defined(OS_MACOSX) || defined(OS_IOS) |
| 1842 namespace { | 1831 namespace { |
| 1843 | 1832 |
| 1844 static size_t GetMallocUsage() { | 1833 static size_t GetMallocUsage() { |
| 1845 malloc_statistics_t stats = {0}; | 1834 malloc_statistics_t stats = {0}; |
| 1846 malloc_zone_statistics(nullptr, &stats); | 1835 malloc_zone_statistics(nullptr, &stats); |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 } | 2505 } |
| 2517 } | 2506 } |
| 2518 | 2507 |
| 2519 void RenderThreadImpl::OnRendererInterfaceRequest( | 2508 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2520 mojom::RendererAssociatedRequest request) { | 2509 mojom::RendererAssociatedRequest request) { |
| 2521 DCHECK(!renderer_binding_.is_bound()); | 2510 DCHECK(!renderer_binding_.is_bound()); |
| 2522 renderer_binding_.Bind(std::move(request)); | 2511 renderer_binding_.Bind(std::move(request)); |
| 2523 } | 2512 } |
| 2524 | 2513 |
| 2525 } // namespace content | 2514 } // namespace content |
| OLD | NEW |