1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
base / trace_event / memory_infra_background_allowlist.cc [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/trace_event/memory_infra_background_allowlist.h"
#include <string.h>
#include <string>
#include <string_view>
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "partition_alloc/buildflags.h"
#include "third_party/abseil-cpp/absl/strings/ascii.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/meminfo_dump_provider.h"
#endif
namespace base::trace_event {
namespace {
// The names of dump providers allowed to perform background tracing. Dump
// providers can be added here only if the background mode dump has very
// little processor and memory overhead.
// TODO(ssid): Some dump providers do not create ownership edges on background
// dump. So, the effective size will not be correct.
constexpr auto kDumpProviderAllowlist =
base::MakeFixedFlatSet<std::string_view>({
// clang-format off
#if BUILDFLAG(IS_ANDROID)
base::android::MeminfoDumpProvider::kDumpProviderName,
"android::ResourceManagerImpl",
#endif
"AutocompleteController",
"AXPlatformNode",
"BlinkGC",
"BlinkObjectCounters",
"BlobStorageContext",
"Canvas",
"ClientDiscardableSharedMemoryManager",
#if BUILDFLAG(IS_MAC)
"CommandBuffer",
#endif
"ContextProviderCommandBuffer",
"DOMStorage",
"DawnSharedContext",
"DevTools",
"DiscardableSharedMemoryManager",
"DownloadService",
"ExtensionFunctions",
"FontCaches",
"FrameEvictionManager",
"GrShaderCache",
"HistoryReport",
"cc::ResourcePool",
"gpu::BufferManager",
"gpu::RenderbufferManager",
"gpu::ServiceDiscardableManager",
"gpu::ServiceTransferCache",
"gpu::SharedImageStub",
"gpu::TextureManager",
"hibernated_canvas",
"vulkan",
"IPCChannel",
"InMemoryURLIndex",
"IndexedDBBackingStore",
"IndexedDBFactoryImpl",
"JavaHeap",
"LevelDB",
"LeveldbValueStore",
"LocalStorage",
"MadvFreeDiscardableMemoryAllocator",
"Malloc",
"ManualFillingCache",
"MemoryCache",
"MojoHandleTable",
"MojoLevelDB",
"MojoMessages",
"PartitionAlloc",
"PartitionAlloc.AddressSpace",
"ProcessMemoryMetrics",
"SharedContextState",
"SharedImageManager",
"SharedMemoryTracker",
"Skia",
"Sql",
"TabRestoreServiceHelper",
"TextureOwner"
"URLRequestContext",
"V8Isolate",
"WebMediaPlayer_MainThread",
"WebMediaPlayer_MediaThread",
// clang-format on
});
// A list of string names that are allowed for the memory allocator dumps in
// background mode.
constexpr auto kAllocatorDumpNameAllowlist =
base::MakeFixedFlatSet<std::string_view>({
// clang-format off
// Some of the blink values vary based on compile time flags. The
// compile time flags are not in base, so all are listed here.
#if BUILDFLAG(IS_ANDROID)
base::android::MeminfoDumpProvider::kDumpName,
#endif
"accessibility/ax_platform_node",
"blink_gc/main/allocated_objects",
"blink_gc/main/heap",
"blink_gc/workers/heap/worker_0x?",
"blink_gc/workers/worker_0x?/heap",
"blink_gc/workers/worker_0x?/allocated_objects",
"blink_objects/AdSubframe",
"blink_objects/ArrayBufferContents",
"blink_objects/AudioHandler",
"blink_objects/AudioWorkletProcessor",
"blink_objects/ContextLifecycleStateObserver",
"blink_objects/DetachedScriptState",
"blink_objects/Document",
"blink_objects/Frame",
"blink_objects/JSEventListener",
"blink_objects/LayoutObject",
"blink_objects/MediaKeySession",
"blink_objects/MediaKeys",
"blink_objects/Node",
"blink_objects/Resource",
"blink_objects/RTCPeerConnection",
"blink_objects/ScriptPromise",
"blink_objects/V8PerContextData",
"blink_objects/WorkerGlobalScope",
"blink_objects/UACSSResource",
"blink_objects/ResourceFetcher",
"canvas/hibernated",
"canvas/ResourceProvider/SkSurface",
"canvas/ResourceProvider/SkSurface/0x?",
"cc/tile_memory/provider_0x?",
"components/download/controller_0x?",
"devtools/file_watcher_0x?",
"discardable",
"discardable/madv_free_allocated",
"discardable/child_0x?",
"extensions/functions",
"extensions/value_store/Extensions.Database.Open.OriginManagedConfiguration/0x?",
"extensions/value_store/Extensions.Database.Open.Rules/0x?",
"extensions/value_store/Extensions.Database.Open.Scripts/0x?",
"extensions/value_store/Extensions.Database.Open.Settings/0x?",
"extensions/value_store/Extensions.Database.Open.State/0x?",
"extensions/value_store/Extensions.Database.Open.WebAppsLockScreen/0x?",
"extensions/value_store/Extensions.Database.Open/0x?",
"extensions/value_store/Extensions.Database.Restore/0x?",
"extensions/value_store/Extensions.Database.Value.Restore/0x?",
"font_caches/font_platform_data_cache",
"font_caches/shape_caches",
"frame_evictor",
"gpu/command_buffer_memory/buffer_0x?",
"gpu/dawn",
"gpu/discardable_cache/cache_0x?",
"gpu/discardable_cache/cache_0x?/avg_image_size",
"gpu/gl/buffers/context_group_0x?",
"gpu/gl/renderbuffers/context_group_0x?",
"gpu/gl/textures/context_group_0x?",
"gpu/gr_shader_cache/cache_0x?",
"gpu/mapped_memory/manager_0x?",
"gpu/shared_images",
"gpu/media_texture_owner_?",
"gpu/transfer_buffer_memory/buffer_0x?",
"gpu/transfer_cache/cache_0x?",
"gpu/transfer_cache/cache_0x?/avg_image_size",
"gpu/vulkan/vma_allocator_0x?",
"history/delta_file_service/leveldb_0x?",
"history/usage_reports_buffer/leveldb_0x?",
#if BUILDFLAG(IS_MAC)
"ioaccelerator",
"iosurface",
#endif
"java_heap",
"java_heap/allocated_objects",
"leveldatabase",
"leveldatabase/block_cache/browser",
"leveldatabase/block_cache/in_memory",
"leveldatabase/block_cache/unified",
"leveldatabase/block_cache/web",
"leveldatabase/db_0x?",
"leveldatabase/db_0x?/block_cache",
"leveldatabase/memenv_0x?",
"malloc",
"malloc/allocated_objects",
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
"malloc/extreme_lud",
"malloc/extreme_lud/small_objects",
"malloc/extreme_lud/large_objects",
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
"malloc/metadata_fragmentation_caches",
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
"malloc/partitions",
"malloc/partitions/allocator",
"malloc/partitions/allocator/scheduler_loop_quarantine",
"malloc/partitions/allocator/thread_cache",
"malloc/partitions/allocator/thread_cache/main_thread",
"malloc/partitions/aligned",
"malloc/partitions/original",
"malloc/sys_malloc",
"malloc/win_heap",
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
"media/webmediaplayer/audio/player_0x?",
"media/webmediaplayer/data_source/player_0x?",
"media/webmediaplayer/demuxer/player_0x?",
"media/webmediaplayer/video/player_0x?",
"media/webmediaplayer/player_0x?",
"mojo",
"mojo/data_pipe_consumer",
"mojo/data_pipe_producer",
"mojo/invitation",
"mojo/messages",
"mojo/message_pipe",
"mojo/platform_handle",
"mojo/queued_ipc_channel_message/0x?",
"mojo/shared_buffer",
"mojo/unknown",
"mojo/watcher",
"omnibox/autocomplete_controller/0x?",
"omnibox/in_memory_url_index/0x?",
"passwords/manual_filling_controller/0x?",
"web_cache/Image_resources",
"web_cache/CSS stylesheet_resources",
"web_cache/Script_resources",
"web_cache/XSL stylesheet_resources",
"web_cache/Font_resources",
"web_cache/Code_cache",
"web_cache/Encoded_size_duplicated_in_data_urls",
"web_cache/Other_resources",
"partition_alloc/allocated_objects",
"partition_alloc/address_space",
"partition_alloc/partitions",
"partition_alloc/partitions/array_buffer",
"partition_alloc/partitions/buffer",
"partition_alloc/partitions/fast_malloc",
#if !PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
"partition_alloc/partitions/fast_malloc/thread_cache",
"partition_alloc/partitions/fast_malloc/thread_cache/main_thread",
#endif
"partition_alloc/partitions/layout",
"skia/gpu_resources/context_0x?",
"skia/gpu_resources/graphite_context_0x?",
"skia/gpu_resources/gpu_main_graphite_image_provider_0x?",
"skia/gpu_resources/gpu_main_graphite_recorder_0x?",
"skia/gpu_resources/viz_compositor_graphite_image_provider_0x?",
"skia/gpu_resources/viz_compositor_graphite_recorder_0x?",
"skia/sk_glyph_cache",
"skia/sk_resource_cache",
"sqlite",
"ui/resource_manager_0x?/default_resource/0x?",
"ui/resource_manager_0x?/tinted_resource",
"site_storage/blob_storage/0x?",
"v8/main/code_stats",
"v8/main/contexts/detached_context",
"v8/main/contexts/native_context",
"v8/main/global_handles",
"v8/main/heap/code_space",
"v8/main/heap/code_stats",
"v8/main/heap/code_large_object_space",
"v8/main/heap/large_object_space",
"v8/main/heap/map_space",
"v8/main/heap/new_large_object_space",
"v8/main/heap/new_space",
"v8/main/heap/old_space",
"v8/main/heap/read_only_space",
"v8/main/heap/shared_large_object_space",
"v8/main/heap/shared_space",
"v8/main/heap/shared_trusted_large_object_space",
"v8/main/heap/shared_trusted_space",
"v8/main/heap/trusted_space",
"v8/main/heap/trusted_large_object_space",
"v8/main/malloc",
"v8/main/zapped_for_debug",
"v8/utility/code_stats",
"v8/utility/contexts/detached_context",
"v8/utility/contexts/native_context",
"v8/utility/global_handles",
"v8/utility/heap/code_space",
"v8/utility/heap/code_large_object_space",
"v8/utility/heap/large_object_space",
"v8/utility/heap/map_space",
"v8/utility/heap/new_large_object_space",
"v8/utility/heap/new_space",
"v8/utility/heap/old_space",
"v8/utility/heap/read_only_space",
"v8/utility/heap/shared_large_object_space",
"v8/utility/heap/shared_space",
"v8/utility/heap/shared_trusted_large_object_space",
"v8/utility/heap/shared_trusted_space",
"v8/utility/heap/trusted_space",
"v8/utility/heap/trusted_large_object_space",
"v8/utility/malloc",
"v8/utility/zapped_for_debug",
"v8/workers/code_stats/isolate_0x?",
"v8/workers/contexts/detached_context/isolate_0x?",
"v8/workers/contexts/native_context/isolate_0x?",
"v8/workers/global_handles/isolate_0x?",
"v8/workers/heap/code_space/isolate_0x?",
"v8/workers/heap/code_large_object_space/isolate_0x?",
"v8/workers/heap/large_object_space/isolate_0x?",
"v8/workers/heap/map_space/isolate_0x?",
"v8/workers/heap/new_large_object_space/isolate_0x?",
"v8/workers/heap/new_space/isolate_0x?",
"v8/workers/heap/old_space/isolate_0x?",
"v8/workers/heap/read_only_space/isolate_0x?",
"v8/workers/heap/shared_large_object_space/isolate_0x?",
"v8/workers/heap/shared_space/isolate_0x?",
"v8/workers/heap/shared_trusted_large_object_space/isolate_0x?",
"v8/workers/heap/shared_trusted_space/isolate_0x?",
"v8/workers/heap/trusted_space/isolate_0x?",
"v8/workers/heap/trusted_large_object_space/isolate_0x?",
"v8/workers/malloc/isolate_0x?",
"v8/workers/zapped_for_debug/isolate_0x?",
"site_storage/index_db/db_0x?",
"site_storage/index_db/memenv_0x?",
"site_storage/index_db/in_flight_0x?",
"site_storage/local_storage/0x?/cache_size",
"site_storage/localstorage/0x?/cache_size",
"site_storage/localstorage/0x?/leveldb",
"site_storage/session_storage/0x?",
"site_storage/session_storage/0x?/cache_size",
"tab_restore/service_helper_0x?/entries",
"tab_restore/service_helper_0x?/entries/group_0x?",
"tab_restore/service_helper_0x?/entries/tab_0x?",
"tab_restore/service_helper_0x?/entries/window_0x?",
"tracing/heap_profiler_blink_gc/AllocationRegister",
"tracing/heap_profiler_malloc/AllocationRegister",
"tracing/heap_profiler_partition_alloc/AllocationRegister",
// clang-format on
});
base::span<const std::string_view> g_dump_provider_allowlist_for_testing;
base::span<const std::string_view> g_allocator_dump_name_allowlist_for_testing;
} // namespace
bool IsMemoryDumpProviderInAllowlist(const char* mdp_name) {
if (g_dump_provider_allowlist_for_testing.empty()) {
return kDumpProviderAllowlist.contains(mdp_name);
} else {
return base::Contains(g_dump_provider_allowlist_for_testing, mdp_name);
}
}
bool IsMemoryAllocatorDumpNameInAllowlist(const std::string& name) {
// Global dumps that are of hex digits are all allowed for background use.
if (base::StartsWith(name, "global/", CompareCase::SENSITIVE)) {
for (size_t i = strlen("global/"); i < name.size(); i++)
if (!base::IsHexDigit(name[i]))
return false;
return true;
}
if (base::StartsWith(name, "shared_memory/", CompareCase::SENSITIVE)) {
for (size_t i = strlen("shared_memory/"); i < name.size(); i++)
if (!base::IsHexDigit(name[i]))
return false;
return true;
}
// Remove special characters, numbers (including hexadecimal which are marked
// by '0x') from the given string.
const size_t length = name.size();
std::string stripped_str;
stripped_str.reserve(length);
bool parsing_hex = false;
for (size_t i = 0; i < length; ++i) {
if (parsing_hex &&
absl::ascii_isxdigit(static_cast<unsigned char>(name[i]))) {
continue;
}
parsing_hex = false;
if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') {
parsing_hex = true;
stripped_str.append("0x?");
++i;
} else {
stripped_str.push_back(name[i]);
}
}
if (g_allocator_dump_name_allowlist_for_testing.empty()) {
return kAllocatorDumpNameAllowlist.contains(stripped_str);
} else {
return base::Contains(g_allocator_dump_name_allowlist_for_testing,
stripped_str);
}
}
void SetDumpProviderAllowlistForTesting(
base::span<const std::string_view> list) {
g_dump_provider_allowlist_for_testing = list;
}
void SetAllocatorDumpNameAllowlistForTesting(
base::span<const std::string_view> list) {
g_allocator_dump_name_allowlist_for_testing = list;
}
} // namespace base::trace_event