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

Unified Diff: content/browser/tracing/memory_tracing_browsertest.cc

Issue 2067793004: [memory-infra] Add support for queueing memory dump requests in the browser process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/tracing/memory_tracing_browsertest.cc
diff --git a/content/browser/tracing/memory_tracing_browsertest.cc b/content/browser/tracing/memory_tracing_browsertest.cc
index c2cafd80d0de503e8bee43c5bbbe711878b6685f..3e572b01a3400b649ce0b58dd2d0b0d118010b0d 100644
--- a/content/browser/tracing/memory_tracing_browsertest.cc
+++ b/content/browser/tracing/memory_tracing_browsertest.cc
@@ -21,6 +21,7 @@
#include "testing/gmock/include/gmock/gmock.h"
using base::trace_event::MemoryDumpArgs;
+using base::trace_event::MemoryDumpLevelOfDetail;
using base::trace_event::MemoryDumpManager;
using base::trace_event::MemoryDumpType;
using base::trace_event::ProcessMemoryDump;
@@ -39,10 +40,11 @@ class MockDumpProvider : public base::trace_event::MemoryDumpProvider {
class MemoryTracingTest : public ContentBrowserTest {
public:
- void DoRequestGlobalDump(const base::trace_event::MemoryDumpCallback& cb) {
- MemoryDumpManager::GetInstance()->RequestGlobalDump(
- MemoryDumpType::EXPLICITLY_TRIGGERED,
- base::trace_event::MemoryDumpLevelOfDetail::DETAILED, cb);
+ void DoRequestGlobalDump(const MemoryDumpType& dump_type,
+ const MemoryDumpLevelOfDetail& level_of_detail,
+ const base::trace_event::MemoryDumpCallback& cb) {
+ MemoryDumpManager::GetInstance()->RequestGlobalDump(dump_type,
+ level_of_detail, cb);
}
// Used as callback argument for MemoryDumpManager::RequestGlobalDump():
@@ -106,19 +108,30 @@ class MemoryTracingTest : public ContentBrowserTest {
base::RunLoop().RunUntilIdle();
}
- void RequestGlobalDumpAndWait(bool from_renderer_thread) {
- base::RunLoop run_loop;
+ std::unique_ptr<base::RunLoop> RequestGlobalDumpWhichQuitsLoop(
+ bool from_renderer_thread,
+ const MemoryDumpType& dump_type,
+ const MemoryDumpLevelOfDetail& level_of_detail) {
+ std::unique_ptr<base::RunLoop> run_loop;
+ run_loop.reset(new base::RunLoop());
base::trace_event::MemoryDumpCallback callback = base::Bind(
&MemoryTracingTest::OnGlobalMemoryDumpDone, base::Unretained(this),
- base::ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure());
+ base::ThreadTaskRunnerHandle::Get(), run_loop->QuitClosure());
if (from_renderer_thread) {
- PostTaskToInProcessRendererAndWait(
- base::Bind(&MemoryTracingTest::DoRequestGlobalDump,
- base::Unretained(this), callback));
+ PostTaskToInProcessRendererAndWait(base::Bind(
+ &MemoryTracingTest::DoRequestGlobalDump, base::Unretained(this),
+ dump_type, level_of_detail, callback));
} else {
- DoRequestGlobalDump(callback);
+ DoRequestGlobalDump(dump_type, level_of_detail, callback);
}
- run_loop.Run();
+ return run_loop;
+ }
+
+ void RequestGlobalDumpAndWait(bool from_renderer_thread) {
+ std::unique_ptr<base::RunLoop> run_loop = RequestGlobalDumpWhichQuitsLoop(
+ from_renderer_thread, MemoryDumpType::EXPLICITLY_TRIGGERED,
+ MemoryDumpLevelOfDetail::DETAILED);
+ run_loop->Run();
}
void Navigate(Shell* shell) {
@@ -206,6 +219,86 @@ IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, ManyInterleavedDumps) {
DisableTracing();
}
+IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, QueuedDumps) {
ssid 2016/06/16 23:12:03 I am removing SingleProcessMemoryTracingTest in th
petrcermak 2016/06/17 08:36:44 Not that I'm aware of, I just followed what the ot
ssid 2016/06/17 18:43:45 Sorry, I got confused with the test files here. Ig
Primiano Tucci (use gerrit) 2016/06/23 11:09:16 Had a chat offline on this. Let's simplify it Req
petrcermak 2016/06/24 10:49:57 Done (but kept everything in one test).
+ Navigate(shell());
+
+ EnableMemoryTracing();
+
+ // This test issues the following 6 global memory dump requests:
+ //
+ // loop1 (ED) req---------------------------------->ok
+ // loop2 (PD) req->fail(1)
+ // loop3 (PL) req-------------------->ok
+ // loop4 (PL) req->fail(3)
+ // loop5 (ED) req-------------->ok
+ // loop6 (PL) req->ok
+ //
+ // where P=PERIODIC_INTERVAL, E=EXPLICITLY_TRIGGERED, D=DETAILED and L=LIGHT.
+
+ EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_, _))
+ .Times(4)
+ .WillRepeatedly(Return(true));
+
+ std::unique_ptr<base::RunLoop> loop1 = RequestGlobalDumpWhichQuitsLoop(
+ true /* from_renderer_thread */, MemoryDumpType::EXPLICITLY_TRIGGERED,
+ MemoryDumpLevelOfDetail::DETAILED);
+ EXPECT_EQ(0u, callback_call_count_);
+
+ // This periodic request should immediately fail because there already is a
+ // request for a detailed memory dump on the queue (loop1).
+ std::unique_ptr<base::RunLoop> loop2 = RequestGlobalDumpWhichQuitsLoop(
+ false /* from_renderer_thread */, MemoryDumpType::PERIODIC_INTERVAL,
+ MemoryDumpLevelOfDetail::DETAILED);
+ loop2->Run();
+ EXPECT_EQ(1u, callback_call_count_);
+ EXPECT_FALSE(last_callback_success_);
+
+ std::unique_ptr<base::RunLoop> loop3 = RequestGlobalDumpWhichQuitsLoop(
+ false /* from_renderer_thread */, MemoryDumpType::PERIODIC_INTERVAL,
+ MemoryDumpLevelOfDetail::LIGHT);
+ EXPECT_EQ(1u, callback_call_count_);
+
+ // This periodic request should immediately fail because there already is a
+ // request for a light memory dump on the queue (loop3).
+ std::unique_ptr<base::RunLoop> loop4 = RequestGlobalDumpWhichQuitsLoop(
+ true /* from_renderer_thread */, MemoryDumpType::PERIODIC_INTERVAL,
+ MemoryDumpLevelOfDetail::LIGHT);
+ loop4->Run();
+ EXPECT_EQ(2u, callback_call_count_);
+ EXPECT_FALSE(last_callback_success_);
+
+ std::unique_ptr<base::RunLoop> loop5 = RequestGlobalDumpWhichQuitsLoop(
+ false /* from_renderer_thread */, MemoryDumpType::EXPLICITLY_TRIGGERED,
+ MemoryDumpLevelOfDetail::DETAILED);
+ EXPECT_EQ(2u, callback_call_count_);
+
+ loop1->Run();
+ EXPECT_EQ(3u, callback_call_count_);
+ EXPECT_NE(0u, last_callback_dump_guid_);
+ EXPECT_TRUE(last_callback_success_);
+
+ loop3->Run();
+ EXPECT_EQ(4u, callback_call_count_);
+ EXPECT_NE(0u, last_callback_dump_guid_);
+ EXPECT_TRUE(last_callback_success_);
+
+ std::unique_ptr<base::RunLoop> loop6 = RequestGlobalDumpWhichQuitsLoop(
+ false /* from_renderer_thread */, MemoryDumpType::PERIODIC_INTERVAL,
+ MemoryDumpLevelOfDetail::LIGHT);
+
+ loop5->Run();
+ EXPECT_EQ(5u, callback_call_count_);
+ EXPECT_NE(0u, last_callback_dump_guid_);
+ EXPECT_TRUE(last_callback_success_);
+
+ loop6->Run();
+ EXPECT_EQ(6u, callback_call_count_);
+ EXPECT_NE(0u, last_callback_dump_guid_);
+ EXPECT_TRUE(last_callback_success_);
+
+ DisableTracing();
+}
+
#endif // !defined(GOOGLE_CHROME_BUILD)
// Non-deterministic races under TSan. crbug.com/529678
« no previous file with comments | « no previous file | content/browser/tracing/tracing_controller_impl.h » ('j') | content/browser/tracing/tracing_controller_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698