Commit efe60ec8 authored by Hector Dearman's avatar Hector Dearman Committed by Commit Bot

Revert "memory-infra: Add an end-to-end test of private footprint"

This reverts commit 8779e536.

Reason for revert: Breaks a test: https://uberchromegw.corp.google.com/i/chromium.memory/builders/Linux%20MSan%20Tests/builds/2673

Original change's description:
> memory-infra: Add an end-to-end test of private footprint
> 
> Bug: 742958
> Change-Id: I2908ad0794835b1ad002da3a4b9be7c3578cdce5
> Reviewed-on: https://chromium-review.googlesource.com/574029
> Commit-Queue: Hector Dearman <hjd@chromium.org>
> Reviewed-by: Primiano Tucci <primiano@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#487834}

TBR=primiano@chromium.org,erikchen@chromium.org,hjd@chromium.org

Change-Id: I3d309673b0cf4ce489d6ee535975ea1bc049e782
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 742958
Reviewed-on: https://chromium-review.googlesource.com/576184Reviewed-by: default avatarHector Dearman <hjd@chromium.org>
Commit-Queue: Hector Dearman <hjd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487860}
parent ab08362c
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include "base/bind.h"
#include "base/run_loop.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"
using testing::Le;
using testing::Ge;
using testing::AllOf;
using memory_instrumentation::mojom::GlobalMemoryDumpPtr;
using memory_instrumentation::mojom::GlobalMemoryDump;
using memory_instrumentation::mojom::ProcessMemoryDumpPtr;
using memory_instrumentation::mojom::ProcessMemoryDump;
using memory_instrumentation::mojom::ProcessType;
namespace content {
class MemoryInstrumentationTest : public ContentBrowserTest {
protected:
void Navigate(Shell* shell) {
NavigateToURL(shell, GetTestUrl("", "title.html"));
}
};
uint64_t GetPrivateFootprintKb(ProcessType type,
const GlobalMemoryDump& global_dump) {
ProcessMemoryDump* target_dump = nullptr;
for (const ProcessMemoryDumpPtr& dump : global_dump.process_dumps) {
if (dump->process_type == type) {
EXPECT_FALSE(target_dump);
target_dump = dump.get();
}
}
EXPECT_TRUE(target_dump);
return target_dump->os_dump->private_footprint_kb;
}
GlobalMemoryDumpPtr DoGlobalDump() {
GlobalMemoryDumpPtr result = nullptr;
base::RunLoop run_loop;
memory_instrumentation::MemoryInstrumentation::GetInstance()
->RequestGlobalDump(base::Bind(
[](base::Closure quit_closure, GlobalMemoryDumpPtr* out_result,
bool success, GlobalMemoryDumpPtr result) {
EXPECT_TRUE(success);
*out_result = std::move(result);
quit_closure.Run();
},
run_loop.QuitClosure(), &result));
run_loop.Run();
return result;
}
// ASAN and TSAN fake some sys calls we need meaning we never get dumps for the
// processes.
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
#define MAYBE_PrivateFootprintComputation DISABLED_PrivateFootprintComputation
#else
#define MAYBE_PrivateFootprintComputation PrivateFootprintComputatio
#endif
// Despite the location, this test is not tracing related.
// TODO(hjd): Move this once we have a resource_coordinator folder in browser.
IN_PROC_BROWSER_TEST_F(MemoryInstrumentationTest,
MAYBE_PrivateFootprintComputation) {
Navigate(shell());
// We have to pick a big size (>=64mb) to avoid an implementation detail of
// malloc on MacOS which doesn't free or mark as reusable small allocations
// after a free.
const int64_t kAllocSize = 65 * 1024 * 1024;
const int64_t kAllocSizeKb = kAllocSize / 1024;
GlobalMemoryDumpPtr before_ptr = DoGlobalDump();
std::unique_ptr<char[]> buffer = base::MakeUnique<char[]>(kAllocSize);
memset(buffer.get(), 1, kAllocSize);
volatile char* x = static_cast<volatile char*>(buffer.get());
EXPECT_EQ(x[0] + x[kAllocSize - 1], 2);
content::WebContents* web_contents = shell()->web_contents();
// Should allocate at least 4*10^6 / 1024 = 4000kb.
EXPECT_TRUE(content::ExecuteScript(web_contents,
"var a = Array(1000000).fill(1234);\n"));
GlobalMemoryDumpPtr during_ptr = DoGlobalDump();
buffer.reset();
GlobalMemoryDumpPtr after_ptr = DoGlobalDump();
int64_t before_kb = GetPrivateFootprintKb(ProcessType::BROWSER, *before_ptr);
int64_t during_kb = GetPrivateFootprintKb(ProcessType::BROWSER, *during_ptr);
int64_t after_kb = GetPrivateFootprintKb(ProcessType::BROWSER, *after_ptr);
EXPECT_THAT(after_kb - before_kb,
AllOf(Ge(-kAllocSizeKb / 10), Le(kAllocSizeKb / 10)));
EXPECT_THAT(during_kb - before_kb,
AllOf(Ge(kAllocSizeKb - 3000), Le(kAllocSizeKb + 3000)));
EXPECT_THAT(during_kb - after_kb,
AllOf(Ge(kAllocSizeKb - 3000), Le(kAllocSizeKb + 3000)));
int64_t before_renderer_kb =
GetPrivateFootprintKb(ProcessType::RENDERER, *before_ptr);
int64_t during_renderer_kb =
GetPrivateFootprintKb(ProcessType::RENDERER, *during_ptr);
EXPECT_GE(during_renderer_kb - before_renderer_kb, 3000);
}
} // namespace content
......@@ -714,7 +714,6 @@ test("content_browsertests") {
"../browser/site_per_process_mac_browsertest.mm",
"../browser/top_document_isolation_browsertest.cc",
"../browser/tracing/background_tracing_manager_browsertest.cc",
"../browser/tracing/memory_instrumentation_browsertest.cc",
"../browser/tracing/memory_tracing_browsertest.cc",
"../browser/tracing/tracing_controller_browsertest.cc",
"../browser/utility_process_host_impl_browsertest.cc",
......
......@@ -44,20 +44,6 @@ MemoryInstrumentation::~MemoryInstrumentation() {
g_instance = nullptr;
}
void MemoryInstrumentation::RequestGlobalDump(
RequestGlobalDumpCallback callback) {
const auto& coordinator = GetCoordinatorBindingForCurrentThread();
auto callback_adapter = [](RequestGlobalDumpCallback callback, bool success,
uint64_t dump_id, mojom::GlobalMemoryDumpPtr ptr) {
if (callback)
callback.Run(success, std::move(ptr));
};
base::trace_event::MemoryDumpRequestArgs args = {
0, MemoryDumpType::SUMMARY_ONLY, MemoryDumpLevelOfDetail::BACKGROUND};
coordinator->RequestGlobalMemoryDump(args,
base::Bind(callback_adapter, callback));
}
void MemoryInstrumentation::RequestGlobalDumpAndAppendToTrace(
MemoryDumpType dump_type,
MemoryDumpLevelOfDetail level_of_detail,
......
......@@ -29,8 +29,6 @@ class SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_EXPORT MemoryInstrumentation {
public:
using MemoryDumpType = base::trace_event::MemoryDumpType;
using MemoryDumpLevelOfDetail = base::trace_event::MemoryDumpLevelOfDetail;
using RequestGlobalDumpCallback =
base::Callback<void(bool success, mojom::GlobalMemoryDumpPtr)>;
using RequestGlobalDumpAndAppendToTraceCallback =
base::Callback<void(bool success, uint64_t dump_id)>;
......@@ -38,14 +36,6 @@ class SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_EXPORT MemoryInstrumentation {
const std::string& service_name);
static MemoryInstrumentation* GetInstance();
// Requests a global memory dump.
// Returns asynchronously, via the callback argument:
// (true, global_dump) if succeeded;
// (false, nullptr) if failed.
// The callback (if not null), will be posted on the same thread of the
// RequestGlobalDump() call.
void RequestGlobalDump(RequestGlobalDumpCallback);
// Requests a global memory dump and serializes the result into the trace.
// This requires that both tracing and the memory-infra category have been
// previousy enabled. Will just gracefully fail otherwise.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment