[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metrics / system_memory_stats_recorder_linux.cc
1 // Copyright 2015 The Chromium Authors
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 "components/metrics/system_memory_stats_recorder.h"
6
7 #include "base/metrics/histogram_macros.h"
8 #include "base/process/process_metrics.h"
9 #include "build/build_config.h"
10
11 namespace metrics {
12
13 // Record a size in megabytes, a potential interval from 250MB up to 32 GB.
14 #define UMA_HISTOGRAM_ALLOCATED_MEGABYTES(name, sample) \
15   UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 250, 32768, 50)
16
17 // Records a statistics |sample| for UMA histogram |name|
18 // using a linear distribution of buckets.
19 #define UMA_HISTOGRAM_LINEAR(name, sample, max, buckets)                       \
20   STATIC_HISTOGRAM_POINTER_BLOCK(                                              \
21       name, Add(sample),                                                       \
22       base::LinearHistogram::FactoryGet(                                       \
23           name,                                                                \
24           1, /* Minimum. The 0 bin for underflow is automatically added. */    \
25           max + 1,     /* Ensure bucket size of |maximum| / |bucket_count|. */ \
26           buckets + 2, /*  Account for the underflow and overflow bins. */     \
27           base::Histogram::kUmaTargetedHistogramFlag))
28
29 #define UMA_HISTOGRAM_MEGABYTES_LINEAR(name, sample) \
30   UMA_HISTOGRAM_LINEAR(name, sample, 2500, 50)
31
32 void RecordMemoryStats(RecordMemoryStatsType type) {
33 #if BUILDFLAG(IS_CHROMEOS)
34   // Record graphics GEM object size in a histogram with 50 MB buckets.
35   int mem_gpu_mb = 0;
36   bool mem_gpu_result = false;
37   base::GraphicsMemoryInfoKB gpu_memory;
38   mem_gpu_result = base::GetGraphicsMemoryInfo(&gpu_memory);
39
40   if (mem_gpu_result) {
41     mem_gpu_mb = gpu_memory.gpu_memory_size / 1024 / 1024;
42     switch (type) {
43       case RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED:
44         UMA_HISTOGRAM_MEGABYTES_LINEAR(
45             "Memory.OOMKill.Extensions.MemGraphicsMB", mem_gpu_mb);
46         break;
47       default:
48         break;
49     }
50   }
51 #endif
52
53   base::SystemMemoryInfoKB memory;
54   if (base::GetSystemMemoryInfo(&memory)) {
55     // On Intel, graphics objects are in anonymous pages, but on ARM they are
56     // not. For a total "allocated count" add in graphics pages on ARM.
57     int mem_allocated_mb = (memory.active_anon + memory.inactive_anon) / 1024;
58 #if BUILDFLAG(IS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
59     mem_allocated_mb += mem_gpu_mb;
60 #endif
61
62     int mem_available_mb =
63         (memory.active_file + memory.inactive_file + memory.free) / 1024;
64
65     switch (type) {
66       case RECORD_MEMORY_STATS_CONTENTS_OOM_KILLED: {
67         UMA_HISTOGRAM_ALLOCATED_MEGABYTES(
68             "Memory.OOMKill.Contents.MemAllocatedMB", mem_allocated_mb);
69         break;
70       }
71       case RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED: {
72         UMA_HISTOGRAM_ALLOCATED_MEGABYTES(
73             "Memory.OOMKill.Extensions.MemAllocatedMB", mem_allocated_mb);
74         UMA_HISTOGRAM_LARGE_MEMORY_MB(
75             "Memory.OOMKill.Extensions.MemAvailableMB", mem_available_mb);
76         break;
77       }
78     }
79
80 #if BUILDFLAG(IS_CHROMEOS)
81     // Record shared memory (used by renderer/GPU buffers).
82     int mem_shmem_mb = memory.shmem / 1024;
83     switch (type) {
84       case RECORD_MEMORY_STATS_CONTENTS_OOM_KILLED:
85         UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Contents.MemShmemMB",
86                                        mem_shmem_mb);
87         break;
88       case RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED:
89         UMA_HISTOGRAM_MEGABYTES_LINEAR("Memory.OOMKill.Extensions.MemShmemMB",
90                                        mem_shmem_mb);
91         break;
92     }
93 #endif
94   }
95 }
96
97 }  // namespace metrics