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

Unified Diff: base/trace_event/process_memory_totals_dump_provider_unittest.cc

Issue 934323002: [tracing] Add a dump provider to dump process memory totals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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: 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

Powered by Google App Engine
This is Rietveld 408576698