Home | History | Annotate | Download | only in trace_event
      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     "android::ResourceManagerImpl",
     21     "BlinkGC",
     22     "ClientDiscardableSharedMemoryManager",
     23     "DOMStorage",
     24     "DiscardableSharedMemoryManager",
     25     "IndexedDBBackingStore",
     26     "JavaHeap",
     27     "LevelDB",
     28     "LeveldbValueStore",
     29     "Malloc",
     30     "MemoryCache",
     31     "PartitionAlloc",
     32     "ProcessMemoryMetrics",
     33     "Skia",
     34     "Sql",
     35     "URLRequestContext",
     36     "V8Isolate",
     37     "WinHeap",
     38     "SyncDirectory",
     39     "TabRestoreServiceHelper",
     40     nullptr  // End of list marker.
     41 };
     42 
     43 // A list of string names that are allowed for the memory allocator dumps in
     44 // background mode.
     45 const char* const kAllocatorDumpNameWhitelist[] = {
     46     "blink_gc",
     47     "blink_gc/allocated_objects",
     48     "discardable",
     49     "discardable/child_0x?",
     50     "dom_storage/0x?/cache_size",
     51     "dom_storage/session_storage_0x?",
     52     "java_heap",
     53     "java_heap/allocated_objects",
     54     "leveldb/index_db/0x?",
     55     "leveldb/leveldb_proto/0x?",
     56     "leveldb/value_store/Extensions.Database.Open.Settings/0x?",
     57     "leveldb/value_store/Extensions.Database.Open.Rules/0x?",
     58     "leveldb/value_store/Extensions.Database.Open.State/0x?",
     59     "leveldb/value_store/Extensions.Database.Open/0x?",
     60     "leveldb/value_store/Extensions.Database.Restore/0x?",
     61     "leveldb/value_store/Extensions.Database.Value.Restore/0x?",
     62     "malloc",
     63     "malloc/allocated_objects",
     64     "malloc/metadata_fragmentation_caches",
     65     "net/http_network_session_0x?",
     66     "net/http_network_session_0x?/quic_stream_factory",
     67     "net/http_network_session_0x?/socket_pool",
     68     "net/http_network_session_0x?/spdy_session_pool",
     69     "net/http_network_session_0x?/stream_factory",
     70     "net/sdch_manager_0x?",
     71     "net/ssl_session_cache",
     72     "net/url_request_context",
     73     "net/url_request_context/app_request",
     74     "net/url_request_context/app_request/0x?",
     75     "net/url_request_context/app_request/0x?/http_cache",
     76     "net/url_request_context/app_request/0x?/http_cache/memory_backend",
     77     "net/url_request_context/app_request/0x?/http_cache/simple_backend",
     78     "net/url_request_context/app_request/0x?/http_network_session",
     79     "net/url_request_context/app_request/0x?/sdch_manager",
     80     "net/url_request_context/extensions",
     81     "net/url_request_context/extensions/0x?",
     82     "net/url_request_context/extensions/0x?/http_cache",
     83     "net/url_request_context/extensions/0x?/http_cache/memory_backend",
     84     "net/url_request_context/extensions/0x?/http_cache/simple_backend",
     85     "net/url_request_context/extensions/0x?/http_network_session",
     86     "net/url_request_context/extensions/0x?/sdch_manager",
     87     "net/url_request_context/isolated_media",
     88     "net/url_request_context/isolated_media/0x?",
     89     "net/url_request_context/isolated_media/0x?/http_cache",
     90     "net/url_request_context/isolated_media/0x?/http_cache/memory_backend",
     91     "net/url_request_context/isolated_media/0x?/http_cache/simple_backend",
     92     "net/url_request_context/isolated_media/0x?/http_network_session",
     93     "net/url_request_context/isolated_media/0x?/sdch_manager",
     94     "net/url_request_context/main",
     95     "net/url_request_context/main/0x?",
     96     "net/url_request_context/main/0x?/http_cache",
     97     "net/url_request_context/main/0x?/http_cache/memory_backend",
     98     "net/url_request_context/main/0x?/http_cache/simple_backend",
     99     "net/url_request_context/main/0x?/http_network_session",
    100     "net/url_request_context/main/0x?/sdch_manager",
    101     "net/url_request_context/main_media",
    102     "net/url_request_context/main_media/0x?",
    103     "net/url_request_context/main_media/0x?/http_cache",
    104     "net/url_request_context/main_media/0x?/http_cache/memory_backend",
    105     "net/url_request_context/main_media/0x?/http_cache/simple_backend",
    106     "net/url_request_context/main_media/0x?/http_network_session",
    107     "net/url_request_context/main_media/0x?/sdch_manager",
    108     "net/url_request_context/proxy",
    109     "net/url_request_context/proxy/0x?",
    110     "net/url_request_context/proxy/0x?/http_cache",
    111     "net/url_request_context/proxy/0x?/http_cache/memory_backend",
    112     "net/url_request_context/proxy/0x?/http_cache/simple_backend",
    113     "net/url_request_context/proxy/0x?/http_network_session",
    114     "net/url_request_context/proxy/0x?/sdch_manager",
    115     "net/url_request_context/safe_browsing",
    116     "net/url_request_context/safe_browsing/0x?",
    117     "net/url_request_context/safe_browsing/0x?/http_cache",
    118     "net/url_request_context/safe_browsing/0x?/http_cache/memory_backend",
    119     "net/url_request_context/safe_browsing/0x?/http_cache/simple_backend",
    120     "net/url_request_context/safe_browsing/0x?/http_network_session",
    121     "net/url_request_context/safe_browsing/0x?/sdch_manager",
    122     "net/url_request_context/system",
    123     "net/url_request_context/system/0x?",
    124     "net/url_request_context/system/0x?/http_cache",
    125     "net/url_request_context/system/0x?/http_cache/memory_backend",
    126     "net/url_request_context/system/0x?/http_cache/simple_backend",
    127     "net/url_request_context/system/0x?/http_network_session",
    128     "net/url_request_context/system/0x?/sdch_manager",
    129     "net/url_request_context/unknown",
    130     "net/url_request_context/unknown/0x?",
    131     "net/url_request_context/unknown/0x?/http_cache",
    132     "net/url_request_context/unknown/0x?/http_cache/memory_backend",
    133     "net/url_request_context/unknown/0x?/http_cache/simple_backend",
    134     "net/url_request_context/unknown/0x?/http_network_session",
    135     "net/url_request_context/unknown/0x?/sdch_manager",
    136     "web_cache/Image_resources",
    137     "web_cache/CSS stylesheet_resources",
    138     "web_cache/Script_resources",
    139     "web_cache/XSL stylesheet_resources",
    140     "web_cache/Font_resources",
    141     "web_cache/Other_resources",
    142     "partition_alloc/allocated_objects",
    143     "partition_alloc/partitions",
    144     "partition_alloc/partitions/array_buffer",
    145     "partition_alloc/partitions/buffer",
    146     "partition_alloc/partitions/fast_malloc",
    147     "partition_alloc/partitions/layout",
    148     "skia/sk_glyph_cache",
    149     "skia/sk_resource_cache",
    150     "sqlite",
    151     "ui/resource_manager_0x?",
    152     "v8/isolate_0x?/heap_spaces",
    153     "v8/isolate_0x?/heap_spaces/code_space",
    154     "v8/isolate_0x?/heap_spaces/large_object_space",
    155     "v8/isolate_0x?/heap_spaces/map_space",
    156     "v8/isolate_0x?/heap_spaces/new_space",
    157     "v8/isolate_0x?/heap_spaces/old_space",
    158     "v8/isolate_0x?/heap_spaces/other_spaces",
    159     "v8/isolate_0x?/malloc",
    160     "v8/isolate_0x?/zapped_for_debug",
    161     "winheap",
    162     "winheap/allocated_objects",
    163     "sync/0x?/kernel",
    164     "sync/0x?/store",
    165     "sync/0x?/model_type/APP",
    166     "sync/0x?/model_type/APP_LIST",
    167     "sync/0x?/model_type/APP_NOTIFICATION",
    168     "sync/0x?/model_type/APP_SETTING",
    169     "sync/0x?/model_type/ARC_PACKAGE",
    170     "sync/0x?/model_type/ARTICLE",
    171     "sync/0x?/model_type/AUTOFILL",
    172     "sync/0x?/model_type/AUTOFILL_PROFILE",
    173     "sync/0x?/model_type/AUTOFILL_WALLET",
    174     "sync/0x?/model_type/BOOKMARK",
    175     "sync/0x?/model_type/DEVICE_INFO",
    176     "sync/0x?/model_type/DICTIONARY",
    177     "sync/0x?/model_type/EXPERIMENTS",
    178     "sync/0x?/model_type/EXTENSION",
    179     "sync/0x?/model_type/EXTENSION_SETTING",
    180     "sync/0x?/model_type/FAVICON_IMAGE",
    181     "sync/0x?/model_type/FAVICON_TRACKING",
    182     "sync/0x?/model_type/HISTORY_DELETE_DIRECTIVE",
    183     "sync/0x?/model_type/MANAGED_USER",
    184     "sync/0x?/model_type/MANAGED_USER_SETTING",
    185     "sync/0x?/model_type/MANAGED_USER_SHARED_SETTING",
    186     "sync/0x?/model_type/MANAGED_USER_WHITELIST",
    187     "sync/0x?/model_type/NIGORI",
    188     "sync/0x?/model_type/PASSWORD",
    189     "sync/0x?/model_type/PREFERENCE",
    190     "sync/0x?/model_type/PRINTER",
    191     "sync/0x?/model_type/PRIORITY_PREFERENCE",
    192     "sync/0x?/model_type/READING_LIST",
    193     "sync/0x?/model_type/SEARCH_ENGINE",
    194     "sync/0x?/model_type/SESSION",
    195     "sync/0x?/model_type/SYNCED_NOTIFICATION",
    196     "sync/0x?/model_type/SYNCED_NOTIFICATION_APP_INFO",
    197     "sync/0x?/model_type/THEME",
    198     "sync/0x?/model_type/TYPED_URL",
    199     "sync/0x?/model_type/WALLET_METADATA",
    200     "sync/0x?/model_type/WIFI_CREDENTIAL",
    201     "tab_restore/service_helper_0x?/entries",
    202     "tab_restore/service_helper_0x?/entries/tab_0x?",
    203     "tab_restore/service_helper_0x?/entries/window_0x?",
    204     nullptr  // End of list marker.
    205 };
    206 
    207 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist;
    208 const char* const* g_allocator_dump_name_whitelist =
    209     kAllocatorDumpNameWhitelist;
    210 
    211 }  // namespace
    212 
    213 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
    214   for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) {
    215     if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0)
    216       return true;
    217   }
    218   return false;
    219 }
    220 
    221 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) {
    222   // Remove special characters, numbers (including hexadecimal which are marked
    223   // by '0x') from the given string.
    224   const size_t length = name.size();
    225   std::string stripped_str;
    226   stripped_str.reserve(length);
    227   bool parsing_hex = false;
    228   for (size_t i = 0; i < length; ++i) {
    229     if (parsing_hex && isxdigit(name[i]))
    230       continue;
    231     parsing_hex = false;
    232     if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') {
    233       parsing_hex = true;
    234       stripped_str.append("0x?");
    235       ++i;
    236     } else {
    237       stripped_str.push_back(name[i]);
    238     }
    239   }
    240 
    241   for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) {
    242     if (stripped_str == g_allocator_dump_name_whitelist[i]) {
    243       return true;
    244     }
    245   }
    246   return false;
    247 }
    248 
    249 void SetDumpProviderWhitelistForTesting(const char* const* list) {
    250   g_dump_provider_whitelist = list;
    251 }
    252 
    253 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
    254   g_allocator_dump_name_whitelist = list;
    255 }
    256 
    257 }  // namespace trace_event
    258 }  // namespace base
    259