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

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

Issue 1620783002: tracing: fix edge case when dumping while trace being disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 11 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') | no next file » | 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 <vector> 9 #include <vector>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 MOCK_METHOD2(RequestGlobalMemoryDump, 85 MOCK_METHOD2(RequestGlobalMemoryDump,
86 void(const MemoryDumpRequestArgs& args, 86 void(const MemoryDumpRequestArgs& args,
87 const MemoryDumpCallback& callback)); 87 const MemoryDumpCallback& callback));
88 88
89 uint64_t GetTracingProcessId() const override { 89 uint64_t GetTracingProcessId() const override {
90 NOTREACHED(); 90 NOTREACHED();
91 return MemoryDumpManager::kInvalidTracingProcessId; 91 return MemoryDumpManager::kInvalidTracingProcessId;
92 } 92 }
93
94 // Promote the CreateProcessDump to public so it can be used by test fixtures.
95 using MemoryDumpManagerDelegate::CreateProcessDump;
93 }; 96 };
94 97
95 class MockMemoryDumpProvider : public MemoryDumpProvider { 98 class MockMemoryDumpProvider : public MemoryDumpProvider {
96 public: 99 public:
97 MOCK_METHOD0(Destructor, void()); 100 MOCK_METHOD0(Destructor, void());
98 MOCK_METHOD2(OnMemoryDump, 101 MOCK_METHOD2(OnMemoryDump,
99 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); 102 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
100 103
101 MockMemoryDumpProvider() : enable_mock_destructor(false) {} 104 MockMemoryDumpProvider() : enable_mock_destructor(false) {}
102 ~MockMemoryDumpProvider() override { 105 ~MockMemoryDumpProvider() override {
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 RunLoop run_loop; 822 RunLoop run_loop;
820 MemoryDumpCallback callback = 823 MemoryDumpCallback callback =
821 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 824 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
822 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 825 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
823 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 826 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
824 MemoryDumpLevelOfDetail::DETAILED, callback); 827 MemoryDumpLevelOfDetail::DETAILED, callback);
825 DisableTracing(); 828 DisableTracing();
826 tracing_disabled_event.Signal(); 829 tracing_disabled_event.Signal();
827 run_loop.Run(); 830 run_loop.Run();
828 831
829 // RequestGlobalMemoryDump() should still suceed even if some threads were 832 EXPECT_FALSE(last_callback_success_);
830 // torn down during the dump. 833 }
831 EXPECT_TRUE(last_callback_success_); 834
835 // Tests against race conditions that can happen if tracing is disabled before
836 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
837 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
838 base::WaitableEvent tracing_disabled_event(false, false);
839 InitializeMemoryDumpManager(false /* is_coordinator */);
840
841 MockMemoryDumpProvider mdp;
842 RegisterDumpProvider(&mdp);
843 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
844
845 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
846 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args,
847 const MemoryDumpCallback& callback) {
848 DisableTracing();
849 delegate_->CreateProcessDump(args, callback);
850 }));
851
852 last_callback_success_ = true;
853 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
854 MemoryDumpLevelOfDetail::DETAILED);
855 EXPECT_FALSE(last_callback_success_);
832 } 856 }
833 857
834 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { 858 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) {
835 using trace_analyzer::Query; 859 using trace_analyzer::Query;
836 860
837 InitializeMemoryDumpManager(false /* is_coordinator */); 861 InitializeMemoryDumpManager(false /* is_coordinator */);
838 862
839 // Standard provider with default options (create dump for current process). 863 // Standard provider with default options (create dump for current process).
840 MemoryDumpProvider::Options options; 864 MemoryDumpProvider::Options options;
841 MockMemoryDumpProvider mdp1; 865 MockMemoryDumpProvider mdp1;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); 973 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2);
950 for (int i = 0; i < 2; ++i) { 974 for (int i = 0; i < 2; ++i) {
951 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 975 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
952 MemoryDumpLevelOfDetail::DETAILED); 976 MemoryDumpLevelOfDetail::DETAILED);
953 } 977 }
954 DisableTracing(); 978 DisableTracing();
955 } 979 }
956 980
957 } // namespace trace_event 981 } // namespace trace_event
958 } // namespace base 982 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698