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

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: 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
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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // RequestGlobalMemoryDump() should still suceed even if some threads were
830 // torn down during the dump. 833 // torn down during the dump.
831 EXPECT_TRUE(last_callback_success_); 834 EXPECT_TRUE(last_callback_success_);
832 } 835 }
833 836
837 // Tests against race conditions that can happen if tracing is disabled before
838 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
839 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
840 base::WaitableEvent tracing_disabled_event(false, false);
841 InitializeMemoryDumpManager(false /* is_coordinator */);
842
843 MockMemoryDumpProvider mdp;
844 RegisterDumpProvider(&mdp);
845 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
846
847 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
848 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args,
849 const MemoryDumpCallback& callback) {
850 DisableTracing();
851 delegate_->CreateProcessDump(args, callback);
852 }));
853
854 last_callback_success_ = true;
855 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
856 MemoryDumpLevelOfDetail::DETAILED);
857 EXPECT_FALSE(last_callback_success_);
858 }
859
834 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { 860 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) {
835 using trace_analyzer::Query; 861 using trace_analyzer::Query;
836 862
837 InitializeMemoryDumpManager(false /* is_coordinator */); 863 InitializeMemoryDumpManager(false /* is_coordinator */);
838 864
839 // Standard provider with default options (create dump for current process). 865 // Standard provider with default options (create dump for current process).
840 MemoryDumpProvider::Options options; 866 MemoryDumpProvider::Options options;
841 MockMemoryDumpProvider mdp1; 867 MockMemoryDumpProvider mdp1;
842 RegisterDumpProvider(&mdp1, nullptr, options); 868 RegisterDumpProvider(&mdp1, nullptr, options);
843 869
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); 975 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2);
950 for (int i = 0; i < 2; ++i) { 976 for (int i = 0; i < 2; ++i) {
951 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 977 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
952 MemoryDumpLevelOfDetail::DETAILED); 978 MemoryDumpLevelOfDetail::DETAILED);
953 } 979 }
954 DisableTracing(); 980 DisableTracing();
955 } 981 }
956 982
957 } // namespace trace_event 983 } // namespace trace_event
958 } // namespace base 984 } // namespace base
OLDNEW
« base/trace_event/memory_dump_manager.cc ('K') | « 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