#include <stdint.h>
#include <memory>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/memory_dump_request_args.h"
#include "base/trace_event/trace_config_memory_test_util.h"
#include "base/trace_event/trace_log.h"
#include "build/build_config.h"
#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/tracing_controller.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
#include "testing/gmock/include/gmock/gmock.h"
MemoryDumpArgs;
MemoryDumpDeterminism;
MemoryDumpLevelOfDetail;
MemoryDumpManager;
MemoryDumpType;
ProcessMemoryDump;
_;
Return;
namespace content {
class MockDumpProvider : public base::trace_event::MemoryDumpProvider { … };
class MemoryTracingTest : public ContentBrowserTest { … };
#if BUILDFLAG(IS_ANDROID)
class SingleProcessMemoryTracingTest : public MemoryTracingTest {
public:
SingleProcessMemoryTracingTest() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kSingleProcess);
}
};
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_BrowserInitiatedSingleDump …
#else
#define MAYBE_BrowserInitiatedSingleDump …
#endif
IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest,
MAYBE_BrowserInitiatedSingleDump) {
Navigate(shell());
EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true));
EXPECT_CALL(*this, OnMemoryDumpDone(_, true ));
EnableMemoryTracing();
RequestGlobalDumpAndWait(false ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
DisableTracing();
}
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_RendererInitiatedSingleDump …
#else
#define MAYBE_RendererInitiatedSingleDump …
#endif
IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest,
MAYBE_RendererInitiatedSingleDump) {
Navigate(shell());
EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true));
EXPECT_CALL(*this, OnMemoryDumpDone(_, true ));
EnableMemoryTracing();
RequestGlobalDumpAndWait(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
DisableTracing();
}
#if BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)
#define MAYBE_ManyInterleavedDumps …
#else
#define MAYBE_ManyInterleavedDumps …
#endif
IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest,
MAYBE_ManyInterleavedDumps) {
Navigate(shell());
EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_))
.Times(4)
.WillRepeatedly(Return(true));
EXPECT_CALL(*this, OnMemoryDumpDone(_, true )).Times(4);
EnableMemoryTracing();
RequestGlobalDumpAndWait(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
RequestGlobalDumpAndWait(false ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
RequestGlobalDumpAndWait(false ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
RequestGlobalDumpAndWait(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
DisableTracing();
}
IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, DISABLED_QueuedDumps) {
Navigate(shell());
EnableMemoryTracing();
EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_, _))
.Times(5)
.WillRepeatedly(Return(true));
EXPECT_CALL(*this, OnMemoryDumpDone(0, true ));
RequestGlobalDump(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
EXPECT_CALL(*this, OnMemoryDumpDone(1, false ));
RequestGlobalDump(true ,
MemoryDumpType::kPeriodicInterval,
MemoryDumpLevelOfDetail::kDetailed);
EXPECT_CALL(*this, OnMemoryDumpDone(2, true ));
RequestGlobalDump(true ,
MemoryDumpType::kPeriodicInterval,
MemoryDumpLevelOfDetail::kLight);
EXPECT_CALL(*this, OnMemoryDumpDone(3, false ));
RequestGlobalDump(true ,
MemoryDumpType::kPeriodicInterval,
MemoryDumpLevelOfDetail::kLight);
EXPECT_CALL(*this, OnMemoryDumpDone(4, true ));
RequestGlobalDump(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kLight);
EXPECT_CALL(*this, OnMemoryDumpDone(5, true ));
RequestGlobalDumpAndWait(true ,
MemoryDumpType::kExplicitlyTriggered,
MemoryDumpLevelOfDetail::kDetailed);
EXPECT_CALL(*this, OnMemoryDumpDone(6, true ));
RequestGlobalDumpAndWait(true ,
MemoryDumpType::kPeriodicInterval,
MemoryDumpLevelOfDetail::kLight);
DisableTracing();
}
#endif
#if BUILDFLAG(IS_MAC) || \
(BUILDFLAG(IS_ANDROID) && defined(ADDRESS_SANITIZER)) || \
BUILDFLAG(IS_FUCHSIA)
#define MAYBE_BrowserInitiatedDump …
#else
#define MAYBE_BrowserInitiatedDump …
#endif
IN_PROC_BROWSER_TEST_F(MemoryTracingTest, MAYBE_BrowserInitiatedDump) { … }
}