Chromium Code Reviews| 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 <utility> | 10 #include <utility> |
| (...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1102 | 1102 |
| 1103 ASSERT_EQ(3u, events.size()); | 1103 ASSERT_EQ(3u, events.size()); |
| 1104 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); | 1104 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); |
| 1105 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); | 1105 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); |
| 1106 ASSERT_EQ(1u, trace_analyzer::CountMatches( | 1106 ASSERT_EQ(1u, trace_analyzer::CountMatches( |
| 1107 events, Query::EventPidIs(GetCurrentProcId()))); | 1107 events, Query::EventPidIs(GetCurrentProcId()))); |
| 1108 ASSERT_EQ(events[0]->id, events[1]->id); | 1108 ASSERT_EQ(events[0]->id, events[1]->id); |
| 1109 ASSERT_EQ(events[0]->id, events[2]->id); | 1109 ASSERT_EQ(events[0]->id, events[2]->id); |
| 1110 } | 1110 } |
| 1111 | 1111 |
| 1112 TEST_F(MemoryDumpManagerTest, SummaryOnlyDumpsArentAddedToTrace) { | |
| 1113 using trace_analyzer::Query; | |
| 1114 | |
| 1115 InitializeMemoryDumpManager(false /* is_coordinator */); | |
| 1116 | |
| 1117 // Standard provider with default options (create dump for current process). | |
| 1118 MemoryDumpProvider::Options options; | |
| 1119 MockMemoryDumpProvider mdp; | |
| 1120 RegisterDumpProvider(&mdp, nullptr, options); | |
| 1121 | |
| 1122 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | |
| 1123 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | |
| 1124 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(2).WillRepeatedly(Return(true)); | |
| 1125 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | |
| 1126 MemoryDumpLevelOfDetail::DETAILED); | |
|
Primiano Tucci (use gerrit)
2017/04/25 18:02:22
i'd s/DETAILED/BACKGROUND/ just in case in future
hjd
2017/04/26 11:11:58
Done.
| |
| 1127 RequestGlobalDumpAndWait(MemoryDumpType::SUMMARY_ONLY, | |
| 1128 MemoryDumpLevelOfDetail::DETAILED); | |
| 1129 DisableTracing(); | |
| 1130 | |
| 1131 // Flush the trace into JSON. | |
| 1132 trace_event::TraceResultBuffer buffer; | |
|
Primiano Tucci (use gerrit)
2017/04/25 18:02:22
maybe you can factor this and the one in DumpOnBeh
hjd
2017/04/26 11:11:58
Done.
| |
| 1133 TraceResultBuffer::SimpleOutput trace_output; | |
| 1134 buffer.SetOutputCallback(trace_output.GetCallback()); | |
| 1135 RunLoop run_loop; | |
| 1136 buffer.Start(); | |
| 1137 trace_event::TraceLog::GetInstance()->Flush( | |
| 1138 Bind(&OnTraceDataCollected, run_loop.QuitClosure(), Unretained(&buffer))); | |
| 1139 run_loop.Run(); | |
| 1140 buffer.Finish(); | |
| 1141 | |
| 1142 // Analyze the JSON. | |
| 1143 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer = WrapUnique( | |
| 1144 trace_analyzer::TraceAnalyzer::Create(trace_output.json_output)); | |
| 1145 trace_analyzer::TraceEventVector events; | |
| 1146 analyzer->FindEvents(Query::EventPhaseIs(TRACE_EVENT_PHASE_MEMORY_DUMP), | |
| 1147 &events); | |
| 1148 | |
| 1149 ASSERT_EQ(1u, events.size()); | |
| 1150 ASSERT_EQ(1u, trace_analyzer::CountMatches( | |
|
Primiano Tucci (use gerrit)
2017/04/25 18:02:22
I'd replace this with
ASSERT_TRUE(trace_analyzer:
hjd
2017/04/26 11:11:58
Done.
| |
| 1151 events, Query::EventPidIs(GetCurrentProcId()))); | |
| 1152 } | |
| 1153 | |
| 1112 // Tests the basics of the UnregisterAndDeleteDumpProviderSoon(): the | 1154 // Tests the basics of the UnregisterAndDeleteDumpProviderSoon(): the |
| 1113 // unregistration should actually delete the providers and not leak them. | 1155 // unregistration should actually delete the providers and not leak them. |
| 1114 TEST_F(MemoryDumpManagerTest, UnregisterAndDeleteDumpProviderSoon) { | 1156 TEST_F(MemoryDumpManagerTest, UnregisterAndDeleteDumpProviderSoon) { |
| 1115 InitializeMemoryDumpManager(false /* is_coordinator */); | 1157 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1116 static const int kNumProviders = 3; | 1158 static const int kNumProviders = 3; |
| 1117 int dtor_count = 0; | 1159 int dtor_count = 0; |
| 1118 std::vector<std::unique_ptr<MemoryDumpProvider>> mdps; | 1160 std::vector<std::unique_ptr<MemoryDumpProvider>> mdps; |
| 1119 for (int i = 0; i < kNumProviders; ++i) { | 1161 for (int i = 0; i < kNumProviders; ++i) { |
| 1120 std::unique_ptr<MockMemoryDumpProvider> mdp(new MockMemoryDumpProvider); | 1162 std::unique_ptr<MockMemoryDumpProvider> mdp(new MockMemoryDumpProvider); |
| 1121 mdp->enable_mock_destructor = true; | 1163 mdp->enable_mock_destructor = true; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1276 // successful we also managed to add the dump to the trace. | 1318 // successful we also managed to add the dump to the trace. |
| 1277 EXPECT_FALSE(last_callback_success_); | 1319 EXPECT_FALSE(last_callback_success_); |
| 1278 | 1320 |
| 1279 mdm_->Disable(); | 1321 mdm_->Disable(); |
| 1280 | 1322 |
| 1281 mdm_->UnregisterDumpProvider(&mdp); | 1323 mdm_->UnregisterDumpProvider(&mdp); |
| 1282 } | 1324 } |
| 1283 | 1325 |
| 1284 } // namespace trace_event | 1326 } // namespace trace_event |
| 1285 } // namespace base | 1327 } // namespace base |
| OLD | NEW |