| 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 "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // GTest matchers for MemoryDumpRequestArgs arguments. | 31 // GTest matchers for MemoryDumpRequestArgs arguments. |
| 32 MATCHER(IsDetailedDump, "") { | 32 MATCHER(IsDetailedDump, "") { |
| 33 return arg.level_of_detail == MemoryDumpLevelOfDetail::DETAILED; | 33 return arg.level_of_detail == MemoryDumpLevelOfDetail::DETAILED; |
| 34 } | 34 } |
| 35 | 35 |
| 36 MATCHER(IsLightDump, "") { | 36 MATCHER(IsLightDump, "") { |
| 37 return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT; | 37 return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT; |
| 38 } | 38 } |
| 39 | 39 |
| 40 namespace { |
| 41 void RegisterDumpProvider( |
| 42 MemoryDumpProvider* mdp, |
| 43 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 44 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
| 45 mdm->set_dumper_registrations_ignored_for_testing(false); |
| 46 mdm->RegisterDumpProvider(mdp, task_runner); |
| 47 mdm->set_dumper_registrations_ignored_for_testing(true); |
| 48 } |
| 49 |
| 50 void RegisterDumpProvider(MemoryDumpProvider* mdp) { |
| 51 RegisterDumpProvider(mdp, nullptr); |
| 52 } |
| 53 } // namespace |
| 54 |
| 40 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump | 55 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump |
| 41 // requests locally to the MemoryDumpManager instead of performing IPC dances. | 56 // requests locally to the MemoryDumpManager instead of performing IPC dances. |
| 42 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { | 57 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { |
| 43 public: | 58 public: |
| 44 MemoryDumpManagerDelegateForTesting() { | 59 MemoryDumpManagerDelegateForTesting() { |
| 45 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) | 60 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) |
| 46 .WillByDefault(Invoke( | 61 .WillByDefault(Invoke( |
| 47 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); | 62 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); |
| 48 } | 63 } |
| 49 | 64 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, | 100 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, |
| 86 Closure closure, | 101 Closure closure, |
| 87 uint64 dump_guid, | 102 uint64 dump_guid, |
| 88 bool success) { | 103 bool success) { |
| 89 last_callback_success_ = success; | 104 last_callback_success_ = success; |
| 90 task_runner->PostTask(FROM_HERE, closure); | 105 task_runner->PostTask(FROM_HERE, closure); |
| 91 } | 106 } |
| 92 | 107 |
| 93 protected: | 108 protected: |
| 94 void InitializeMemoryDumpManager(bool is_coordinator) { | 109 void InitializeMemoryDumpManager(bool is_coordinator) { |
| 110 mdm_->set_dumper_registrations_ignored_for_testing(true); |
| 95 mdm_->Initialize(delegate_.get(), is_coordinator); | 111 mdm_->Initialize(delegate_.get(), is_coordinator); |
| 96 } | 112 } |
| 97 | 113 |
| 98 void EnableTracingWithLegacyCategories(const char* category) { | 114 void EnableTracingWithLegacyCategories(const char* category) { |
| 99 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""), | 115 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""), |
| 100 TraceLog::RECORDING_MODE); | 116 TraceLog::RECORDING_MODE); |
| 101 } | 117 } |
| 102 | 118 |
| 103 void EnableTracingWithTraceConfig(const std::string& trace_config) { | 119 void EnableTracingWithTraceConfig(const std::string& trace_config) { |
| 104 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), | 120 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 | 140 |
| 125 // We want our singleton torn down after each test. | 141 // We want our singleton torn down after each test. |
| 126 ShadowingAtExitManager at_exit_manager_; | 142 ShadowingAtExitManager at_exit_manager_; |
| 127 }; | 143 }; |
| 128 | 144 |
| 129 // Basic sanity checks. Registers a memory dump provider and checks that it is | 145 // Basic sanity checks. Registers a memory dump provider and checks that it is |
| 130 // called, but only when memory-infra is enabled. | 146 // called, but only when memory-infra is enabled. |
| 131 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 147 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
| 132 InitializeMemoryDumpManager(false /* is_coordinator */); | 148 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 133 MockMemoryDumpProvider mdp; | 149 MockMemoryDumpProvider mdp; |
| 134 mdm_->RegisterDumpProvider(&mdp); | 150 RegisterDumpProvider(&mdp); |
| 135 | 151 |
| 136 // Check that the dumper is not called if the memory category is not enabled. | 152 // Check that the dumper is not called if the memory category is not enabled. |
| 137 EnableTracingWithLegacyCategories("foobar-but-not-memory"); | 153 EnableTracingWithLegacyCategories("foobar-but-not-memory"); |
| 138 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 154 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
| 139 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 155 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 140 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 156 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 141 MemoryDumpLevelOfDetail::DETAILED); | 157 MemoryDumpLevelOfDetail::DETAILED); |
| 142 DisableTracing(); | 158 DisableTracing(); |
| 143 | 159 |
| 144 // Now repeat enabling the memory category and check that the dumper is | 160 // Now repeat enabling the memory category and check that the dumper is |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 MemoryDumpLevelOfDetail::DETAILED); | 178 MemoryDumpLevelOfDetail::DETAILED); |
| 163 TraceLog::GetInstance()->SetDisabled(); | 179 TraceLog::GetInstance()->SetDisabled(); |
| 164 } | 180 } |
| 165 | 181 |
| 166 // Checks that requesting dumps with high level of detail actually propagates | 182 // Checks that requesting dumps with high level of detail actually propagates |
| 167 // the level of the detail properly to OnMemoryDump() call on dump providers. | 183 // the level of the detail properly to OnMemoryDump() call on dump providers. |
| 168 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 184 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
| 169 InitializeMemoryDumpManager(false /* is_coordinator */); | 185 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 170 MockMemoryDumpProvider mdp; | 186 MockMemoryDumpProvider mdp; |
| 171 | 187 |
| 172 mdm_->RegisterDumpProvider(&mdp); | 188 RegisterDumpProvider(&mdp); |
| 173 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 189 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 174 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 190 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 175 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); | 191 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); |
| 176 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 192 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 177 MemoryDumpLevelOfDetail::DETAILED); | 193 MemoryDumpLevelOfDetail::DETAILED); |
| 178 DisableTracing(); | 194 DisableTracing(); |
| 179 mdm_->UnregisterDumpProvider(&mdp); | 195 mdm_->UnregisterDumpProvider(&mdp); |
| 180 | 196 |
| 181 // Check that requesting dumps with low level of detail actually propagates to | 197 // Check that requesting dumps with low level of detail actually propagates to |
| 182 // OnMemoryDump() call on dump providers. | 198 // OnMemoryDump() call on dump providers. |
| 183 mdm_->RegisterDumpProvider(&mdp); | 199 RegisterDumpProvider(&mdp); |
| 184 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 200 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 185 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 201 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 186 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); | 202 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); |
| 187 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 203 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 188 MemoryDumpLevelOfDetail::LIGHT); | 204 MemoryDumpLevelOfDetail::LIGHT); |
| 189 DisableTracing(); | 205 DisableTracing(); |
| 190 mdm_->UnregisterDumpProvider(&mdp); | 206 mdm_->UnregisterDumpProvider(&mdp); |
| 191 } | 207 } |
| 192 | 208 |
| 193 // Checks that the SharedSessionState object is acqually shared over time. | 209 // Checks that the SharedSessionState object is acqually shared over time. |
| 194 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 210 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
| 195 InitializeMemoryDumpManager(false /* is_coordinator */); | 211 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 196 MockMemoryDumpProvider mdp1; | 212 MockMemoryDumpProvider mdp1; |
| 197 MockMemoryDumpProvider mdp2; | 213 MockMemoryDumpProvider mdp2; |
| 198 mdm_->RegisterDumpProvider(&mdp1); | 214 RegisterDumpProvider(&mdp1); |
| 199 mdm_->RegisterDumpProvider(&mdp2); | 215 RegisterDumpProvider(&mdp2); |
| 200 | 216 |
| 201 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 217 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 202 const MemoryDumpSessionState* session_state = mdm_->session_state().get(); | 218 const MemoryDumpSessionState* session_state = mdm_->session_state().get(); |
| 203 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 219 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); |
| 204 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 220 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 205 .Times(2) | 221 .Times(2) |
| 206 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 222 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
| 207 ProcessMemoryDump* pmd) -> bool { | 223 ProcessMemoryDump* pmd) -> bool { |
| 208 EXPECT_EQ(session_state, pmd->session_state().get()); | 224 EXPECT_EQ(session_state, pmd->session_state().get()); |
| 209 return true; | 225 return true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 223 DisableTracing(); | 239 DisableTracing(); |
| 224 } | 240 } |
| 225 | 241 |
| 226 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. | 242 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. |
| 227 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 243 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
| 228 InitializeMemoryDumpManager(false /* is_coordinator */); | 244 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 229 MockMemoryDumpProvider mdp1; | 245 MockMemoryDumpProvider mdp1; |
| 230 MockMemoryDumpProvider mdp2; | 246 MockMemoryDumpProvider mdp2; |
| 231 | 247 |
| 232 // Enable only mdp1. | 248 // Enable only mdp1. |
| 233 mdm_->RegisterDumpProvider(&mdp1); | 249 RegisterDumpProvider(&mdp1); |
| 234 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 250 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 235 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 251 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 252 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 237 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 253 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
| 238 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 254 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 239 MemoryDumpLevelOfDetail::DETAILED); | 255 MemoryDumpLevelOfDetail::DETAILED); |
| 240 DisableTracing(); | 256 DisableTracing(); |
| 241 | 257 |
| 242 // Invert: enable mdp1 and disable mdp2. | 258 // Invert: enable mdp1 and disable mdp2. |
| 243 mdm_->UnregisterDumpProvider(&mdp1); | 259 mdm_->UnregisterDumpProvider(&mdp1); |
| 244 mdm_->RegisterDumpProvider(&mdp2); | 260 RegisterDumpProvider(&mdp2); |
| 245 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 261 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 246 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 262 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 247 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 263 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
| 248 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 264 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 249 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 265 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 250 MemoryDumpLevelOfDetail::DETAILED); | 266 MemoryDumpLevelOfDetail::DETAILED); |
| 251 DisableTracing(); | 267 DisableTracing(); |
| 252 | 268 |
| 253 // Enable both mdp1 and mdp2. | 269 // Enable both mdp1 and mdp2. |
| 254 mdm_->RegisterDumpProvider(&mdp1); | 270 RegisterDumpProvider(&mdp1); |
| 255 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 271 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 256 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 272 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 257 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 273 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 258 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 274 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 259 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 275 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 260 MemoryDumpLevelOfDetail::DETAILED); | 276 MemoryDumpLevelOfDetail::DETAILED); |
| 261 DisableTracing(); | 277 DisableTracing(); |
| 262 } | 278 } |
| 263 | 279 |
| 264 // Checks that the dump provider invocations depend only on the current | 280 // Checks that the dump provider invocations depend only on the current |
| 265 // registration state and not on previous registrations and dumps. | 281 // registration state and not on previous registrations and dumps. |
| 266 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { | 282 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { |
| 267 InitializeMemoryDumpManager(false /* is_coordinator */); | 283 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 268 MockMemoryDumpProvider mdp; | 284 MockMemoryDumpProvider mdp; |
| 269 | 285 |
| 270 mdm_->RegisterDumpProvider(&mdp); | 286 RegisterDumpProvider(&mdp); |
| 271 | 287 |
| 272 { | 288 { |
| 273 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 289 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 274 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 290 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 275 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 291 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 276 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 292 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 277 MemoryDumpLevelOfDetail::DETAILED); | 293 MemoryDumpLevelOfDetail::DETAILED); |
| 278 DisableTracing(); | 294 DisableTracing(); |
| 279 } | 295 } |
| 280 | 296 |
| 281 mdm_->UnregisterDumpProvider(&mdp); | 297 mdm_->UnregisterDumpProvider(&mdp); |
| 282 | 298 |
| 283 { | 299 { |
| 284 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 300 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 285 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 301 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 286 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 302 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 287 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 303 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 288 MemoryDumpLevelOfDetail::DETAILED); | 304 MemoryDumpLevelOfDetail::DETAILED); |
| 289 DisableTracing(); | 305 DisableTracing(); |
| 290 } | 306 } |
| 291 | 307 |
| 292 mdm_->RegisterDumpProvider(&mdp); | 308 RegisterDumpProvider(&mdp); |
| 293 mdm_->UnregisterDumpProvider(&mdp); | 309 mdm_->UnregisterDumpProvider(&mdp); |
| 294 | 310 |
| 295 { | 311 { |
| 296 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 312 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 297 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 313 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 298 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 314 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 299 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 315 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 300 MemoryDumpLevelOfDetail::DETAILED); | 316 MemoryDumpLevelOfDetail::DETAILED); |
| 301 DisableTracing(); | 317 DisableTracing(); |
| 302 } | 318 } |
| 303 | 319 |
| 304 mdm_->RegisterDumpProvider(&mdp); | 320 RegisterDumpProvider(&mdp); |
| 305 mdm_->UnregisterDumpProvider(&mdp); | 321 mdm_->UnregisterDumpProvider(&mdp); |
| 306 mdm_->RegisterDumpProvider(&mdp); | 322 RegisterDumpProvider(&mdp); |
| 307 | 323 |
| 308 { | 324 { |
| 309 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 325 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 310 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 326 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 311 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 327 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 312 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 328 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 313 MemoryDumpLevelOfDetail::DETAILED); | 329 MemoryDumpLevelOfDetail::DETAILED); |
| 314 DisableTracing(); | 330 DisableTracing(); |
| 315 } | 331 } |
| 316 } | 332 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 329 // Create the threads and setup the expectations. Given that at each iteration | 345 // Create the threads and setup the expectations. Given that at each iteration |
| 330 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be | 346 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be |
| 331 // invoked a number of times equal to its index. | 347 // invoked a number of times equal to its index. |
| 332 for (uint32 i = kNumInitialThreads; i > 0; --i) { | 348 for (uint32 i = kNumInitialThreads; i > 0; --i) { |
| 333 Thread* thread = new Thread("test thread"); | 349 Thread* thread = new Thread("test thread"); |
| 334 threads.push_back(thread); | 350 threads.push_back(thread); |
| 335 threads.back()->Start(); | 351 threads.back()->Start(); |
| 336 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); | 352 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); |
| 337 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); | 353 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); |
| 338 mdps.push_back(mdp); | 354 mdps.push_back(mdp); |
| 339 mdm_->RegisterDumpProvider(mdp, task_runner); | 355 RegisterDumpProvider(mdp, task_runner); |
| 340 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 356 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
| 341 .Times(i) | 357 .Times(i) |
| 342 .WillRepeatedly(Invoke( | 358 .WillRepeatedly(Invoke( |
| 343 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 359 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 344 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 360 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
| 345 return true; | 361 return true; |
| 346 })); | 362 })); |
| 347 } | 363 } |
| 348 | 364 |
| 349 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 365 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 DisableTracing(); | 400 DisableTracing(); |
| 385 } | 401 } |
| 386 | 402 |
| 387 // Checks that providers get disabled after 3 consecutive failures, but not | 403 // Checks that providers get disabled after 3 consecutive failures, but not |
| 388 // otherwise (e.g., if interleaved). | 404 // otherwise (e.g., if interleaved). |
| 389 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { | 405 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
| 390 InitializeMemoryDumpManager(false /* is_coordinator */); | 406 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 391 MockMemoryDumpProvider mdp1; | 407 MockMemoryDumpProvider mdp1; |
| 392 MockMemoryDumpProvider mdp2; | 408 MockMemoryDumpProvider mdp2; |
| 393 | 409 |
| 394 mdm_->RegisterDumpProvider(&mdp1); | 410 RegisterDumpProvider(&mdp1); |
| 395 mdm_->RegisterDumpProvider(&mdp2); | 411 RegisterDumpProvider(&mdp2); |
| 396 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 412 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 397 | 413 |
| 398 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); | 414 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); |
| 399 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); | 415 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); |
| 400 | 416 |
| 401 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 417 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 402 .Times(GetMaxConsecutiveFailuresCount()) | 418 .Times(GetMaxConsecutiveFailuresCount()) |
| 403 .WillRepeatedly(Return(false)); | 419 .WillRepeatedly(Return(false)); |
| 404 | 420 |
| 405 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 421 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 418 DisableTracing(); | 434 DisableTracing(); |
| 419 } | 435 } |
| 420 | 436 |
| 421 // Sneakily registers an extra memory dump provider while an existing one is | 437 // Sneakily registers an extra memory dump provider while an existing one is |
| 422 // dumping and expect it to take part in the already active tracing session. | 438 // dumping and expect it to take part in the already active tracing session. |
| 423 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 439 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
| 424 InitializeMemoryDumpManager(false /* is_coordinator */); | 440 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 425 MockMemoryDumpProvider mdp1; | 441 MockMemoryDumpProvider mdp1; |
| 426 MockMemoryDumpProvider mdp2; | 442 MockMemoryDumpProvider mdp2; |
| 427 | 443 |
| 428 mdm_->RegisterDumpProvider(&mdp1); | 444 RegisterDumpProvider(&mdp1); |
| 429 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 445 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 430 | 446 |
| 431 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 447 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); |
| 432 | 448 |
| 433 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 449 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 434 .Times(4) | 450 .Times(4) |
| 435 .WillOnce(Return(true)) | 451 .WillOnce(Return(true)) |
| 436 .WillOnce( | 452 .WillOnce( |
| 437 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 453 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 438 MemoryDumpManager::GetInstance()->RegisterDumpProvider(&mdp2); | 454 RegisterDumpProvider(&mdp2); |
| 439 return true; | 455 return true; |
| 440 })) | 456 })) |
| 441 .WillRepeatedly(Return(true)); | 457 .WillRepeatedly(Return(true)); |
| 442 | 458 |
| 443 // Depending on the insertion order (before or after mdp1), mdp2 might be | 459 // Depending on the insertion order (before or after mdp1), mdp2 might be |
| 444 // called also immediately after it gets registered. | 460 // called also immediately after it gets registered. |
| 445 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 461 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
| 446 .Times(Between(2, 3)) | 462 .Times(Between(2, 3)) |
| 447 .WillRepeatedly(Return(true)); | 463 .WillRepeatedly(Return(true)); |
| 448 | 464 |
| 449 for (int i = 0; i < 4; i++) { | 465 for (int i = 0; i < 4; i++) { |
| 450 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 466 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 451 MemoryDumpLevelOfDetail::DETAILED); | 467 MemoryDumpLevelOfDetail::DETAILED); |
| 452 } | 468 } |
| 453 | 469 |
| 454 DisableTracing(); | 470 DisableTracing(); |
| 455 } | 471 } |
| 456 | 472 |
| 457 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. | 473 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. |
| 458 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 474 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
| 459 InitializeMemoryDumpManager(false /* is_coordinator */); | 475 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 460 MockMemoryDumpProvider mdp1; | 476 MockMemoryDumpProvider mdp1; |
| 461 MockMemoryDumpProvider mdp2; | 477 MockMemoryDumpProvider mdp2; |
| 462 | 478 |
| 463 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); | 479 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
| 464 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); | 480 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); |
| 465 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 481 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 466 | 482 |
| 467 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 483 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); |
| 468 | 484 |
| 469 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 485 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 470 .Times(4) | 486 .Times(4) |
| 471 .WillOnce(Return(true)) | 487 .WillOnce(Return(true)) |
| 472 .WillOnce( | 488 .WillOnce( |
| 473 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 489 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 474 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); | 490 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 493 // Checks that the dump does not abort when unregistering a provider while | 509 // Checks that the dump does not abort when unregistering a provider while |
| 494 // dumping from a different thread than the dumping thread. | 510 // dumping from a different thread than the dumping thread. |
| 495 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { | 511 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { |
| 496 InitializeMemoryDumpManager(false /* is_coordinator */); | 512 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 497 ScopedVector<TestIOThread> threads; | 513 ScopedVector<TestIOThread> threads; |
| 498 ScopedVector<MockMemoryDumpProvider> mdps; | 514 ScopedVector<MockMemoryDumpProvider> mdps; |
| 499 | 515 |
| 500 for (int i = 0; i < 2; i++) { | 516 for (int i = 0; i < 2; i++) { |
| 501 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); | 517 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); |
| 502 mdps.push_back(new MockMemoryDumpProvider()); | 518 mdps.push_back(new MockMemoryDumpProvider()); |
| 503 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); | 519 RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); |
| 504 } | 520 } |
| 505 | 521 |
| 506 int on_memory_dump_call_count = 0; | 522 int on_memory_dump_call_count = 0; |
| 507 RunLoop run_loop; | 523 RunLoop run_loop; |
| 508 | 524 |
| 509 // When OnMemoryDump is called on either of the dump providers, it will | 525 // When OnMemoryDump is called on either of the dump providers, it will |
| 510 // unregister the other one. | 526 // unregister the other one. |
| 511 for (MockMemoryDumpProvider* mdp : mdps) { | 527 for (MockMemoryDumpProvider* mdp : mdps) { |
| 512 int other_idx = (mdps.front() == mdp); | 528 int other_idx = (mdps.front() == mdp); |
| 513 TestIOThread* other_thread = threads[other_idx]; | 529 TestIOThread* other_thread = threads[other_idx]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 ASSERT_EQ(true, last_callback_success_); | 561 ASSERT_EQ(true, last_callback_success_); |
| 546 | 562 |
| 547 DisableTracing(); | 563 DisableTracing(); |
| 548 } | 564 } |
| 549 | 565 |
| 550 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when | 566 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when |
| 551 // tracing is not enabled. | 567 // tracing is not enabled. |
| 552 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 568 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
| 553 InitializeMemoryDumpManager(false /* is_coordinator */); | 569 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 554 MockMemoryDumpProvider mdp1; | 570 MockMemoryDumpProvider mdp1; |
| 555 mdm_->RegisterDumpProvider(&mdp1); | 571 RegisterDumpProvider(&mdp1); |
| 556 | 572 |
| 557 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 573 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
| 558 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 574 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
| 559 | 575 |
| 560 last_callback_success_ = true; | 576 last_callback_success_ = true; |
| 561 { | 577 { |
| 562 RunLoop run_loop; | 578 RunLoop run_loop; |
| 563 MemoryDumpCallback callback = | 579 MemoryDumpCallback callback = |
| 564 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 580 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
| 565 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 581 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
| 566 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 582 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 567 MemoryDumpLevelOfDetail::DETAILED, callback); | 583 MemoryDumpLevelOfDetail::DETAILED, callback); |
| 568 run_loop.Run(); | 584 run_loop.Run(); |
| 569 } | 585 } |
| 570 EXPECT_FALSE(last_callback_success_); | 586 EXPECT_FALSE(last_callback_success_); |
| 571 } | 587 } |
| 572 | 588 |
| 573 // Checks that is the MemoryDumpManager is initialized after tracing already | 589 // Checks that is the MemoryDumpManager is initialized after tracing already |
| 574 // began, it will still late-join the party (real use case: startup tracing). | 590 // began, it will still late-join the party (real use case: startup tracing). |
| 575 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { | 591 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { |
| 576 MockMemoryDumpProvider mdp; | 592 MockMemoryDumpProvider mdp; |
| 577 mdm_->RegisterDumpProvider(&mdp); | 593 RegisterDumpProvider(&mdp); |
| 578 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 594 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 579 | 595 |
| 580 // First check that a RequestGlobalDump() issued before the MemoryDumpManager | 596 // First check that a RequestGlobalDump() issued before the MemoryDumpManager |
| 581 // initialization gets NACK-ed cleanly. | 597 // initialization gets NACK-ed cleanly. |
| 582 { | 598 { |
| 583 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 599 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 584 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 600 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
| 585 RunLoop run_loop; | 601 RunLoop run_loop; |
| 586 MemoryDumpCallback callback = | 602 MemoryDumpCallback callback = |
| 587 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 603 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 713 |
| 698 EnableTracingWithTraceConfig( | 714 EnableTracingWithTraceConfig( |
| 699 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( | 715 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( |
| 700 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); | 716 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); |
| 701 run_loop.Run(); | 717 run_loop.Run(); |
| 702 DisableTracing(); | 718 DisableTracing(); |
| 703 } | 719 } |
| 704 | 720 |
| 705 } // namespace trace_event | 721 } // namespace trace_event |
| 706 } // namespace base | 722 } // namespace base |
| OLD | NEW |