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_", | |
44 "dom_storage/cache_size", | |
45 "dom_storage/session_storage_", | |
46 "javaheap", | |
47 "javaheap/allocated_objects", | |
48 "leveldb/index_db/", | |
49 "leveldb/value_store/Extensions.Database.Open.Settings/", | |
50 "leveldb/value_store/Extensions.Database.Open.Rules/", | |
51 "leveldb/value_store/Extensions.Database.Open.State/", | |
52 "leveldb/value_store/Extensions.Database.Open/", | |
53 "leveldb/value_store/Extensions.Database.Restore/", | |
54 "leveldb/value_store/Extensions.Database.Value.Restore/", | |
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 "v/isolate_/heap_spaces", | |
67 "v/isolate_/heap_spaces/code_space", | |
68 "v/isolate_/heap_spaces/large_object_space", | |
69 "v/isolate_/heap_spaces/map_space", | |
70 "v/isolate_/heap_spaces/new_space", | |
71 "v/isolate_/heap_spaces/old_space", | |
72 "v/isolate_/heap_spaces/other_spaces", | |
73 "v/isolate_/malloc", | |
74 "v/isolate_/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) { |
Primiano Tucci (use gerrit)
2016/06/09 18:11:59
Sorry for the back an forths, trying to make this
ssid
2016/06/09 22:23:13
No problem I was expecting suggestion on this.
| |
55 if (isxdigit(name[i])) { | 103 if (isxdigit(name[i])) { |
56 continue; | 104 continue; |
57 } else { | 105 } else { |
58 parsing_hex = false; | 106 parsing_hex = false; |
59 } | 107 } |
60 } | 108 } |
61 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { | 109 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') { |
62 parsing_hex = true; | 110 parsing_hex = true; |
63 ++i; | 111 ++i; |
64 } else if (isalpha(name[i]) || | 112 } else if (isalpha(name[i]) || ((ispunct(name[i]) || isblank(name[i])) && |
65 (name[i] == '/' && stripped_str.back() != '/')) { | 113 stripped_str.back() != '/')) { |
66 // Do not add successive '/'(s) in |stripped_str|. | 114 // Do not add successive '/'(s) in |stripped_str|. |
67 stripped_str.push_back(name[i]); | 115 stripped_str.push_back(name[i]); |
68 } | 116 } |
69 } | 117 } |
70 | 118 |
71 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { | 119 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) { |
72 if (stripped_str == g_allocator_dump_name_whitelist[i]) { | 120 if (stripped_str == g_allocator_dump_name_whitelist[i]) { |
73 return true; | 121 return true; |
74 } | 122 } |
75 } | 123 } |
76 return false; | 124 return false; |
77 } | 125 } |
78 | 126 |
79 void SetDumpProviderWhitelistForTesting(const char* const* list) { | 127 void SetDumpProviderWhitelistForTesting(const char* const* list) { |
80 g_dump_provider_whitelist = list; | 128 g_dump_provider_whitelist = list; |
81 } | 129 } |
82 | 130 |
83 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { | 131 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) { |
84 g_allocator_dump_name_whitelist = list; | 132 g_allocator_dump_name_whitelist = list; |
85 } | 133 } |
86 | 134 |
87 } // namespace trace_event | 135 } // namespace trace_event |
88 } // namespace base | 136 } // namespace base |
OLD | NEW |