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