| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 MATCHER(IsBackgroundDump, "") { | 58 MATCHER(IsBackgroundDump, "") { |
| 59 return arg.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND; | 59 return arg.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND; |
| 60 } | 60 } |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 const char* kMDPName = "TestDumpProvider"; | 64 const char* kMDPName = "TestDumpProvider"; |
| 65 const char* kWhitelistedMDPName = "WhitelistedTestDumpProvider"; | 65 const char* kWhitelistedMDPName = "WhitelistedTestDumpProvider"; |
| 66 const char* const kTestMDPWhitelist[] = {kWhitelistedMDPName, nullptr}; | 66 const char* const kTestMDPWhitelist[] = {kWhitelistedMDPName, nullptr}; |
| 67 const char* const kTestMDPWhitelistForSummary[] = {kWhitelistedMDPName, |
| 68 nullptr}; |
| 67 | 69 |
| 68 void RegisterDumpProvider( | 70 void RegisterDumpProvider( |
| 69 MemoryDumpProvider* mdp, | 71 MemoryDumpProvider* mdp, |
| 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 71 const MemoryDumpProvider::Options& options, | 73 const MemoryDumpProvider::Options& options, |
| 72 const char* name = kMDPName) { | 74 const char* name = kMDPName) { |
| 73 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); | 75 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); |
| 74 mdm->set_dumper_registrations_ignored_for_testing(false); | 76 mdm->set_dumper_registrations_ignored_for_testing(false); |
| 75 mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options); | 77 mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options); |
| 76 mdm->set_dumper_registrations_ignored_for_testing(true); | 78 mdm->set_dumper_registrations_ignored_for_testing(true); |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 | 1076 |
| 1075 ASSERT_EQ(3u, events.size()); | 1077 ASSERT_EQ(3u, events.size()); |
| 1076 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); | 1078 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); |
| 1077 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); | 1079 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); |
| 1078 ASSERT_EQ(1u, trace_analyzer::CountMatches( | 1080 ASSERT_EQ(1u, trace_analyzer::CountMatches( |
| 1079 events, Query::EventPidIs(GetCurrentProcId()))); | 1081 events, Query::EventPidIs(GetCurrentProcId()))); |
| 1080 ASSERT_EQ(events[0]->id, events[1]->id); | 1082 ASSERT_EQ(events[0]->id, events[1]->id); |
| 1081 ASSERT_EQ(events[0]->id, events[2]->id); | 1083 ASSERT_EQ(events[0]->id, events[2]->id); |
| 1082 } | 1084 } |
| 1083 | 1085 |
| 1086 TEST_F(MemoryDumpManagerTest, TestSummaryWhitelisting) { |
| 1087 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1088 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); |
| 1089 |
| 1090 // Standard provider with default options (create dump for current process). |
| 1091 MockMemoryDumpProvider mdp; |
| 1092 RegisterDumpProvider(&mdp, nullptr, kDefaultOptions, kWhitelistedMDPName); |
| 1093 |
| 1094 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1095 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 1096 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 1097 RequestGlobalDumpAndWait(MemoryDumpType::SUMMARY_ONLY, |
| 1098 MemoryDumpLevelOfDetail::BACKGROUND); |
| 1099 DisableTracing(); |
| 1100 } |
| 1101 |
| 1084 TEST_F(MemoryDumpManagerTest, SummaryOnlyDumpsArentAddedToTrace) { | 1102 TEST_F(MemoryDumpManagerTest, SummaryOnlyDumpsArentAddedToTrace) { |
| 1085 using trace_analyzer::Query; | 1103 using trace_analyzer::Query; |
| 1086 | 1104 |
| 1087 InitializeMemoryDumpManager(false /* is_coordinator */); | 1105 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1106 SetDumpProviderSummaryWhitelistForTesting(kTestMDPWhitelistForSummary); |
| 1088 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); | 1107 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); |
| 1089 | 1108 |
| 1090 // Standard provider with default options (create dump for current process). | 1109 // Standard provider with default options (create dump for current process). |
| 1091 MockMemoryDumpProvider mdp; | 1110 MockMemoryDumpProvider mdp; |
| 1092 RegisterDumpProvider(&mdp, nullptr, kDefaultOptions, kWhitelistedMDPName); | 1111 RegisterDumpProvider(&mdp, nullptr, kDefaultOptions, kWhitelistedMDPName); |
| 1093 | 1112 |
| 1094 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1113 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1095 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); | 1114 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
| 1096 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(2).WillRepeatedly(Return(true)); | 1115 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(2).WillRepeatedly(Return(true)); |
| 1097 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1116 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb); | 1393 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb); |
| 1375 // partition_alloc has partition_alloc/allocated_objects/* which is a subset | 1394 // partition_alloc has partition_alloc/allocated_objects/* which is a subset |
| 1376 // of partition_alloc/partitions/* so we only count the latter. | 1395 // of partition_alloc/partitions/* so we only count the latter. |
| 1377 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb); | 1396 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb); |
| 1378 // resident_set_kb should read from process_totals. | 1397 // resident_set_kb should read from process_totals. |
| 1379 EXPECT_EQ(5u, result.os_dump.resident_set_kb); | 1398 EXPECT_EQ(5u, result.os_dump.resident_set_kb); |
| 1380 }; | 1399 }; |
| 1381 | 1400 |
| 1382 } // namespace trace_event | 1401 } // namespace trace_event |
| 1383 } // namespace base | 1402 } // namespace base |
| OLD | NEW |