| Index: base/trace_event/process_memory_totals_dump_provider_unittest.cc
|
| diff --git a/base/trace_event/process_memory_totals_dump_provider_unittest.cc b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b7415c80e2cfd0fbb106e89414907bcf15f94e87
|
| --- /dev/null
|
| +++ b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
|
| @@ -0,0 +1,46 @@
|
| +// Copyright 2015 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 "base/trace_event/process_memory_totals_dump_provider.h"
|
| +
|
| +#include "base/trace_event/process_memory_dump.h"
|
| +#include "base/trace_event/process_memory_totals.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace base {
|
| +namespace trace_event {
|
| +namespace {
|
| +
|
| +TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) {
|
| + auto mdptp = ProcessMemoryTotalsDumpProvider::GetInstance();
|
| + scoped_refptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump());
|
| + scoped_refptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump());
|
| +
|
| + mdptp->DumpInto(pmd_before.get());
|
| +
|
| + // Allocate and fill a 1M buffer.
|
| + const size_t kAllocSize = 1048576;
|
| + scoped_ptr<uint8[]> buf(new uint8[kAllocSize]);
|
| + memset(buf.get(), 0x42, kAllocSize);
|
| +
|
| + mdptp->DumpInto(pmd_after.get());
|
| +
|
| + ASSERT_NE(nullptr, pmd_before->process_totals());
|
| + ASSERT_NE(nullptr, pmd_after->process_totals());
|
| +
|
| + const uint64 rss_before = pmd_before->process_totals()->resident_set_bytes();
|
| + const uint64 rss_after = pmd_after->process_totals()->resident_set_bytes();
|
| +
|
| + EXPECT_NE(0U, rss_before);
|
| + EXPECT_NE(0U, rss_after);
|
| +
|
| + // Leave some margin when checking for the delta RSS to avoid flakiness.
|
| + // Rationale: some of the STL / gtest calls in the middle could free something
|
| + // else causing the overall delta to be slightly < kAllocSize.
|
| + EXPECT_GE(rss_after - rss_before, kAllocSize / 2);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace trace_Event
|
| +} // namespace base
|
|
|