| 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 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 1728 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1729 base::Unretained(this), "60min", process_foregrounded_count_), | 1729 base::Unretained(this), "60min", process_foregrounded_count_), |
| 1730 base::TimeDelta::FromMinutes(60)); | 1730 base::TimeDelta::FromMinutes(60)); |
| 1731 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1731 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1732 FROM_HERE, | 1732 FROM_HERE, |
| 1733 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 1733 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1734 base::Unretained(this), "90min", process_foregrounded_count_), | 1734 base::Unretained(this), "90min", process_foregrounded_count_), |
| 1735 base::TimeDelta::FromMinutes(90)); | 1735 base::TimeDelta::FromMinutes(90)); |
| 1736 } | 1736 } |
| 1737 | 1737 |
| 1738 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | |
| 1739 // when it is possible to run memory-infra without tracing. | |
| 1740 #if defined(OS_WIN) | |
| 1741 namespace { | |
| 1742 | |
| 1743 static size_t GetMallocUsage() { | |
| 1744 // Iterate through whichever heap the CRT is using. | |
| 1745 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | |
| 1746 if (crt_heap == NULL) | |
| 1747 return 0; | |
| 1748 if (!::HeapLock(crt_heap)) | |
| 1749 return 0 ; | |
| 1750 size_t malloc_usage = 0; | |
| 1751 PROCESS_HEAP_ENTRY heap_entry; | |
| 1752 heap_entry.lpData = NULL; | |
| 1753 while (::HeapWalk(crt_heap, &heap_entry) != 0) { | |
| 1754 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) | |
| 1755 malloc_usage += heap_entry.cbData; | |
| 1756 } | |
| 1757 ::HeapUnlock(crt_heap); | |
| 1758 return malloc_usage; | |
| 1759 } | |
| 1760 | |
| 1761 } // namespace | |
| 1762 #elif defined(OS_MACOSX) || defined(OS_IOS) | |
| 1763 namespace { | |
| 1764 | |
| 1765 static size_t GetMallocUsage() { | |
| 1766 malloc_statistics_t stats = {0}; | |
| 1767 malloc_zone_statistics(nullptr, &stats); | |
| 1768 return stats.size_in_use; | |
| 1769 } | |
| 1770 | |
| 1771 } // namespace | |
| 1772 #endif | |
| 1773 | |
| 1774 bool RenderThreadImpl::GetRendererMemoryMetrics( | 1738 bool RenderThreadImpl::GetRendererMemoryMetrics( |
| 1775 RendererMemoryMetrics* memory_metrics) const { | 1739 RendererMemoryMetrics* memory_metrics) const { |
| 1776 DCHECK(memory_metrics); | 1740 DCHECK(memory_metrics); |
| 1777 | 1741 |
| 1778 // Cache this result, as it can change while this code is running, and is used | 1742 // Cache this result, as it can change while this code is running, and is used |
| 1779 // as a divisor below. | 1743 // as a divisor below. |
| 1780 size_t render_view_count = RenderView::GetRenderViewCount(); | 1744 size_t render_view_count = RenderView::GetRenderViewCount(); |
| 1781 | 1745 |
| 1782 // If there are no render views it doesn't make sense to calculate metrics | 1746 // If there are no render views it doesn't make sense to calculate metrics |
| 1783 // right now. | 1747 // right now. |
| 1784 if (render_view_count == 0) | 1748 if (render_view_count == 0) |
| 1785 return false; | 1749 return false; |
| 1786 | 1750 |
| 1787 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); | 1751 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); |
| 1788 memory_metrics->partition_alloc_kb = | 1752 memory_metrics->partition_alloc_kb = |
| 1789 blink_stats.partition_alloc_total_allocated_bytes / 1024; | 1753 blink_stats.partition_alloc_total_allocated_bytes / 1024; |
| 1790 memory_metrics->blink_gc_kb = | 1754 memory_metrics->blink_gc_kb = |
| 1791 blink_stats.blink_gc_total_allocated_bytes / 1024; | 1755 blink_stats.blink_gc_total_allocated_bytes / 1024; |
| 1792 #if defined(OS_LINUX) || defined(OS_ANDROID) | 1756 std::unique_ptr<base::ProcessMetrics> metric( |
| 1793 struct mallinfo minfo = mallinfo(); | 1757 base::ProcessMetrics::CreateCurrentProcessMetrics()); |
| 1794 #if defined(USE_TCMALLOC) | 1758 size_t malloc_usage = metric->GetMallocUsage(); |
| 1795 size_t malloc_usage = minfo.uordblks; | |
| 1796 #else | |
| 1797 size_t malloc_usage = minfo.hblkhd + minfo.arena; | |
| 1798 #endif | |
| 1799 #else | |
| 1800 size_t malloc_usage = GetMallocUsage(); | |
| 1801 #endif | |
| 1802 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; | 1759 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; |
| 1803 | 1760 |
| 1804 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics | 1761 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics |
| 1805 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); | 1762 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); |
| 1806 size_t discardable_usage = | 1763 size_t discardable_usage = |
| 1807 discardable_stats.total_size - discardable_stats.freelist_size; | 1764 discardable_stats.total_size - discardable_stats.freelist_size; |
| 1808 memory_metrics->discardable_kb = discardable_usage / 1024; | 1765 memory_metrics->discardable_kb = discardable_usage / 1024; |
| 1809 | 1766 |
| 1810 size_t v8_usage = 0; | 1767 size_t v8_usage = 0; |
| 1811 if (v8::Isolate* isolate = blink::MainThreadIsolate()) { | 1768 if (v8::Isolate* isolate = blink::MainThreadIsolate()) { |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2518 } | 2475 } |
| 2519 } | 2476 } |
| 2520 | 2477 |
| 2521 void RenderThreadImpl::OnRendererInterfaceRequest( | 2478 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2522 mojom::RendererAssociatedRequest request) { | 2479 mojom::RendererAssociatedRequest request) { |
| 2523 DCHECK(!renderer_binding_.is_bound()); | 2480 DCHECK(!renderer_binding_.is_bound()); |
| 2524 renderer_binding_.Bind(std::move(request)); | 2481 renderer_binding_.Bind(std::move(request)); |
| 2525 } | 2482 } |
| 2526 | 2483 |
| 2527 } // namespace content | 2484 } // namespace content |
| OLD | NEW |