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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 // GTest matchers for MemoryDumpRequestArgs arguments. | 42 // GTest matchers for MemoryDumpRequestArgs arguments. |
43 MATCHER(IsDetailedDump, "") { | 43 MATCHER(IsDetailedDump, "") { |
44 return arg.level_of_detail == MemoryDumpLevelOfDetail::DETAILED; | 44 return arg.level_of_detail == MemoryDumpLevelOfDetail::DETAILED; |
45 } | 45 } |
46 | 46 |
47 MATCHER(IsLightDump, "") { | 47 MATCHER(IsLightDump, "") { |
48 return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT; | 48 return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT; |
49 } | 49 } |
50 | 50 |
| 51 MATCHER(IsBackgroundDump, "") { |
| 52 return arg.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND; |
| 53 } |
| 54 |
51 namespace { | 55 namespace { |
52 | 56 |
| 57 const char* kMDPName = "TestDumpProvider"; |
| 58 const char* kWhitelistedMDPName = "WhitelistedTestDumpProvider"; |
| 59 const char* const kTestMDPWhitelist[] = {kWhitelistedMDPName, nullptr}; |
| 60 |
53 void RegisterDumpProvider( | 61 void RegisterDumpProvider( |
54 MemoryDumpProvider* mdp, | 62 MemoryDumpProvider* mdp, |
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
56 const MemoryDumpProvider::Options& options) { | 64 const MemoryDumpProvider::Options& options, |
| 65 const char* name = kMDPName) { |
57 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); | 66 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
58 mdm->set_dumper_registrations_ignored_for_testing(false); | 67 mdm->set_dumper_registrations_ignored_for_testing(false); |
59 const char* kMDPName = "TestDumpProvider"; | 68 mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options); |
60 mdm->RegisterDumpProvider(mdp, kMDPName, std::move(task_runner), options); | |
61 mdm->set_dumper_registrations_ignored_for_testing(true); | 69 mdm->set_dumper_registrations_ignored_for_testing(true); |
62 } | 70 } |
63 | 71 |
64 void RegisterDumpProvider(MemoryDumpProvider* mdp) { | 72 void RegisterDumpProvider(MemoryDumpProvider* mdp) { |
65 RegisterDumpProvider(mdp, nullptr, MemoryDumpProvider::Options()); | 73 RegisterDumpProvider(mdp, nullptr, MemoryDumpProvider::Options()); |
66 } | 74 } |
67 | 75 |
68 void RegisterDumpProviderWithSequencedTaskRunner( | 76 void RegisterDumpProviderWithSequencedTaskRunner( |
69 MemoryDumpProvider* mdp, | 77 MemoryDumpProvider* mdp, |
70 scoped_refptr<base::SequencedTaskRunner> task_runner, | 78 scoped_refptr<base::SequencedTaskRunner> task_runner, |
71 const MemoryDumpProvider::Options& options) { | 79 const MemoryDumpProvider::Options& options) { |
72 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); | 80 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
73 mdm->set_dumper_registrations_ignored_for_testing(false); | 81 mdm->set_dumper_registrations_ignored_for_testing(false); |
74 const char* kMDPName = "TestDumpProvider"; | |
75 mdm->RegisterDumpProviderWithSequencedTaskRunner(mdp, kMDPName, task_runner, | 82 mdm->RegisterDumpProviderWithSequencedTaskRunner(mdp, kMDPName, task_runner, |
76 options); | 83 options); |
77 mdm->set_dumper_registrations_ignored_for_testing(true); | 84 mdm->set_dumper_registrations_ignored_for_testing(true); |
78 } | 85 } |
79 | 86 |
80 void OnTraceDataCollected(Closure quit_closure, | 87 void OnTraceDataCollected(Closure quit_closure, |
81 trace_event::TraceResultBuffer* buffer, | 88 trace_event::TraceResultBuffer* buffer, |
82 const scoped_refptr<RefCountedString>& json, | 89 const scoped_refptr<RefCountedString>& json, |
83 bool has_more_events) { | 90 bool has_more_events) { |
84 buffer->AddFragment(json->data()); | 91 buffer->AddFragment(json->data()); |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1099 |
1093 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1100 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1094 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 1101 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); |
1095 for (int i = 0; i < 2; ++i) { | 1102 for (int i = 0; i < 2; ++i) { |
1096 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1103 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1097 MemoryDumpLevelOfDetail::DETAILED); | 1104 MemoryDumpLevelOfDetail::DETAILED); |
1098 } | 1105 } |
1099 DisableTracing(); | 1106 DisableTracing(); |
1100 } | 1107 } |
1101 | 1108 |
| 1109 TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { |
| 1110 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1111 mdm_->set_dump_provider_whitelist_for_testing(kTestMDPWhitelist); |
| 1112 std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); |
| 1113 RegisterDumpProvider(mdp1.get()); |
| 1114 std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); |
| 1115 RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, |
| 1116 kWhitelistedMDPName); |
| 1117 |
| 1118 EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); |
| 1119 EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); |
| 1120 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 1121 |
| 1122 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1123 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
| 1124 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1125 MemoryDumpLevelOfDetail::BACKGROUND); |
| 1126 DisableTracing(); |
| 1127 } |
| 1128 |
| 1129 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
| 1130 InitializeMemoryDumpManager(true /* is_coordinator */); |
| 1131 |
| 1132 RunLoop run_loop; |
| 1133 auto quit_closure = run_loop.QuitClosure(); |
| 1134 |
| 1135 testing::InSequence sequence; |
| 1136 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
| 1137 .Times(5); |
| 1138 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
| 1139 .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args, |
| 1140 const MemoryDumpCallback& callback) { |
| 1141 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); |
| 1142 })); |
| 1143 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); |
| 1144 |
| 1145 EnableTracingWithTraceConfig( |
| 1146 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger()); |
| 1147 ASSERT_TRUE(IsPeriodicDumpingEnabled()); |
| 1148 run_loop.Run(); |
| 1149 DisableTracing(); |
| 1150 } |
| 1151 |
1102 } // namespace trace_event | 1152 } // namespace trace_event |
1103 } // namespace base | 1153 } // namespace base |
OLD | NEW |