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 <stddef.h> 8 #include <stdint.h> 9 10 #include "base/trace_event/process_memory_dump.h" 11 #include "base/trace_event/process_memory_totals.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace base { 15 namespace trace_event { 16 17 TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) { 18 const MemoryDumpArgs high_detail_args = {MemoryDumpLevelOfDetail::DETAILED}; 19 auto pmtdp = ProcessMemoryTotalsDumpProvider::GetInstance(); 20 scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump(nullptr)); 21 scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump(nullptr)); 22 23 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 1024; 24 pmtdp->OnMemoryDump(high_detail_args, pmd_before.get()); 25 26 // Pretend that the RSS of the process increased of +1M. 27 const size_t kAllocSize = 1048576; 28 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing += kAllocSize; 29 30 pmtdp->OnMemoryDump(high_detail_args, pmd_after.get()); 31 32 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; 33 34 ASSERT_TRUE(pmd_before->has_process_totals()); 35 ASSERT_TRUE(pmd_after->has_process_totals()); 36 37 const uint64_t rss_before = 38 pmd_before->process_totals()->resident_set_bytes(); 39 const uint64_t rss_after = pmd_after->process_totals()->resident_set_bytes(); 40 41 EXPECT_NE(0U, rss_before); 42 EXPECT_NE(0U, rss_after); 43 44 EXPECT_EQ(rss_after - rss_before, kAllocSize); 45 } 46 47 } // namespace trace_event 48 } // namespace base 49