Chromium Code Reviews| 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) | |
| 21 #include <libgen.h> | |
| 22 #include <mach-o/dyld.h> | |
| 23 #endif | |
| 24 | |
| 20 namespace tracing { | 25 namespace tracing { |
| 21 | 26 |
| 22 #if defined(OS_LINUX) || defined(OS_ANDROID) | 27 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 23 namespace { | 28 namespace { |
| 24 const char kTestSmaps1[] = | 29 const char kTestSmaps1[] = |
| 25 "00400000-004be000 r-xp 00000000 fc:01 1234 /file/1\n" | 30 "00400000-004be000 r-xp 00000000 fc:01 1234 /file/1\n" |
| 26 "Size: 760 kB\n" | 31 "Size: 760 kB\n" |
| 27 "Rss: 296 kB\n" | 32 "Rss: 296 kB\n" |
| 28 "Pss: 162 kB\n" | 33 "Pss: 162 kB\n" |
| 29 "Shared_Clean: 228 kB\n" | 34 "Shared_Clean: 228 kB\n" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 mdp.PollFastMemoryTotal(&value); | 267 mdp.PollFastMemoryTotal(&value); |
| 263 EXPECT_EQ(100 * page_size, value); | 268 EXPECT_EQ(100 * page_size, value); |
| 264 | 269 |
| 265 mdp.SuspendFastMemoryPolling(); | 270 mdp.SuspendFastMemoryPolling(); |
| 266 EXPECT_FALSE(mdp.fast_polling_statm_fd_.is_valid()); | 271 EXPECT_FALSE(mdp.fast_polling_statm_fd_.is_valid()); |
| 267 #else | 272 #else |
| 268 mdp.SuspendFastMemoryPolling(); | 273 mdp.SuspendFastMemoryPolling(); |
| 269 #endif | 274 #endif |
| 270 } | 275 } |
| 271 | 276 |
| 277 #if defined(OS_MACOSX) | |
| 278 TEST(ProcessMetricsMemoryDumpProviderTest, TestMachOReading) { | |
|
Primiano Tucci (use gerrit)
2017/02/01 00:03:57
\o/ Look a test! thanks, you rock.
| |
| 279 using VMRegion = base::trace_event::ProcessMemoryMaps::VMRegion; | |
| 280 ProcessMetricsMemoryDumpProvider mdp(base::kNullProcessId); | |
| 281 base::trace_event::MemoryDumpArgs args; | |
| 282 base::trace_event::ProcessMemoryDump dump(nullptr, args); | |
| 283 ASSERT_TRUE(mdp.DumpProcessMemoryMaps(args, &dump)); | |
| 284 ASSERT_TRUE(dump.has_process_mmaps()); | |
| 285 uint32_t size = 100; | |
| 286 char full_path[size]; | |
| 287 int result = _NSGetExecutablePath(full_path, &size); | |
| 288 ASSERT_EQ(0, result); | |
| 289 std::string name = basename(full_path); | |
| 290 | |
| 291 bool found_components_unittests = false; | |
| 292 for (const VMRegion& region : dump.process_mmaps()->vm_regions()) { | |
| 293 EXPECT_NE(0u, region.start_address); | |
| 294 EXPECT_NE(0u, region.size_in_bytes); | |
| 295 | |
| 296 EXPECT_LT(region.size_in_bytes, 1ull << 32); | |
| 297 uint32_t required_protection_flags = | |
| 298 VMRegion::kProtectionFlagsRead | VMRegion::kProtectionFlagsExec; | |
| 299 if (region.mapped_file.find(name) != std::string::npos && | |
| 300 region.protection_flags == required_protection_flags) { | |
| 301 found_components_unittests = true; | |
| 302 } | |
| 303 } | |
| 304 EXPECT_TRUE(found_components_unittests); | |
| 305 } | |
| 306 #endif // defined(OS_MACOSX) | |
| 307 | |
| 272 } // namespace tracing | 308 } // namespace tracing |
| OLD | NEW |