| 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 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // UnregisterDumpProvider is called while the trace is enabled. | 104 // UnregisterDumpProvider is called while the trace is enabled. |
| 105 it = std::find(dump_providers_enabled_.begin(), dump_providers_enabled_.end(), | 105 it = std::find(dump_providers_enabled_.begin(), dump_providers_enabled_.end(), |
| 106 mdp); | 106 mdp); |
| 107 if (it != dump_providers_enabled_.end()) | 107 if (it != dump_providers_enabled_.end()) |
| 108 dump_providers_enabled_.erase(it); | 108 dump_providers_enabled_.erase(it); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void MemoryDumpManager::RequestGlobalDump( | 111 void MemoryDumpManager::RequestGlobalDump( |
| 112 MemoryDumpType dump_type, | 112 MemoryDumpType dump_type, |
| 113 const MemoryDumpCallback& callback) { | 113 const MemoryDumpCallback& callback) { |
| 114 LOG(ERROR) << "MDM request enabled=" |
| 115 << subtle::NoBarrier_Load(&memory_tracing_enabled_); |
| 114 // Bail out immediately if tracing is not enabled at all. | 116 // Bail out immediately if tracing is not enabled at all. |
| 115 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) | 117 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) |
| 116 return; | 118 return; |
| 117 | 119 |
| 118 // TODO(primiano): Make guid actually unique (cross-process) by hashing it | 120 // TODO(primiano): Make guid actually unique (cross-process) by hashing it |
| 119 // with the PID. See crbug.com/462931 for details. | 121 // with the PID. See crbug.com/462931 for details. |
| 120 const uint64 guid = g_next_guid.GetNext(); | 122 const uint64 guid = g_next_guid.GetNext(); |
| 121 | 123 |
| 122 // The delegate_ is supposed to be thread safe, immutable and long lived. | 124 // The delegate_ is supposed to be thread safe, immutable and long lived. |
| 123 // No need to keep the lock after we ensure that a delegate has been set. | 125 // No need to keep the lock after we ensure that a delegate has been set. |
| 124 MemoryDumpManagerDelegate* delegate; | 126 MemoryDumpManagerDelegate* delegate; |
| 125 { | 127 { |
| 126 AutoLock lock(lock_); | 128 AutoLock lock(lock_); |
| 127 delegate = delegate_; | 129 delegate = delegate_; |
| 128 } | 130 } |
| 129 | 131 |
| 132 LOG(ERROR) << "MDM request " << guid << " delegate : " << (void*)delegate; |
| 130 if (delegate) { | 133 if (delegate) { |
| 131 // The delegate is in charge to coordinate the request among all the | 134 // The delegate is in charge to coordinate the request among all the |
| 132 // processes and call the CreateLocalDumpPoint on the local process. | 135 // processes and call the CreateLocalDumpPoint on the local process. |
| 133 MemoryDumpRequestArgs args = {guid, dump_type}; | 136 MemoryDumpRequestArgs args = {guid, dump_type}; |
| 134 delegate->RequestGlobalMemoryDump(args, callback); | 137 delegate->RequestGlobalMemoryDump(args, callback); |
| 135 } else if (!callback.is_null()) { | 138 } else if (!callback.is_null()) { |
| 136 callback.Run(guid, false /* success */); | 139 callback.Run(guid, false /* success */); |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 | 142 |
| 140 void MemoryDumpManager::RequestGlobalDump(MemoryDumpType dump_type) { | 143 void MemoryDumpManager::RequestGlobalDump(MemoryDumpType dump_type) { |
| 141 RequestGlobalDump(dump_type, MemoryDumpCallback()); | 144 RequestGlobalDump(dump_type, MemoryDumpCallback()); |
| 142 } | 145 } |
| 143 | 146 |
| 144 // Creates a memory dump for the current process and appends it to the trace. | 147 // Creates a memory dump for the current process and appends it to the trace. |
| 145 void MemoryDumpManager::CreateProcessDump( | 148 void MemoryDumpManager::CreateProcessDump( |
| 146 const MemoryDumpRequestArgs& args) { | 149 const MemoryDumpRequestArgs& args) { |
| 150 LOG(ERROR) << "MDM create " << args.dump_guid; |
| 147 bool did_any_provider_dump = false; | 151 bool did_any_provider_dump = false; |
| 148 scoped_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump()); | 152 scoped_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump()); |
| 149 | 153 |
| 150 // Serialize dump generation so that memory dump providers don't have to deal | 154 // Serialize dump generation so that memory dump providers don't have to deal |
| 151 // with thread safety. | 155 // with thread safety. |
| 152 { | 156 { |
| 153 AutoLock lock(lock_); | 157 AutoLock lock(lock_); |
| 154 for (auto it = dump_providers_enabled_.begin(); | 158 for (auto it = dump_providers_enabled_.begin(); |
| 155 it != dump_providers_enabled_.end();) { | 159 it != dump_providers_enabled_.end();) { |
| 156 dump_provider_currently_active_ = *it; | 160 dump_provider_currently_active_ = *it; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 186 } | 190 } |
| 187 | 191 |
| 188 void MemoryDumpManager::OnTraceLogEnabled() { | 192 void MemoryDumpManager::OnTraceLogEnabled() { |
| 189 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter | 193 // TODO(primiano): at this point we query TraceLog::GetCurrentCategoryFilter |
| 190 // to figure out (and cache) which dumpers should be enabled or not. | 194 // to figure out (and cache) which dumpers should be enabled or not. |
| 191 // For the moment piggy back everything on the generic "memory" category. | 195 // For the moment piggy back everything on the generic "memory" category. |
| 192 bool enabled; | 196 bool enabled; |
| 193 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | 197 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); |
| 194 | 198 |
| 195 AutoLock lock(lock_); | 199 AutoLock lock(lock_); |
| 200 LOG(ERROR) << "OnTraceLogEnabled " << enabled; |
| 196 if (enabled) { | 201 if (enabled) { |
| 197 dump_providers_enabled_.assign(dump_providers_registered_.begin(), | 202 dump_providers_enabled_.assign(dump_providers_registered_.begin(), |
| 198 dump_providers_registered_.end()); | 203 dump_providers_registered_.end()); |
| 199 } else { | 204 } else { |
| 200 dump_providers_enabled_.clear(); | 205 dump_providers_enabled_.clear(); |
| 201 } | 206 } |
| 202 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 207 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
| 203 } | 208 } |
| 204 | 209 |
| 205 void MemoryDumpManager::OnTraceLogDisabled() { | 210 void MemoryDumpManager::OnTraceLogDisabled() { |
| 211 LOG(ERROR) << "OnTraceLogDisabled"; |
| 206 AutoLock lock(lock_); | 212 AutoLock lock(lock_); |
| 207 dump_providers_enabled_.clear(); | 213 dump_providers_enabled_.clear(); |
| 208 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 214 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
| 209 } | 215 } |
| 210 | 216 |
| 211 } // namespace trace_event | 217 } // namespace trace_event |
| 212 } // namespace base | 218 } // namespace base |
| OLD | NEW |