OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/allocator/features.h" | 10 #include "base/allocator/features.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const int kTraceEventNumArgs = 1; | 43 const int kTraceEventNumArgs = 1; |
44 const char* kTraceEventArgNames[] = {"dumps"}; | 44 const char* kTraceEventArgNames[] = {"dumps"}; |
45 const unsigned char kTraceEventArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; | 45 const unsigned char kTraceEventArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; |
46 | 46 |
47 StaticAtomicSequenceNumber g_next_guid; | 47 StaticAtomicSequenceNumber g_next_guid; |
48 MemoryDumpManager* g_instance_for_testing = nullptr; | 48 MemoryDumpManager* g_instance_for_testing = nullptr; |
49 | 49 |
50 // The list of dump providers that are blacklisted from strict checks when | |
51 // unregistration. These providers could potentially cause crashes on build bots | |
Primiano Tucci (use gerrit)
2017/01/06 14:00:39
either "checks on unregistration" or "checks when
ssid
2017/01/10 23:59:38
Done.
| |
52 // if they do not unregister on right thread. | |
53 // TODO(ssid): Fix all the dump providers to unregister if needed and clear the | |
54 // blacklist, crbug.com/643438. | |
55 const char* kStrictThreadCheckBlacklist[] = { | |
Primiano Tucci (use gerrit)
2017/01/06 14:00:39
+const (consts are never enough), i.e.
const char*
ssid
2017/01/10 23:59:38
Sorry forgot const here.
| |
56 "android::ResourceManagerImpl", | |
57 "AndroidGraphics", | |
58 "BrowserGpuMemoryBufferManager", | |
59 "ClientDiscardableSharedMemoryManager", | |
60 "ContextProviderCommandBuffer", | |
61 "DOMStorage", | |
62 "DiscardableSharedMemoryManager", | |
63 "FontCaches", | |
64 "GpuMemoryBufferVideoFramePool", | |
65 "IndexedDBBackingStore", | |
66 "LeveldbValueStore", | |
67 "MemoryCache", | |
68 "Skia", | |
69 "Sql", | |
70 "ThreadLocalEventBuffer", | |
71 "TraceLog", | |
72 "URLRequestContext", | |
73 "V8Isolate", | |
74 "VpxVideoDecoder", | |
75 "cc::ResourcePool", | |
76 "cc::ResourceProvider", | |
77 "cc::SoftwareImageDecodeCache", | |
78 "cc::StagingBufferPool", | |
79 "gpu::BufferManager", | |
80 "gpu::MappedMemoryManager", | |
81 "gpu::RenderbufferManager", | |
82 "gpu::TextureManager", | |
83 "gpu::TransferBufferManager", | |
84 "sql::Connection", | |
85 "SyncDirectory", | |
86 "BlacklistTestDumpProvider" // for testing | |
87 }; | |
88 | |
89 // Returns true if the name is present in the blacklist. | |
90 bool IsDumpproviderBlackListedForStrictThreadCheck(const char* name) { | |
Primiano Tucci (use gerrit)
2017/01/06 14:00:39
my suggestion is that you keep the array above and
ssid
2017/01/10 23:59:38
Done.
| |
91 for (auto* str : kStrictThreadCheckBlacklist) { | |
92 if (strcmp(name, str) == 0) | |
93 return true; | |
94 } | |
95 return false; | |
96 } | |
97 | |
50 // Callback wrapper to hook upon the completion of RequestGlobalDump() and | 98 // Callback wrapper to hook upon the completion of RequestGlobalDump() and |
51 // inject trace markers. | 99 // inject trace markers. |
52 void OnGlobalDumpDone(MemoryDumpCallback wrapped_callback, | 100 void OnGlobalDumpDone(MemoryDumpCallback wrapped_callback, |
53 uint64_t dump_guid, | 101 uint64_t dump_guid, |
54 bool success) { | 102 bool success) { |
55 TRACE_EVENT_NESTABLE_ASYNC_END1( | 103 TRACE_EVENT_NESTABLE_ASYNC_END1( |
56 MemoryDumpManager::kTraceCategory, "GlobalMemoryDump", | 104 MemoryDumpManager::kTraceCategory, "GlobalMemoryDump", |
57 TRACE_ID_MANGLE(dump_guid), "success", success); | 105 TRACE_ID_MANGLE(dump_guid), "success", success); |
58 | 106 |
59 if (!wrapped_callback.is_null()) { | 107 if (!wrapped_callback.is_null()) { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 return; // Not registered / already unregistered. | 380 return; // Not registered / already unregistered. |
333 | 381 |
334 if (take_mdp_ownership_and_delete_async) { | 382 if (take_mdp_ownership_and_delete_async) { |
335 // The MDP will be deleted whenever the MDPInfo struct will, that is either: | 383 // The MDP will be deleted whenever the MDPInfo struct will, that is either: |
336 // - At the end of this function, if no dump is in progress. | 384 // - At the end of this function, if no dump is in progress. |
337 // - Either in SetupNextMemoryDump() or InvokeOnMemoryDump() when MDPInfo is | 385 // - Either in SetupNextMemoryDump() or InvokeOnMemoryDump() when MDPInfo is |
338 // removed from |pending_dump_providers|. | 386 // removed from |pending_dump_providers|. |
339 // - When the provider is removed from |dump_providers_for_polling_|. | 387 // - When the provider is removed from |dump_providers_for_polling_|. |
340 DCHECK(!(*mdp_iter)->owned_dump_provider); | 388 DCHECK(!(*mdp_iter)->owned_dump_provider); |
341 (*mdp_iter)->owned_dump_provider = std::move(owned_mdp); | 389 (*mdp_iter)->owned_dump_provider = std::move(owned_mdp); |
342 } else if (subtle::NoBarrier_Load(&memory_tracing_enabled_)) { | 390 } else if (!IsDumpproviderBlackListedForStrictThreadCheck( |
391 (*mdp_iter)->name) || | |
392 subtle::NoBarrier_Load(&memory_tracing_enabled_)) { | |
393 // If IsDumpproviderBlackListedForStrictThreadCheck() is true, then the | |
394 // DCHECK is fired only when tracing is enabled. Otherwise the DCHECK is | |
395 // fired even when tracing is not enabled (stricter). | |
396 // TODO(ssid): Remove this condition after removing all the dump providers | |
397 // in the blacklist and the buildbots are no longer flakily hitting the | |
398 // DCHECK, crbug.com/643438. | |
399 | |
343 // If you hit this DCHECK, your dump provider has a bug. | 400 // If you hit this DCHECK, your dump provider has a bug. |
344 // Unregistration of a MemoryDumpProvider is safe only if: | 401 // Unregistration of a MemoryDumpProvider is safe only if: |
345 // - The MDP has specified a sequenced task runner affinity AND the | 402 // - The MDP has specified a sequenced task runner affinity AND the |
346 // unregistration happens on the same task runner. So that the MDP cannot | 403 // unregistration happens on the same task runner. So that the MDP cannot |
347 // unregister and be in the middle of a OnMemoryDump() at the same time. | 404 // unregister and be in the middle of a OnMemoryDump() at the same time. |
348 // - The MDP has NOT specified a task runner affinity and its ownership is | 405 // - The MDP has NOT specified a task runner affinity and its ownership is |
349 // transferred via UnregisterAndDeleteDumpProviderSoon(). | 406 // transferred via UnregisterAndDeleteDumpProviderSoon(). |
350 // In all the other cases, it is not possible to guarantee that the | 407 // In all the other cases, it is not possible to guarantee that the |
351 // unregistration will not race with OnMemoryDump() calls. | 408 // unregistration will not race with OnMemoryDump() calls. |
352 DCHECK((*mdp_iter)->task_runner && | 409 DCHECK((*mdp_iter)->task_runner && |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) | 1013 if (heavy_dump_rate_ > 0 && periodic_dumps_count_ % heavy_dump_rate_ == 0) |
957 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; | 1014 level_of_detail = MemoryDumpLevelOfDetail::DETAILED; |
958 ++periodic_dumps_count_; | 1015 ++periodic_dumps_count_; |
959 | 1016 |
960 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 1017 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
961 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 1018 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
962 } | 1019 } |
963 | 1020 |
964 } // namespace trace_event | 1021 } // namespace trace_event |
965 } // namespace base | 1022 } // namespace base |
OLD | NEW |