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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 930 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
931 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 931 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
932 // redirection experiment concludes https://crbug.com/622400. | 932 // redirection experiment concludes https://crbug.com/622400. |
933 if (!command_line.HasSwitch(switches::kSingleProcess)) | 933 if (!command_line.HasSwitch(switches::kSingleProcess)) |
934 base::SequencedWorkerPool::EnableForProcess(); | 934 base::SequencedWorkerPool::EnableForProcess(); |
935 } | 935 } |
936 | 936 |
937 RenderThreadImpl::~RenderThreadImpl() { | 937 RenderThreadImpl::~RenderThreadImpl() { |
938 } | 938 } |
939 | 939 |
940 void RenderThreadImpl::Shutdown() { | 940 void RenderThreadImpl::Shutdown() { |
Ilya Sherman
2017/01/10 20:29:56
Are you sure that this code is routinely reached?
keishi
2017/01/11 02:40:46
You're right this wasn't called so I've removed th
| |
941 { | |
942 RendererMemoryMetrics memory_metrics; | |
943 GetRendererMemoryMetrics(&memory_metrics); | |
944 UMA_HISTOGRAM_MEMORY_MB( | |
945 "Memory.Experimental.Renderer.Shutdown.PartitionAllocMB", | |
946 memory_metrics.partition_alloc_kb / 1024); | |
947 UMA_HISTOGRAM_MEMORY_MB( | |
948 "Memory.Experimental.Renderer.Shutdown.BlinkGCMB", | |
949 memory_metrics.blink_gc_kb / 1024); | |
950 UMA_HISTOGRAM_MEMORY_MB("Memory.Experimental.Renderer.Shutdown.MallocMB", | |
951 memory_metrics.malloc_mb); | |
952 UMA_HISTOGRAM_MEMORY_MB( | |
953 "Memory.Experimental.Renderer.Shutdown.DiscardableMB", | |
954 memory_metrics.discardable_kb / 1024); | |
955 UMA_HISTOGRAM_MEMORY_MB( | |
956 "Memory.Experimental.Renderer.Shutdown.V8MainThreadIsolateMB", | |
957 memory_metrics.v8_main_thread_isolate_mb); | |
958 UMA_HISTOGRAM_MEMORY_MB( | |
959 "Memory.Experimental.Renderer.Shutdown.TotalAllocatedMB", | |
960 memory_metrics.total_allocated_mb); | |
961 UMA_HISTOGRAM_MEMORY_MB( | |
962 "Memory.Experimental.Renderer.Shutdown.NonDiscardableTotalAllocatedMB", | |
963 memory_metrics.non_discardable_total_allocated_mb); | |
964 UMA_HISTOGRAM_MEMORY_MB( | |
965 "Memory.Experimental.Renderer.Shutdown.TotalAllocatedPerRenderViewMB", | |
966 memory_metrics.total_allocated_per_render_view_mb); | |
967 } | |
968 | |
941 for (auto& observer : observers_) | 969 for (auto& observer : observers_) |
942 observer.OnRenderProcessShutdown(); | 970 observer.OnRenderProcessShutdown(); |
943 | 971 |
944 if (memory_observer_) { | 972 if (memory_observer_) { |
945 message_loop()->RemoveTaskObserver(memory_observer_.get()); | 973 message_loop()->RemoveTaskObserver(memory_observer_.get()); |
946 memory_observer_.reset(); | 974 memory_observer_.reset(); |
947 } | 975 } |
948 | 976 |
949 // Wait for all databases to be closed. | 977 // Wait for all databases to be closed. |
950 if (blink_platform_impl_) { | 978 if (blink_platform_impl_) { |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1828 | 1856 |
1829 static size_t GetMallocUsage() { | 1857 static size_t GetMallocUsage() { |
1830 malloc_statistics_t stats = {0}; | 1858 malloc_statistics_t stats = {0}; |
1831 malloc_zone_statistics(nullptr, &stats); | 1859 malloc_zone_statistics(nullptr, &stats); |
1832 return stats.size_in_use; | 1860 return stats.size_in_use; |
1833 } | 1861 } |
1834 | 1862 |
1835 } // namespace | 1863 } // namespace |
1836 #endif | 1864 #endif |
1837 | 1865 |
1838 // TODO(tasak): Once it is possible to use memory-infra without tracing, | 1866 void RenderThreadImpl::GetRendererMemoryMetrics( |
1839 // we should collect the metrics using memory-infra. | 1867 RendererMemoryMetrics* memory_metrics) const { |
1840 // TODO(tasak): We should also report a difference between the memory usages | 1868 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 | 1869 |
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(); | 1870 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); |
1850 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", | 1871 memory_metrics->partition_alloc_kb = |
1851 blink_stats.partitionAllocTotalAllocatedBytes / 1024); | 1872 blink_stats.partitionAllocTotalAllocatedBytes / 1024; |
1852 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", | 1873 memory_metrics->blink_gc_kb = blink_stats.blinkGCTotalAllocatedBytes / 1024; |
1853 blink_stats.blinkGCTotalAllocatedBytes / 1024); | |
1854 #if defined(OS_LINUX) || defined(OS_ANDROID) | 1874 #if defined(OS_LINUX) || defined(OS_ANDROID) |
1855 struct mallinfo minfo = mallinfo(); | 1875 struct mallinfo minfo = mallinfo(); |
1856 #if defined(USE_TCMALLOC) | 1876 #if defined(USE_TCMALLOC) |
1857 size_t malloc_usage = minfo.uordblks; | 1877 size_t malloc_usage = minfo.uordblks; |
1858 #else | 1878 #else |
1859 size_t malloc_usage = minfo.hblkhd + minfo.arena; | 1879 size_t malloc_usage = minfo.hblkhd + minfo.arena; |
1860 #endif | 1880 #endif |
1861 #else | 1881 #else |
1862 size_t malloc_usage = GetMallocUsage(); | 1882 size_t malloc_usage = GetMallocUsage(); |
1863 #endif | 1883 #endif |
1864 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", | 1884 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; |
1865 malloc_usage / 1024 / 1024); | |
1866 | 1885 |
1867 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics | 1886 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics |
1868 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); | 1887 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); |
1869 size_t discardable_usage = | 1888 size_t discardable_usage = |
1870 discardable_stats.total_size - discardable_stats.freelist_size; | 1889 discardable_stats.total_size - discardable_stats.freelist_size; |
1871 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", | 1890 memory_metrics->discardable_kb = discardable_usage / 1024; |
1872 discardable_usage / 1024); | |
1873 | 1891 |
1874 size_t v8_usage = 0; | 1892 size_t v8_usage = 0; |
1875 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { | 1893 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { |
1876 v8::HeapStatistics v8_heap_statistics; | 1894 v8::HeapStatistics v8_heap_statistics; |
1877 isolate->GetHeapStatistics(&v8_heap_statistics); | 1895 isolate->GetHeapStatistics(&v8_heap_statistics); |
1878 v8_usage = v8_heap_statistics.total_heap_size(); | 1896 v8_usage = v8_heap_statistics.total_heap_size(); |
1879 } | 1897 } |
1880 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is | 1898 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is |
1881 // reported. We should collect memory usages of all isolates using | 1899 // reported. We should collect memory usages of all isolates using |
1882 // memory-infra. | 1900 // memory-infra. |
1901 memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024; | |
1902 size_t total_allocated = blink_stats.partitionAllocTotalAllocatedBytes + | |
1903 blink_stats.blinkGCTotalAllocatedBytes + | |
1904 malloc_usage + v8_usage + discardable_usage; | |
1905 memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024; | |
1906 memory_metrics->non_discardable_total_allocated_mb = | |
1907 (total_allocated - discardable_usage) / 1024 / 1024; | |
1908 memory_metrics->total_allocated_per_render_view_mb = | |
1909 total_allocated / RenderView::GetRenderViewCount() / 1024 / 1024; | |
1910 } | |
1911 | |
1912 // TODO(tasak): Once it is possible to use memory-infra without tracing, | |
1913 // we should collect the metrics using memory-infra. | |
1914 // TODO(tasak): We should also report a difference between the memory usages | |
1915 // before and after purging by using memory-infra. | |
1916 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { | |
1917 // If this renderer is resumed, we should not update UMA. | |
1918 if (!RendererIsHidden()) | |
1919 return; | |
1920 | |
1921 // TODO(tasak): Compare memory metrics between purge-enabled renderers and | |
1922 // purge-disabled renderers (A/B testing). | |
1923 RendererMemoryMetrics memory_metrics; | |
1924 GetRendererMemoryMetrics(&memory_metrics); | |
1925 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", | |
1926 memory_metrics.partition_alloc_kb); | |
1927 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", | |
1928 memory_metrics.blink_gc_kb); | |
1929 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", | |
1930 memory_metrics.malloc_mb); | |
1931 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", | |
1932 memory_metrics.discardable_kb); | |
1883 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", | 1933 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", |
1884 v8_usage / 1024 / 1024); | 1934 memory_metrics.v8_main_thread_isolate_mb); |
1885 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", | 1935 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", |
1886 (blink_stats.partitionAllocTotalAllocatedBytes + | 1936 memory_metrics.total_allocated_mb); |
1887 blink_stats.blinkGCTotalAllocatedBytes + | |
1888 malloc_usage + v8_usage + discardable_usage) / | |
1889 1024 / 1024); | |
1890 } | 1937 } |
1891 | 1938 |
1892 void RenderThreadImpl::OnProcessResume() { | 1939 void RenderThreadImpl::OnProcessResume() { |
1893 ChildThreadImpl::OnProcessResume(); | 1940 ChildThreadImpl::OnProcessResume(); |
1894 | 1941 |
1895 if (!RendererIsHidden()) | 1942 if (!RendererIsHidden()) |
1896 return; | 1943 return; |
1897 | 1944 |
1898 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | 1945 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
1899 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | 1946 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2502 } | 2549 } |
2503 } | 2550 } |
2504 | 2551 |
2505 void RenderThreadImpl::OnRendererInterfaceRequest( | 2552 void RenderThreadImpl::OnRendererInterfaceRequest( |
2506 mojom::RendererAssociatedRequest request) { | 2553 mojom::RendererAssociatedRequest request) { |
2507 DCHECK(!renderer_binding_.is_bound()); | 2554 DCHECK(!renderer_binding_.is_bound()); |
2508 renderer_binding_.Bind(std::move(request)); | 2555 renderer_binding_.Bind(std::move(request)); |
2509 } | 2556 } |
2510 | 2557 |
2511 } // namespace content | 2558 } // namespace content |
OLD | NEW |