• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 "base/trace_event/memory_infra_background_whitelist.h"
6 
7 #include <ctype.h>
8 #include <string.h>
9 
10 #include <string>
11 
12 namespace base {
13 namespace trace_event {
14 namespace {
15 
16 // The names of dump providers whitelisted for background tracing. Dump
17 // providers can be added here only if the background mode dump has very
18 // less performance and memory overhead.
19 const char* const kDumpProviderWhitelist[] = {
20     "BlinkGC",
21     "ChildDiscardableSharedMemoryManager",
22     "DOMStorage",
23     "HostDiscardableSharedMemoryManager",
24     "IndexedDBBackingStore",
25     "JavaHeap",
26     "LeveldbValueStore",
27     "Malloc",
28     "PartitionAlloc",
29     "ProcessMemoryMetrics",
30     "Skia",
31     "Sql",
32     "V8Isolate",
33     "WinHeap",
34     nullptr  // End of list marker.
35 };
36 
37 // A list of string names that are allowed for the memory allocator dumps in
38 // background mode.
39 const char* const kAllocatorDumpNameWhitelist[] = {
40     "blink_gc",
41     "blink_gc/allocated_objects",
42     "discardable",
43     "discardable/child_0x?",
44     "dom_storage/0x?/cache_size",
45     "dom_storage/session_storage_0x?",
46     "java_heap",
47     "java_heap/allocated_objects",
48     "leveldb/index_db/0x?",
49     "leveldb/value_store/Extensions.Database.Open.Settings/0x?",
50     "leveldb/value_store/Extensions.Database.Open.Rules/0x?",
51     "leveldb/value_store/Extensions.Database.Open.State/0x?",
52     "leveldb/value_store/Extensions.Database.Open/0x?",
53     "leveldb/value_store/Extensions.Database.Restore/0x?",
54     "leveldb/value_store/Extensions.Database.Value.Restore/0x?",
55     "malloc",
56     "malloc/allocated_objects",
57     "malloc/metadata_fragmentation_caches",
58     "partition_alloc/allocated_objects",
59     "partition_alloc/partitions",
60     "partition_alloc/partitions/buffer",
61     "partition_alloc/partitions/fast_malloc",
62     "partition_alloc/partitions/layout",
63     "skia/sk_glyph_cache",
64     "skia/sk_resource_cache",
65     "sqlite",
66     "v8/isolate_0x?/heap_spaces",
67     "v8/isolate_0x?/heap_spaces/code_space",
68     "v8/isolate_0x?/heap_spaces/large_object_space",
69     "v8/isolate_0x?/heap_spaces/map_space",
70     "v8/isolate_0x?/heap_spaces/new_space",
71     "v8/isolate_0x?/heap_spaces/old_space",
72     "v8/isolate_0x?/heap_spaces/other_spaces",
73     "v8/isolate_0x?/malloc",
74     "v8/isolate_0x?/zapped_for_debug",
75     "winheap",
76     "winheap/allocated_objects",
77     nullptr  // End of list marker.
78 };
79 
80 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist;
81 const char* const* g_allocator_dump_name_whitelist =
82     kAllocatorDumpNameWhitelist;
83 
84 }  // namespace
85 
IsMemoryDumpProviderWhitelisted(const char * mdp_name)86 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
87   for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) {
88     if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0)
89       return true;
90   }
91   return false;
92 }
93 
IsMemoryAllocatorDumpNameWhitelisted(const std::string & name)94 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) {
95   // Remove special characters, numbers (including hexadecimal which are marked
96   // by '0x') from the given string.
97   const size_t length = name.size();
98   std::string stripped_str;
99   stripped_str.reserve(length);
100   bool parsing_hex = false;
101   for (size_t i = 0; i < length; ++i) {
102     if (parsing_hex && isxdigit(name[i]))
103       continue;
104     parsing_hex = false;
105     if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') {
106       parsing_hex = true;
107       stripped_str.append("0x?");
108       ++i;
109     } else {
110       stripped_str.push_back(name[i]);
111     }
112   }
113 
114   for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) {
115     if (stripped_str == g_allocator_dump_name_whitelist[i]) {
116       return true;
117     }
118   }
119   return false;
120 }
121 
SetDumpProviderWhitelistForTesting(const char * const * list)122 void SetDumpProviderWhitelistForTesting(const char* const* list) {
123   g_dump_provider_whitelist = list;
124 }
125 
SetAllocatorDumpNameWhitelistForTesting(const char * const * list)126 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
127   g_allocator_dump_name_whitelist = list;
128 }
129 
130 }  // namespace trace_event
131 }  // namespace base
132