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 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 | 1827 |
1828 static size_t GetMallocUsage() { | 1828 static size_t GetMallocUsage() { |
1829 malloc_statistics_t stats = {0}; | 1829 malloc_statistics_t stats = {0}; |
1830 malloc_zone_statistics(nullptr, &stats); | 1830 malloc_zone_statistics(nullptr, &stats); |
1831 return stats.size_in_use; | 1831 return stats.size_in_use; |
1832 } | 1832 } |
1833 | 1833 |
1834 } // namespace | 1834 } // namespace |
1835 #endif | 1835 #endif |
1836 | 1836 |
1837 // TODO(tasak): Once it is possible to use memory-infra without tracing, | 1837 void RenderThreadImpl::GetRendererMemoryMetrics( |
1838 // we should collect the metrics using memory-infra. | 1838 RendererMemoryMetrics* memory_metrics) const { |
1839 // TODO(tasak): We should also report a difference between the memory usages | 1839 DCHECK(memory_metrics); |
1840 // before and after purging by using memory-infra. | |
1841 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { | |
1842 // If this renderer is resumed, we should not update UMA. | |
1843 if (!RendererIsHidden()) | |
1844 return; | |
1845 | 1840 |
1846 // TODO(tasak): Compare memory metrics between purge-enabled renderers and | |
1847 // purge-disabled renderers (A/B testing). | |
1848 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); | 1841 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); |
1849 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", | 1842 memory_metrics->partition_alloc_kb = |
1850 blink_stats.partitionAllocTotalAllocatedBytes / 1024); | 1843 blink_stats.partitionAllocTotalAllocatedBytes / 1024; |
1851 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", | 1844 memory_metrics->blink_gc_kb = blink_stats.blinkGCTotalAllocatedBytes / 1024; |
1852 blink_stats.blinkGCTotalAllocatedBytes / 1024); | |
1853 #if defined(OS_LINUX) || defined(OS_ANDROID) | 1845 #if defined(OS_LINUX) || defined(OS_ANDROID) |
1854 struct mallinfo minfo = mallinfo(); | 1846 struct mallinfo minfo = mallinfo(); |
1855 #if defined(USE_TCMALLOC) | 1847 #if defined(USE_TCMALLOC) |
1856 size_t malloc_usage = minfo.uordblks; | 1848 size_t malloc_usage = minfo.uordblks; |
1857 #else | 1849 #else |
1858 size_t malloc_usage = minfo.hblkhd + minfo.arena; | 1850 size_t malloc_usage = minfo.hblkhd + minfo.arena; |
1859 #endif | 1851 #endif |
1860 #else | 1852 #else |
1861 size_t malloc_usage = GetMallocUsage(); | 1853 size_t malloc_usage = GetMallocUsage(); |
1862 #endif | 1854 #endif |
1863 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", | 1855 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; |
1864 malloc_usage / 1024 / 1024); | |
1865 | 1856 |
1866 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics | 1857 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics |
1867 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); | 1858 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); |
1868 size_t discardable_usage = | 1859 size_t discardable_usage = |
1869 discardable_stats.total_size - discardable_stats.freelist_size; | 1860 discardable_stats.total_size - discardable_stats.freelist_size; |
1870 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", | 1861 memory_metrics->discardable_kb = discardable_usage / 1024; |
1871 discardable_usage / 1024); | |
1872 | 1862 |
1873 size_t v8_usage = 0; | 1863 size_t v8_usage = 0; |
1874 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { | 1864 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { |
1875 v8::HeapStatistics v8_heap_statistics; | 1865 v8::HeapStatistics v8_heap_statistics; |
1876 isolate->GetHeapStatistics(&v8_heap_statistics); | 1866 isolate->GetHeapStatistics(&v8_heap_statistics); |
1877 v8_usage = v8_heap_statistics.total_heap_size(); | 1867 v8_usage = v8_heap_statistics.total_heap_size(); |
1878 } | 1868 } |
1879 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is | 1869 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is |
1880 // reported. We should collect memory usages of all isolates using | 1870 // reported. We should collect memory usages of all isolates using |
1881 // memory-infra. | 1871 // memory-infra. |
| 1872 memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024; |
| 1873 size_t total_allocated = blink_stats.partitionAllocTotalAllocatedBytes + |
| 1874 blink_stats.blinkGCTotalAllocatedBytes + |
| 1875 malloc_usage + v8_usage + discardable_usage; |
| 1876 memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024; |
| 1877 memory_metrics->non_discardable_total_allocated_mb = |
| 1878 (total_allocated - discardable_usage) / 1024 / 1024; |
| 1879 memory_metrics->total_allocated_per_render_view_mb = |
| 1880 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024; |
| 1881 } |
| 1882 |
| 1883 // TODO(tasak): Once it is possible to use memory-infra without tracing, |
| 1884 // we should collect the metrics using memory-infra. |
| 1885 // TODO(tasak): We should also report a difference between the memory usages |
| 1886 // before and after purging by using memory-infra. |
| 1887 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { |
| 1888 // If this renderer is resumed, we should not update UMA. |
| 1889 if (!RendererIsHidden()) |
| 1890 return; |
| 1891 |
| 1892 // TODO(tasak): Compare memory metrics between purge-enabled renderers and |
| 1893 // purge-disabled renderers (A/B testing). |
| 1894 RendererMemoryMetrics memory_metrics; |
| 1895 GetRendererMemoryMetrics(&memory_metrics); |
| 1896 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", |
| 1897 memory_metrics.partition_alloc_kb); |
| 1898 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", |
| 1899 memory_metrics.blink_gc_kb); |
| 1900 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", |
| 1901 memory_metrics.malloc_mb); |
| 1902 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", |
| 1903 memory_metrics.discardable_kb); |
1882 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", | 1904 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", |
1883 v8_usage / 1024 / 1024); | 1905 memory_metrics.v8_main_thread_isolate_mb); |
1884 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", | 1906 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", |
1885 (blink_stats.partitionAllocTotalAllocatedBytes + | 1907 memory_metrics.total_allocated_mb); |
1886 blink_stats.blinkGCTotalAllocatedBytes + | |
1887 malloc_usage + v8_usage + discardable_usage) / | |
1888 1024 / 1024); | |
1889 } | 1908 } |
1890 | 1909 |
1891 void RenderThreadImpl::OnProcessResume() { | 1910 void RenderThreadImpl::OnProcessResume() { |
1892 ChildThreadImpl::OnProcessResume(); | 1911 ChildThreadImpl::OnProcessResume(); |
1893 | 1912 |
1894 if (!RendererIsHidden()) | 1913 if (!RendererIsHidden()) |
1895 return; | 1914 return; |
1896 | 1915 |
1897 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1916 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
1898 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1917 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2501 } | 2520 } |
2502 } | 2521 } |
2503 | 2522 |
2504 void RenderThreadImpl::OnRendererInterfaceRequest( | 2523 void RenderThreadImpl::OnRendererInterfaceRequest( |
2505 mojom::RendererAssociatedRequest request) { | 2524 mojom::RendererAssociatedRequest request) { |
2506 DCHECK(!renderer_binding_.is_bound()); | 2525 DCHECK(!renderer_binding_.is_bound()); |
2507 renderer_binding_.Bind(std::move(request)); | 2526 renderer_binding_.Bind(std::move(request)); |
2508 } | 2527 } |
2509 | 2528 |
2510 } // namespace content | 2529 } // namespace content |
OLD | NEW |