Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 2778313002: [memory-infra] Move periodic timer to dump thread
Patch Set: nits. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/memory_dump_scheduler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 TraceLog::RECORDING_MODE); 267 TraceLog::RECORDING_MODE);
268 } 268 }
269 269
270 void EnableTracingWithTraceConfig(const std::string& trace_config) { 270 void EnableTracingWithTraceConfig(const std::string& trace_config) {
271 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), 271 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config),
272 TraceLog::RECORDING_MODE); 272 TraceLog::RECORDING_MODE);
273 } 273 }
274 274
275 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } 275 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
276 276
277 void DisablePeriodicTimerForTesting(bool disable) {
278 MemoryDumpScheduler::GetInstance()->DisablePeriodicTimerForTesting(disable);
279 }
280
277 bool IsPeriodicDumpingEnabled() const { 281 bool IsPeriodicDumpingEnabled() const {
278 return MemoryDumpScheduler::GetInstance() 282 return MemoryDumpScheduler::GetInstance()
279 ->IsPeriodicTimerRunningForTesting(); 283 ->IsPeriodicTimerRunningForTesting();
280 } 284 }
281 285
282 int GetMaxConsecutiveFailuresCount() const { 286 int GetMaxConsecutiveFailuresCount() const {
283 return MemoryDumpManager::kMaxConsecutiveFailuresCount; 287 return MemoryDumpManager::kMaxConsecutiveFailuresCount;
284 } 288 }
285 289
286 const MemoryDumpProvider::Options kDefaultOptions; 290 const MemoryDumpProvider::Options kDefaultOptions;
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); 949 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5));
946 EXPECT_FALSE(IsPeriodicDumpingEnabled()); 950 EXPECT_FALSE(IsPeriodicDumpingEnabled());
947 DisableTracing(); 951 DisableTracing();
948 } 952 }
949 953
950 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { 954 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) {
951 InitializeMemoryDumpManager(true /* is_coordinator */); 955 InitializeMemoryDumpManager(true /* is_coordinator */);
952 MemoryDumpManagerDelegateForTesting& delegate = *delegate_; 956 MemoryDumpManagerDelegateForTesting& delegate = *delegate_;
953 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return()); 957 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return());
954 958
959 // Disable timer to avoid post tasks.
960 DisablePeriodicTimerForTesting(true);
961
955 // Enabling memory-infra with the legacy TraceConfig (category filter) in 962 // Enabling memory-infra with the legacy TraceConfig (category filter) in
956 // a coordinator process should enable periodic dumps. 963 // a coordinator process should enable periodic dumps.
957 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 964 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
958 EXPECT_TRUE(IsPeriodicDumpingEnabled()); 965 EXPECT_TRUE(IsPeriodicDumpingEnabled());
959 DisableTracing(); 966 DisableTracing();
960 967
961 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator 968 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator
962 // process without specifying any "memory_dump_config" section should enable 969 // process without specifying any "memory_dump_config" section should enable
963 // periodic dumps. This is to preserve the behavior chrome://tracing UI, that 970 // periodic dumps. This is to preserve the behavior chrome://tracing UI, that
964 // is: ticking memory-infra should dump periodically with the default config. 971 // is: ticking memory-infra should dump periodically with the default config.
965 EnableTracingWithTraceConfig( 972 EnableTracingWithTraceConfig(
966 TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers()); 973 TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers());
967 EXPECT_TRUE(IsPeriodicDumpingEnabled()); 974 EXPECT_TRUE(IsPeriodicDumpingEnabled());
968 DisableTracing(); 975 DisableTracing();
969 976
970 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator 977 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator
971 // process with an empty "memory_dump_config" should NOT enable periodic 978 // process with an empty "memory_dump_config" should NOT enable periodic
972 // dumps. This is the way telemetry is supposed to use memory-infra with 979 // dumps. This is the way telemetry is supposed to use memory-infra with
973 // only explicitly triggered dumps. 980 // only explicitly triggered dumps.
974 EnableTracingWithTraceConfig( 981 EnableTracingWithTraceConfig(
975 TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers()); 982 TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers());
976 EXPECT_FALSE(IsPeriodicDumpingEnabled()); 983 EXPECT_FALSE(IsPeriodicDumpingEnabled());
977 DisableTracing(); 984 DisableTracing();
978 985
986 DisablePeriodicTimerForTesting(false);
987
979 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator 988 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator
980 // process with a fully defined trigger config should cause periodic dumps to 989 // process with a fully defined trigger config should cause periodic dumps to
981 // be performed in the correct order. 990 // be performed in the correct order.
982 RunLoop run_loop; 991 RunLoop run_loop;
983 auto quit_closure = run_loop.QuitClosure(); 992 auto quit_closure = run_loop.QuitClosure();
993 auto run_loop_task_runner = ThreadTaskRunnerHandle::Get();
984 994
985 const int kHeavyDumpRate = 5; 995 const int kHeavyDumpRate = 5;
986 const int kLightDumpPeriodMs = 1; 996 const int kLightDumpPeriodMs = 1;
987 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; 997 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs;
988 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... 998 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,...
989 testing::InSequence sequence; 999 testing::InSequence sequence;
990 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); 1000 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _));
991 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) 1001 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
992 .Times(kHeavyDumpRate - 1); 1002 .Times(kHeavyDumpRate - 1);
993 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); 1003 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _));
994 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) 1004 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
995 .Times(kHeavyDumpRate - 2); 1005 .Times(kHeavyDumpRate - 2);
996 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) 1006 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
997 .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args, 1007 .WillOnce(Invoke([quit_closure, run_loop_task_runner](
998 const MemoryDumpCallback& callback) { 1008 const MemoryDumpRequestArgs& args,
999 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); 1009 const MemoryDumpCallback& callback) {
1010 run_loop_task_runner->PostTask(FROM_HERE, quit_closure);
1000 })); 1011 }));
1001 1012
1002 // Swallow all the final spurious calls until tracing gets disabled. 1013 // Swallow all the final spurious calls until tracing gets disabled.
1003 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); 1014 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber());
1004 1015
1005 EnableTracingWithTraceConfig( 1016 EnableTracingWithTraceConfig(
1006 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( 1017 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(
1007 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); 1018 kLightDumpPeriodMs, kHeavyDumpPeriodMs));
1008 run_loop.Run(); 1019 run_loop.Run();
1009 DisableTracing(); 1020 DisableTracing();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 1249 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
1239 MemoryDumpLevelOfDetail::BACKGROUND); 1250 MemoryDumpLevelOfDetail::BACKGROUND);
1240 DisableTracing(); 1251 DisableTracing();
1241 } 1252 }
1242 1253
1243 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { 1254 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) {
1244 InitializeMemoryDumpManager(true /* is_coordinator */); 1255 InitializeMemoryDumpManager(true /* is_coordinator */);
1245 1256
1246 RunLoop run_loop; 1257 RunLoop run_loop;
1247 auto quit_closure = run_loop.QuitClosure(); 1258 auto quit_closure = run_loop.QuitClosure();
1259 auto run_loop_task_runner = ThreadTaskRunnerHandle::Get();
1248 1260
1249 testing::InSequence sequence; 1261 testing::InSequence sequence;
1250 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) 1262 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _))
1251 .Times(5); 1263 .Times(5);
1252 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) 1264 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _))
1253 .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args, 1265 .WillOnce(Invoke([quit_closure, run_loop_task_runner](
1254 const MemoryDumpCallback& callback) { 1266 const MemoryDumpRequestArgs& args,
1255 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); 1267 const MemoryDumpCallback& callback) {
1268 run_loop_task_runner->PostTask(FROM_HERE, quit_closure);
1256 })); 1269 }));
1257 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); 1270 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber());
1258 1271
1259 EnableTracingWithTraceConfig( 1272 EnableTracingWithTraceConfig(
1260 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( 1273 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger(
1261 1 /* period_ms */)); 1274 1 /* period_ms */));
1262 1275
1263 // Only background mode dumps should be allowed with the trace config. 1276 // Only background mode dumps should be allowed with the trace config.
1264 last_callback_success_ = false; 1277 last_callback_success_ = false;
1265 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 1278 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
(...skipping 21 matching lines...) Expand all
1287 thread.Start(); 1300 thread.Start();
1288 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, 1301 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions,
1289 "BlacklistTestDumpProvider"); 1302 "BlacklistTestDumpProvider");
1290 // Unregistering on wrong thread should not crash. 1303 // Unregistering on wrong thread should not crash.
1291 mdm_->UnregisterDumpProvider(&mdp1); 1304 mdm_->UnregisterDumpProvider(&mdp1);
1292 thread.Stop(); 1305 thread.Stop();
1293 } 1306 }
1294 1307
1295 } // namespace trace_event 1308 } // namespace trace_event
1296 } // namespace base 1309 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/memory_dump_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698