OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "base/trace_event/memory_infra_background_whitelist.h" | 5 #include "base/trace_event/memory_infra_background_whitelist.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace trace_event { | 13 namespace trace_event { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // The names of dump providers whitelisted for background tracing. Dump | 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 | 17 // providers can be added here only if the background mode dump has very |
18 // less performance and memory overhead. | 18 // less performance and memory overhead. |
19 const char* const kDumpProviderWhitelist[] = { | 19 const char* const kDumpProviderWhitelist[] = { |
20 // TODO(ssid): Fill this list with dump provider names which support | 20 "BlinkGC", |
21 // background mode, crbug.com/613198. | 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", |
22 nullptr // End of list marker. | 34 nullptr // End of list marker. |
23 }; | 35 }; |
24 | 36 |
25 // A list of string names that are allowed for the memory allocator dumps in | 37 // A list of string names that are allowed for the memory allocator dumps in |
26 // background mode. | 38 // background mode. |
27 const char* const kAllocatorDumpNameWhitelist[] = { | 39 const char* const kAllocatorDumpNameWhitelist[] = { |
28 // TODO(ssid): Fill this list with dump names, crbug.com/613198. | 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", |
29 nullptr // End of list marker. | 77 nullptr // End of list marker. |
30 }; | 78 }; |
31 | 79 |
32 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist; | 80 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist; |
33 const char* const* g_allocator_dump_name_whitelist = | 81 const char* const* g_allocator_dump_name_whitelist = |
34 kAllocatorDumpNameWhitelist; | 82 kAllocatorDumpNameWhitelist; |
35 | 83 |
36 } // namespace | 84 } // namespace |
37 | 85 |
38 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) { | 86 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) { |
39 for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) { | 87 for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) { |
40 if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0) | 88 if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0) |
41 return true; | 89 return true; |
42 } | 90 } |
43 return false; | 91 return false; |
44 } | 92 } |
45 | 93 |
46 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) { | 94 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) { |
47 // Remove special characters, numbers (including hexadecimal which are marked | 95 // Remove special characters, numbers (including hexadecimal which are marked |
48 // by '0x') from the given string. | 96 // by '0x') from the given string. |
49 const size_t length = name.size(); | 97 const size_t length = name.size(); |
50 std::string stripped_str; | 98 std::string stripped_str; |
51 stripped_str.reserve(length); | 99 stripped_str.reserve(length); |
52 bool parsing_hex = false; | 100 bool parsing_hex = false; |
53 for (size_t i = 0; i < length; ++i) { | 101 for (size_t i = 0; i < length; ++i) { |
54 if (parsing_hex) { | 102 if (parsing_hex && isxdigit(name[i])) |
55 if (isxdigit(name[i])) { | 103 continue; |
56 continue; | 104 parsing_hex = false; |
57 } else { | |
58 parsing_hex = false; | |
59 } | |
60 } | |
61 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { | 105 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { |
62 parsing_hex = true; | 106 parsing_hex = true; |
| 107 stripped_str.append("0x?"); |
63 ++i; | 108 ++i; |
64 } else if (isalpha(name[i]) || | 109 } else { |
65 (name[i] == '/' && stripped_str.back() != '/')) { | |
66 // Do not add successive '/'(s) in |stripped_str|. | |
67 stripped_str.push_back(name[i]); | 110 stripped_str.push_back(name[i]); |
68 } | 111 } |
69 } | 112 } |
70 | 113 |
71 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { | 114 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { |
72 if (stripped_str == g_allocator_dump_name_whitelist[i]) { | 115 if (stripped_str == g_allocator_dump_name_whitelist[i]) { |
73 return true; | 116 return true; |
74 } | 117 } |
75 } | 118 } |
76 return false; | 119 return false; |
77 } | 120 } |
78 | 121 |
79 void SetDumpProviderWhitelistForTesting(const char* const* list) { | 122 void SetDumpProviderWhitelistForTesting(const char* const* list) { |
80 g_dump_provider_whitelist = list; | 123 g_dump_provider_whitelist = list; |
81 } | 124 } |
82 | 125 |
83 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { | 126 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { |
84 g_allocator_dump_name_whitelist = list; | 127 g_allocator_dump_name_whitelist = list; |
85 } | 128 } |
86 | 129 |
87 } // namespace trace_event | 130 } // namespace trace_event |
88 } // namespace base | 131 } // namespace base |
OLD | NEW |