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

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

Issue 2876543002: memory-infra: Don't invoke all dump providers in SUMMARY_ONLY mode (Closed)
Patch Set: address comments Created 3 years, 7 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 | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider_info.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 <utility> 10 #include <utility>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
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* kBackgroundButNotSummaryWhitelistedMDPName =
67 "BackgroundButNotSummaryWhitelistedTestDumpProvider";
68 const char* const kTestMDPWhitelist[] = {
69 kWhitelistedMDPName, kBackgroundButNotSummaryWhitelistedMDPName, nullptr};
70 const char* const kTestMDPWhitelistForSummary[] = {kWhitelistedMDPName,
71 nullptr};
67 72
68 void RegisterDumpProvider( 73 void RegisterDumpProvider(
69 MemoryDumpProvider* mdp, 74 MemoryDumpProvider* mdp,
70 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
71 const MemoryDumpProvider::Options& options, 76 const MemoryDumpProvider::Options& options,
72 const char* name = kMDPName) { 77 const char* name = kMDPName) {
73 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance(); 78 MemoryDumpManager* mdm = MemoryDumpManager::GetInstance();
74 mdm->set_dumper_registrations_ignored_for_testing(false); 79 mdm->set_dumper_registrations_ignored_for_testing(false);
75 mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options); 80 mdm->RegisterDumpProvider(mdp, name, std::move(task_runner), options);
76 mdm->set_dumper_registrations_ignored_for_testing(true); 81 mdm->set_dumper_registrations_ignored_for_testing(true);
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1079
1075 ASSERT_EQ(3u, events.size()); 1080 ASSERT_EQ(3u, events.size());
1076 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); 1081 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123)));
1077 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); 1082 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456)));
1078 ASSERT_EQ(1u, trace_analyzer::CountMatches( 1083 ASSERT_EQ(1u, trace_analyzer::CountMatches(
1079 events, Query::EventPidIs(GetCurrentProcId()))); 1084 events, Query::EventPidIs(GetCurrentProcId())));
1080 ASSERT_EQ(events[0]->id, events[1]->id); 1085 ASSERT_EQ(events[0]->id, events[1]->id);
1081 ASSERT_EQ(events[0]->id, events[2]->id); 1086 ASSERT_EQ(events[0]->id, events[2]->id);
1082 } 1087 }
1083 1088
1089 TEST_F(MemoryDumpManagerTest, SummaryOnlyWhitelisting) {
1090 InitializeMemoryDumpManager(false /* is_coordinator */);
1091 // Summary only MDPs are a subset of background MDPs.
1092 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist);
1093 SetDumpProviderSummaryWhitelistForTesting(kTestMDPWhitelistForSummary);
1094
1095 // Standard provider with default options (create dump for current process).
1096 MockMemoryDumpProvider summaryMdp;
1097 RegisterDumpProvider(&summaryMdp, nullptr, kDefaultOptions,
1098 kWhitelistedMDPName);
1099 MockMemoryDumpProvider backgroundMdp;
1100 RegisterDumpProvider(&backgroundMdp, nullptr, kDefaultOptions,
1101 kBackgroundButNotSummaryWhitelistedMDPName);
1102
1103 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
1104 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1);
1105 EXPECT_CALL(backgroundMdp, OnMemoryDump(_, _)).Times(0);
1106 EXPECT_CALL(summaryMdp, OnMemoryDump(_, _)).Times(1);
1107 RequestGlobalDumpAndWait(MemoryDumpType::SUMMARY_ONLY,
1108 MemoryDumpLevelOfDetail::BACKGROUND);
1109 DisableTracing();
1110 }
1111
1084 TEST_F(MemoryDumpManagerTest, SummaryOnlyDumpsArentAddedToTrace) { 1112 TEST_F(MemoryDumpManagerTest, SummaryOnlyDumpsArentAddedToTrace) {
1085 using trace_analyzer::Query; 1113 using trace_analyzer::Query;
1086 1114
1087 InitializeMemoryDumpManager(false /* is_coordinator */); 1115 InitializeMemoryDumpManager(false /* is_coordinator */);
1116 SetDumpProviderSummaryWhitelistForTesting(kTestMDPWhitelistForSummary);
1088 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); 1117 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist);
1089 1118
1090 // Standard provider with default options (create dump for current process). 1119 // Standard provider with default options (create dump for current process).
1091 MockMemoryDumpProvider mdp; 1120 MockMemoryDumpProvider mdp;
1092 RegisterDumpProvider(&mdp, nullptr, kDefaultOptions, kWhitelistedMDPName); 1121 RegisterDumpProvider(&mdp, nullptr, kDefaultOptions, kWhitelistedMDPName);
1093 1122
1094 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 1123 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
1095 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); 1124 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2);
1096 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(2).WillRepeatedly(Return(true)); 1125 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(2).WillRepeatedly(Return(true));
1097 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 1126 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb); 1403 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb);
1375 // partition_alloc has partition_alloc/allocated_objects/* which is a subset 1404 // partition_alloc has partition_alloc/allocated_objects/* which is a subset
1376 // of partition_alloc/partitions/* so we only count the latter. 1405 // of partition_alloc/partitions/* so we only count the latter.
1377 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb); 1406 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb);
1378 // resident_set_kb should read from process_totals. 1407 // resident_set_kb should read from process_totals.
1379 EXPECT_EQ(5u, result.os_dump.resident_set_kb); 1408 EXPECT_EQ(5u, result.os_dump.resident_set_kb);
1380 }; 1409 };
1381 1410
1382 } // namespace trace_event 1411 } // namespace trace_event
1383 } // namespace base 1412 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698