| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/memory/system_memory_stats_recorder.h" | |
| 6 | |
| 7 #include "base/metrics/histogram_macros.h" | |
| 8 #include "base/process/process_metrics.h" | |
| 9 | |
| 10 // Record a size in megabytes, over a potential interval up to 32 GB. | |
| 11 #define UMA_HISTOGRAM_AVAILABLE_MEGABYTES(name, sample) \ | |
| 12 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 32768, 50) | |
| 13 | |
| 14 // Record a size in megabytes, a potential interval from 250MB up to | |
| 15 // 32 GB. | |
| 16 #define UMA_HISTOGRAM_ALLOCATED_MEGABYTES(name, sample) \ | |
| 17 UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 250, 32768, 50) | |
| 18 | |
| 19 // Records a statistics |sample| for UMA histogram |name| | |
| 20 // using a linear distribution of buckets. | |
| 21 #define UMA_HISTOGRAM_LINEAR(name, sample, max, buckets) \ | |
| 22 STATIC_HISTOGRAM_POINTER_BLOCK( \ | |
| 23 name, Add(sample), \ | |
| 24 base::LinearHistogram::FactoryGet( \ | |
| 25 name, \ | |
| 26 1, /* Minimum. The 0 bin for underflow is automatically added. */ \ | |
| 27 max + 1, /* Ensure bucket size of |maximum| / |bucket_count|. */ \ | |
| 28 buckets + 2, /* Account for the underflow and overflow bins. */ \ | |
| 29 base::Histogram::kUmaTargetedHistogramFlag)) | |
| 30 | |
| 31 #define UMA_HISTOGRAM_MEGABYTES_LINEAR(name, sample) \ | |
| 32 UMA_HISTOGRAM_LINEAR(name, sample, 2500, 50) | |
| 33 | |
| 34 namespace chromeos { | |
| 35 | |
| 36 void RecordMemoryStats(RecordMemoryStatsType type) { | |
| 37 base::SystemMemoryInfoKB memory; | |
| 38 if (!base::GetSystemMemoryInfo(&memory)) | |
| 39 return; | |
| 40 // Record graphics GEM object size in a histogram with 50 MB buckets. | |
| 41 int mem_graphics_gem_mb = 0; | |
| 42 if (memory.gem_size != -1) | |
| 43 mem_graphics_gem_mb = memory.gem_size / 1024 / 1024; | |
| 44 | |
| 45 // Record shared memory (used by renderer/GPU buffers). | |
| 46 int mem_shmem_mb = memory.shmem / 1024; | |
| 47 | |
| 48 // On Intel, graphics objects are in anonymous pages, but on ARM they are | |
| 49 // not. For a total "allocated count" add in graphics pages on ARM. | |
| 50 int mem_allocated_mb = (memory.active_anon + memory.inactive_anon) / 1024; | |
| 51 #if defined(ARCH_CPU_ARM_FAMILY) | |
| 52 mem_allocated_mb += mem_graphics_gem_mb; | |
| 53 #endif | |
| 54 | |
| 55 int mem_available_mb = | |
| 56 (memory.active_file + memory.inactive_file + memory.free) / 1024; | |
| 57 | |
| 58 switch (type) { | |
| 59 case RECORD_MEMORY_STATS_TAB_DISCARDED: { | |
| 60 UMA_HISTOGRAM_MEGABYTES_LINEAR("Tabs.Discard.MemGraphicsMB", | |
| 61 mem_graphics_gem_mb); | |
| 62 UMA_HISTOGRAM_MEGABYTES_LINEAR("Tabs.Discard.MemShmemMB", mem_shmem_mb); | |
| 63 UMA_HISTOGRAM_ALLOCATED_MEGABYTES("Tabs.Discard.MemAllocatedMB", | |
| 64 mem_allocated_mb); | |
| 65 UMA_HISTOGRAM_AVAILABLE_MEGABYTES("Tabs.Discard.MemAvailableMB", | |
| 66 mem_available_mb); | |
| 67 break; | |
| 68 } | |
| 69 case RECORD_MEMORY_STATS_CONTENTS_OOM_KILLED: { | |
| 70 UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Contents.MemGraphicsMB", | |
| 71 mem_graphics_gem_mb); | |
| 72 UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Contents.MemShmemMB", | |
| 73 mem_shmem_mb); | |
| 74 UMA_HISTOGRAM_ALLOCATED_MEGABYTES( | |
| 75 "Memory.OOMKill.Contents.MemAllocatedMB", mem_allocated_mb); | |
| 76 UMA_HISTOGRAM_AVAILABLE_MEGABYTES( | |
| 77 "Memory.OOMKill.Contents.MemAvailableMB", mem_available_mb); | |
| 78 break; | |
| 79 } | |
| 80 case RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED: { | |
| 81 UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Extensions.MemGraphicsMB", | |
| 82 mem_graphics_gem_mb); | |
| 83 UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Extensions.MemShmemMB", | |
| 84 mem_shmem_mb); | |
| 85 UMA_HISTOGRAM_ALLOCATED_MEGABYTES( | |
| 86 "Memory.OOMKill.Extensions.MemAllocatedMB", mem_allocated_mb); | |
| 87 UMA_HISTOGRAM_AVAILABLE_MEGABYTES( | |
| 88 "Memory.OOMKill.Extensions.MemAvailableMB", mem_available_mb); | |
| 89 break; | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 } // namespace chromeos | |
| OLD | NEW |