Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2566043004: Add renderer memory metrics (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 1843
1844 static size_t GetMallocUsage() { 1844 static size_t GetMallocUsage() {
1845 malloc_statistics_t stats = {0}; 1845 malloc_statistics_t stats = {0};
1846 malloc_zone_statistics(nullptr, &stats); 1846 malloc_zone_statistics(nullptr, &stats);
1847 return stats.size_in_use; 1847 return stats.size_in_use;
1848 } 1848 }
1849 1849
1850 } // namespace 1850 } // namespace
1851 #endif 1851 #endif
1852 1852
1853 // TODO(tasak): Once it is possible to use memory-infra without tracing, 1853 void RenderThreadImpl::GetRendererMemoryMetrics(
1854 // we should collect the metrics using memory-infra. 1854 RendererMemoryMetrics* memory_metrics) const {
1855 // TODO(tasak): We should also report a difference between the memory usages 1855 DCHECK(memory_metrics);
1856 // before and after purging by using memory-infra.
1857 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const {
1858 // If this renderer is resumed, we should not update UMA.
1859 if (!is_renderer_suspended_)
1860 return;
1861 1856
1862 // TODO(tasak): Compare memory metrics between purge-enabled renderers and
1863 // purge-disabled renderers (A/B testing).
1864 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); 1857 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get();
1865 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", 1858 memory_metrics->partition_alloc_kb =
1866 blink_stats.partitionAllocTotalAllocatedBytes / 1024); 1859 blink_stats.partitionAllocTotalAllocatedBytes / 1024;
1867 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", 1860 memory_metrics->blink_gc_kb = blink_stats.blinkGCTotalAllocatedBytes / 1024;
1868 blink_stats.blinkGCTotalAllocatedBytes / 1024);
1869 #if defined(OS_LINUX) || defined(OS_ANDROID) 1861 #if defined(OS_LINUX) || defined(OS_ANDROID)
1870 struct mallinfo minfo = mallinfo(); 1862 struct mallinfo minfo = mallinfo();
1871 #if defined(USE_TCMALLOC) 1863 #if defined(USE_TCMALLOC)
1872 size_t malloc_usage = minfo.uordblks; 1864 size_t malloc_usage = minfo.uordblks;
1873 #else 1865 #else
1874 size_t malloc_usage = minfo.hblkhd + minfo.arena; 1866 size_t malloc_usage = minfo.hblkhd + minfo.arena;
1875 #endif 1867 #endif
1876 #else 1868 #else
1877 size_t malloc_usage = GetMallocUsage(); 1869 size_t malloc_usage = GetMallocUsage();
1878 #endif 1870 #endif
1879 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB", 1871 memory_metrics->malloc_mb = malloc_usage / 1024 / 1024;
1880 malloc_usage / 1024 / 1024);
1881 1872
1882 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics 1873 discardable_memory::ClientDiscardableSharedMemoryManager::Statistics
1883 discardable_stats = discardable_shared_memory_manager_->GetStatistics(); 1874 discardable_stats = discardable_shared_memory_manager_->GetStatistics();
1884 size_t discardable_usage = 1875 size_t discardable_usage =
1885 discardable_stats.total_size - discardable_stats.freelist_size; 1876 discardable_stats.total_size - discardable_stats.freelist_size;
1886 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB", 1877 memory_metrics->discardable_kb = discardable_usage / 1024;
1887 discardable_usage / 1024);
1888 1878
1889 size_t v8_usage = 0; 1879 size_t v8_usage = 0;
1890 if (v8::Isolate* isolate = blink::mainThreadIsolate()) { 1880 if (v8::Isolate* isolate = blink::mainThreadIsolate()) {
1891 v8::HeapStatistics v8_heap_statistics; 1881 v8::HeapStatistics v8_heap_statistics;
1892 isolate->GetHeapStatistics(&v8_heap_statistics); 1882 isolate->GetHeapStatistics(&v8_heap_statistics);
1893 v8_usage = v8_heap_statistics.total_heap_size(); 1883 v8_usage = v8_heap_statistics.total_heap_size();
1894 } 1884 }
1895 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is 1885 // TODO(tasak): Currently only memory usage of mainThreadIsolate() is
1896 // reported. We should collect memory usages of all isolates using 1886 // reported. We should collect memory usages of all isolates using
1897 // memory-infra. 1887 // memory-infra.
1888 memory_metrics->v8_main_thread_isolate_mb = v8_usage / 1024 / 1024;
1889 size_t total_allocated = blink_stats.partitionAllocTotalAllocatedBytes +
1890 blink_stats.blinkGCTotalAllocatedBytes +
1891 malloc_usage + v8_usage + discardable_usage;
1892 memory_metrics->total_allocated_mb = total_allocated / 1024 / 1024;
1893 memory_metrics->non_discardable_total_allocated_mb =
1894 (total_allocated - discardable_usage) / 1024 / 1024;
1895 }
1896
1897 // TODO(tasak): Once it is possible to use memory-infra without tracing,
1898 // we should collect the metrics using memory-infra.
1899 // TODO(tasak): We should also report a difference between the memory usages
1900 // before and after purging by using memory-infra.
1901 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const {
1902 // If this renderer is resumed, we should not update UMA.
1903 if (!is_renderer_suspended_)
1904 return;
1905
1906 // TODO(tasak): Compare memory metrics between purge-enabled renderers and
1907 // purge-disabled renderers (A/B testing).
1908 content::RendererMemoryMetrics memory_metrics;
1909 GetRendererMemoryMetrics(&memory_metrics);
1910 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB",
1911 memory_metrics.partition_alloc_kb);
1912 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB",
1913 memory_metrics.blink_gc_kb);
1914 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.MallocMB",
1915 memory_metrics.malloc_mb);
1916 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.DiscardableKB",
1917 memory_metrics.discardable_kb);
1898 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB", 1918 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.V8MainThreadIsolateMB",
1899 v8_usage / 1024 / 1024); 1919 memory_metrics.v8_main_thread_isolate_mb);
1900 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", 1920 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB",
1901 (blink_stats.partitionAllocTotalAllocatedBytes + 1921 memory_metrics.total_allocated_mb);
1902 blink_stats.blinkGCTotalAllocatedBytes +
1903 malloc_usage + v8_usage + discardable_usage) /
1904 1024 / 1024);
1905 } 1922 }
1906 1923
1907 void RenderThreadImpl::OnProcessResume() { 1924 void RenderThreadImpl::OnProcessResume() {
1908 ChildThreadImpl::OnProcessResume(); 1925 ChildThreadImpl::OnProcessResume();
1909 1926
1910 DCHECK(is_renderer_suspended_); 1927 DCHECK(is_renderer_suspended_);
1911 is_renderer_suspended_ = false; 1928 is_renderer_suspended_ = false;
1912 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { 1929 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) {
1913 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify 1930 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify
1914 // and follow MemoryCoordinator's request. 1931 // and follow MemoryCoordinator's request.
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 } 2533 }
2517 } 2534 }
2518 2535
2519 void RenderThreadImpl::OnRendererInterfaceRequest( 2536 void RenderThreadImpl::OnRendererInterfaceRequest(
2520 mojom::RendererAssociatedRequest request) { 2537 mojom::RendererAssociatedRequest request) {
2521 DCHECK(!renderer_binding_.is_bound()); 2538 DCHECK(!renderer_binding_.is_bound());
2522 renderer_binding_.Bind(std::move(request)); 2539 renderer_binding_.Bind(std::move(request));
2523 } 2540 }
2524 2541
2525 } // namespace content 2542 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698