Chromium Code Reviews| Index: components/tracing/common/process_metrics_memory_dump_provider.cc |
| diff --git a/components/tracing/common/process_metrics_memory_dump_provider.cc b/components/tracing/common/process_metrics_memory_dump_provider.cc |
| index 3f2abde07f9c7143049f87ab7065c24e39efa490..6860f71cdb2d55f352ddc7689beeb72eacf1ac5b 100644 |
| --- a/components/tracing/common/process_metrics_memory_dump_provider.cc |
| +++ b/components/tracing/common/process_metrics_memory_dump_provider.cc |
| @@ -180,15 +180,18 @@ uint32_t ReadLinuxProcSmapsFile(FILE* smaps_file, |
| return num_valid_regions; |
| } |
| -bool GetResidentSizeFromStatmFile(int fd, uint64_t* resident_pages) { |
| +bool GetResidentAndSharedPagesFromStatmFile(int fd, |
| + uint64_t* resident_pages, |
| + uint64_t* shared_pages) { |
| lseek(fd, 0, SEEK_SET); |
| char line[kMaxLineSize]; |
| int res = read(fd, line, kMaxLineSize - 1); |
| if (res <= 0) |
| return false; |
| line[res] = '\0'; |
| - int num_scanned = sscanf(line, "%*s %" SCNu64, resident_pages); |
| - return num_scanned == 1; |
| + int num_scanned = |
| + sscanf(line, "%*s %" SCNu64 " %" SCNu64, resident_pages, shared_pages); |
| + return num_scanned == 2; |
| } |
| #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| @@ -633,6 +636,29 @@ bool ProcessMetricsMemoryDumpProvider::DumpProcessTotals( |
| uint64_t peak_rss_bytes = 0; |
| +#if defined(OS_LINUX) || defined(OS_ANDROID) |
| + auto& footprint = pmd->process_totals()->GetPlatformPrivateFootprint(); |
| + |
| + base::ScopedFD autoclose; |
| + int statm_fd = fast_polling_statm_fd_.get(); |
| + if (statm_fd == -1) { |
| + autoclose = OpenStatm(); |
| + statm_fd = autoclose.get(); |
| + } |
| + if (statm_fd == -1) |
| + return false; |
| + const static size_t page_size = base::GetPageSize(); |
| + uint64_t resident_pages; |
| + uint64_t shared_pages; |
| + bool success = GetResidentAndSharedPagesFromStatmFile( |
| + statm_fd, &resident_pages, &shared_pages); |
| + if (!success) |
| + return false; |
| + |
| + // TODO(hjd): Implement swap in the next CL. |
| + footprint.rss_anon_bytes = (resident_pages - shared_pages) * page_size; |
| +#endif // defined(OS_LINUX) |
| + |
| #if !defined(OS_IOS) |
| peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize(); |
| #if defined(OS_LINUX) || defined(OS_ANDROID) |
| @@ -676,27 +702,35 @@ bool ProcessMetricsMemoryDumpProvider::DumpProcessTotals( |
| return true; |
| } |
| +base::ScopedFD ProcessMetricsMemoryDumpProvider::OpenStatm() { |
| + std::string name = |
| + "/proc/" + |
| + (process_ == base::kNullProcessId ? "self" |
| + : base::IntToString(process_)) + |
| + "/statm"; |
| + base::ScopedFD fd = base::ScopedFD(open(name.c_str(), O_RDONLY)); |
| + DCHECK(fd.is_valid()); |
| + return fd; |
| +} |
| + |
| void ProcessMetricsMemoryDumpProvider::PollFastMemoryTotal( |
| uint64_t* memory_total) { |
| *memory_total = 0; |
| #if defined(OS_LINUX) || defined(OS_ANDROID) |
| + |
| int statm_fd = fast_polling_statm_fd_for_testing; |
| if (statm_fd == -1) { |
| - if (!fast_polling_statm_fd_.is_valid()) { |
| - std::string name = "/proc/" + (process_ == base::kNullProcessId |
| - ? "self" |
| - : base::IntToString(process_)) + |
| - "/statm"; |
| - fast_polling_statm_fd_.reset(open(name.c_str(), O_RDONLY)); |
| - DCHECK(fast_polling_statm_fd_.is_valid()); |
| - } |
| + if (!fast_polling_statm_fd_.is_valid()) |
| + fast_polling_statm_fd_ = OpenStatm(); |
| statm_fd = fast_polling_statm_fd_.get(); |
| + if (statm_fd == -1) |
| + return; |
| } |
| - if (statm_fd == -1) |
| - return; |
| uint64_t rss_pages = 0; |
|
Primiano Tucci (use gerrit)
2017/05/04 11:11:16
at this point call this "private_pages" for consis
hjd
2017/05/05 14:59:35
thanks, Used resident_pages to match arg name
|
| - if (!GetResidentSizeFromStatmFile(statm_fd, &rss_pages)) |
| + uint64_t shared_pages = 0; |
|
Primiano Tucci (use gerrit)
2017/05/04 11:11:16
and I'd call this "ignored" (or ignored_shared_pag
hjd
2017/05/05 14:59:35
Done.
|
| + if (!GetResidentAndSharedPagesFromStatmFile(statm_fd, &rss_pages, |
| + &shared_pages)) |
| return; |
| static size_t page_size = base::GetPageSize(); |