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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/process_memory_totals_dump_provider.h"
6
7 #include "base/trace_event/process_memory_dump.h"
8 #include "base/trace_event/process_memory_totals.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace base {
12 namespace trace_event {
13 namespace {
14
15 TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) {
16 auto mdptp = ProcessMemoryTotalsDumpProvider::GetInstance();
17 scoped_refptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump());
18 scoped_refptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump());
19
20 mdptp->DumpInto(pmd_before.get());
21
22 // Allocate and fill a 1M buffer.
23 const size_t kAllocSize = 1048576;
24 scoped_ptr<uint8[]> buf(new uint8[kAllocSize]);
25 memset(buf.get(), 0x42, kAllocSize);
26
27 mdptp->DumpInto(pmd_after.get());
28
29 ASSERT_NE(nullptr, pmd_before->process_totals());
30 ASSERT_NE(nullptr, pmd_after->process_totals());
31
32 const uint64 rss_before = pmd_before->process_totals()->resident_set_bytes();
33 const uint64 rss_after = pmd_after->process_totals()->resident_set_bytes();
34
35 EXPECT_NE(0U, rss_before);
36 EXPECT_NE(0U, rss_after);
37
38 // Leave some margin when checking for the delta RSS to avoid flakiness.
39 // Rationale: some of the STL / gtest calls in the middle could free something
40 // else causing the overall delta to be slightly < kAllocSize.
41 EXPECT_GE(rss_after - rss_before, kAllocSize / 2);
42 }
43
44 } // namespace
45 } // namespace trace_Event
46 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698