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 "components/tracing/common/process_metrics_memory_dump_provider.h" | 5 #include "components/tracing/common/process_metrics_memory_dump_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
14 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
15 #include "base/trace_event/process_memory_maps.h" | 15 #include "base/trace_event/process_memory_maps.h" |
16 #include "base/trace_event/process_memory_totals.h" | 16 #include "base/trace_event/process_memory_totals.h" |
17 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
21 #include <libgen.h> | 21 #include <libgen.h> |
22 #include <mach-o/dyld.h> | 22 #include <mach-o/dyld.h> |
23 #endif | 23 #endif |
24 | 24 |
25 #if defined(OS_WIN) | |
26 #include <base/strings/sys_string_conversions.h> | |
27 #endif | |
28 | |
25 namespace tracing { | 29 namespace tracing { |
26 | 30 |
27 #if defined(OS_LINUX) || defined(OS_ANDROID) | 31 #if defined(OS_LINUX) || defined(OS_ANDROID) |
28 namespace { | 32 namespace { |
29 const char kTestSmaps1[] = | 33 const char kTestSmaps1[] = |
30 "00400000-004be000 r-xp 00000000 fc:01 1234 /file/1\n" | 34 "00400000-004be000 r-xp 00000000 fc:01 1234 /file/1\n" |
31 "Size: 760 kB\n" | 35 "Size: 760 kB\n" |
32 "Rss: 296 kB\n" | 36 "Rss: 296 kB\n" |
33 "Pss: 162 kB\n" | 37 "Pss: 162 kB\n" |
34 "Shared_Clean: 228 kB\n" | 38 "Shared_Clean: 228 kB\n" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 mdp.PollFastMemoryTotal(&value); | 271 mdp.PollFastMemoryTotal(&value); |
268 EXPECT_EQ(100 * page_size, value); | 272 EXPECT_EQ(100 * page_size, value); |
269 | 273 |
270 mdp.SuspendFastMemoryPolling(); | 274 mdp.SuspendFastMemoryPolling(); |
271 EXPECT_FALSE(mdp.fast_polling_statm_fd_.is_valid()); | 275 EXPECT_FALSE(mdp.fast_polling_statm_fd_.is_valid()); |
272 #else | 276 #else |
273 mdp.SuspendFastMemoryPolling(); | 277 mdp.SuspendFastMemoryPolling(); |
274 #endif | 278 #endif |
275 } | 279 } |
276 | 280 |
281 TEST(ProcessMetricsMemoryDumpProviderTest, TestWinModuleReading) { | |
282 using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; | |
283 | |
284 ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); | |
285 base::trace_event::MemoryDumpArgs args; | |
286 base::trace_event::ProcessMemoryDump dump(nullptr, args); | |
287 ASSERT_TRUE(mdp.DumpProcessMemoryMaps(args, &dump)); | |
288 ASSERT_TRUE(dump.has_process_mmaps()); | |
289 | |
290 TCHAR module_name[MAX_PATH]; | |
Wez
2017/02/23 04:15:11
wchar_t
erikchen
2017/02/23 21:00:14
Done.
| |
291 DWORD result = GetModuleFileName(nullptr, module_name, MAX_PATH); | |
292 ASSERT_TRUE(result); | |
293 std::string executable_name = base::SysWideToNativeMB(module_name); | |
294 | |
295 bool found_components_unittests = false; | |
Wez
2017/02/23 04:15:11
For extra credit:
Use GetModuleHandleEx(GET_MODUL
erikchen
2017/02/23 21:00:14
Done.
| |
296 for (const VMRegion& region : dump.process_mmaps()->vm_regions()) { | |
297 EXPECT_NE(0u, region.start_address); | |
298 EXPECT_NE(0u, region.size_in_bytes); | |
299 | |
300 if (region.mapped_file.find(executable_name) != std::string::npos) | |
301 found_components_unittests = true; | |
302 } | |
303 EXPECT_TRUE(found_components_unittests); | |
304 } | |
305 | |
277 #if defined(OS_MACOSX) | 306 #if defined(OS_MACOSX) |
278 TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) { | 307 TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) { |
279 using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; | 308 using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; |
280 ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); | 309 ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); |
281 base::trace_event::MemoryDumpArgs args; | 310 base::trace_event::MemoryDumpArgs args; |
282 base::trace_event::ProcessMemoryDump dump(nullptr, args); | 311 base::trace_event::ProcessMemoryDump dump(nullptr, args); |
283 ASSERT_TRUE(mdp.DumpProcessMemoryMaps(args, &dump)); | 312 ASSERT_TRUE(mdp.DumpProcessMemoryMaps(args, &dump)); |
284 ASSERT_TRUE(dump.has_process_mmaps()); | 313 ASSERT_TRUE(dump.has_process_mmaps()); |
285 uint32_t size = 100; | 314 uint32_t size = 100; |
286 char full_path[size]; | 315 char full_path[size]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 uint64_t last_address = 0; | 362 uint64_t last_address = 0; |
334 for (const VMRegion& region : regions) { | 363 for (const VMRegion& region : regions) { |
335 EXPECT_GE(region.start_address, last_address); | 364 EXPECT_GE(region.start_address, last_address); |
336 last_address = region.start_address + region.size_in_bytes; | 365 last_address = region.start_address + region.size_in_bytes; |
337 } | 366 } |
338 } | 367 } |
339 | 368 |
340 #endif // defined(OS_MACOSX) | 369 #endif // defined(OS_MACOSX) |
341 | 370 |
342 } // namespace tracing | 371 } // namespace tracing |
OLD | NEW |