OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/process_memory_totals_dump_provider.h" | 5 #include "base/trace_event/process_memory_totals_dump_provider.h" |
6 | 6 |
7 #include "base/trace_event/process_memory_dump.h" | 7 #include "base/trace_event/process_memory_dump.h" |
8 #include "base/trace_event/process_memory_totals.h" | 8 #include "base/trace_event/process_memory_totals.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 namespace trace_event { | 12 namespace trace_event { |
13 | 13 |
14 TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) { | 14 TEST(ProcessMemoryTotalsDumpProviderTest, DumpRSS) { |
| 15 const MemoryDumpArgs high_detail_args = { |
| 16 MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH}; |
15 auto pmtdp = ProcessMemoryTotalsDumpProvider::GetInstance(); | 17 auto pmtdp = ProcessMemoryTotalsDumpProvider::GetInstance(); |
16 scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump(nullptr)); | 18 scoped_ptr<ProcessMemoryDump> pmd_before(new ProcessMemoryDump(nullptr)); |
17 scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump(nullptr)); | 19 scoped_ptr<ProcessMemoryDump> pmd_after(new ProcessMemoryDump(nullptr)); |
18 | 20 |
19 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 1024; | 21 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 1024; |
20 pmtdp->OnMemoryDump(pmd_before.get()); | 22 pmtdp->OnMemoryDump(high_detail_args, pmd_before.get()); |
21 | 23 |
22 // Pretend that the RSS of the process increased of +1M. | 24 // Pretend that the RSS of the process increased of +1M. |
23 const size_t kAllocSize = 1048576; | 25 const size_t kAllocSize = 1048576; |
24 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing += kAllocSize; | 26 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing += kAllocSize; |
25 | 27 |
26 pmtdp->OnMemoryDump(pmd_after.get()); | 28 pmtdp->OnMemoryDump(high_detail_args, pmd_after.get()); |
27 | 29 |
28 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; | 30 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; |
29 | 31 |
30 ASSERT_TRUE(pmd_before->has_process_totals()); | 32 ASSERT_TRUE(pmd_before->has_process_totals()); |
31 ASSERT_TRUE(pmd_after->has_process_totals()); | 33 ASSERT_TRUE(pmd_after->has_process_totals()); |
32 | 34 |
33 const uint64 rss_before = pmd_before->process_totals()->resident_set_bytes(); | 35 const uint64 rss_before = pmd_before->process_totals()->resident_set_bytes(); |
34 const uint64 rss_after = pmd_after->process_totals()->resident_set_bytes(); | 36 const uint64 rss_after = pmd_after->process_totals()->resident_set_bytes(); |
35 | 37 |
36 EXPECT_NE(0U, rss_before); | 38 EXPECT_NE(0U, rss_before); |
37 EXPECT_NE(0U, rss_after); | 39 EXPECT_NE(0U, rss_after); |
38 | 40 |
39 EXPECT_EQ(rss_after - rss_before, kAllocSize); | 41 EXPECT_EQ(rss_after - rss_before, kAllocSize); |
40 } | 42 } |
41 | 43 |
42 } // namespace trace_event | 44 } // namespace trace_event |
43 } // namespace base | 45 } // namespace base |
OLD | NEW |