| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 589 |
| 590 if (args.level_of_detail == | 590 if (args.level_of_detail == |
| 591 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) | 591 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) |
| 592 res &= DumpProcessMemoryMaps(args, pmd); | 592 res &= DumpProcessMemoryMaps(args, pmd); |
| 593 return res; | 593 return res; |
| 594 } | 594 } |
| 595 | 595 |
| 596 bool ProcessMetricsMemoryDumpProvider::DumpProcessTotals( | 596 bool ProcessMetricsMemoryDumpProvider::DumpProcessTotals( |
| 597 const base::trace_event::MemoryDumpArgs& args, | 597 const base::trace_event::MemoryDumpArgs& args, |
| 598 base::trace_event::ProcessMemoryDump* pmd) { | 598 base::trace_event::ProcessMemoryDump* pmd) { |
| 599 const uint64_t rss_bytes = rss_bytes_for_testing | 599 #if defined(OS_MACOSX) |
| 600 ? rss_bytes_for_testing | 600 size_t private_bytes; |
| 601 : process_metrics_->GetWorkingSetSize(); | 601 size_t shared_bytes; |
| 602 size_t resident_bytes; |
| 603 if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes, |
| 604 &resident_bytes)) { |
| 605 return false; |
| 606 } |
| 607 uint64_t rss_bytes = resident_bytes; |
| 608 pmd->process_totals()->SetExtraFieldInBytes("private_bytes", private_bytes); |
| 609 pmd->process_totals()->SetExtraFieldInBytes("shared_bytes", shared_bytes); |
| 610 #else |
| 611 uint64_t rss_bytes = process_metrics_->GetWorkingSetSize(); |
| 612 #endif // defined(OS_MACOSX) |
| 613 if (rss_bytes_for_testing) |
| 614 rss_bytes = rss_bytes_for_testing; |
| 602 | 615 |
| 603 // rss_bytes will be 0 if the process ended while dumping. | 616 // rss_bytes will be 0 if the process ended while dumping. |
| 604 if (!rss_bytes) | 617 if (!rss_bytes) |
| 605 return false; | 618 return false; |
| 606 | 619 |
| 607 uint64_t peak_rss_bytes = 0; | 620 uint64_t peak_rss_bytes = 0; |
| 608 | 621 |
| 609 #if !defined(OS_IOS) | 622 #if !defined(OS_IOS) |
| 610 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize(); | 623 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize(); |
| 611 #if defined(OS_LINUX) || defined(OS_ANDROID) | 624 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 612 if (is_rss_peak_resettable_) { | 625 if (is_rss_peak_resettable_) { |
| 613 std::string clear_refs_file = | 626 std::string clear_refs_file = |
| 614 "/proc/" + | 627 "/proc/" + |
| 615 (process_ == base::kNullProcessId ? "self" | 628 (process_ == base::kNullProcessId ? "self" |
| 616 : base::IntToString(process_)) + | 629 : base::IntToString(process_)) + |
| 617 "/clear_refs"; | 630 "/clear_refs"; |
| 618 int clear_refs_fd = open(clear_refs_file.c_str(), O_WRONLY); | 631 int clear_refs_fd = open(clear_refs_file.c_str(), O_WRONLY); |
| 619 if (clear_refs_fd > 0 && | 632 if (clear_refs_fd > 0 && |
| 620 base::WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand, | 633 base::WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand, |
| 621 sizeof(kClearPeakRssCommand))) { | 634 sizeof(kClearPeakRssCommand))) { |
| 622 pmd->process_totals()->set_is_peak_rss_resetable(true); | 635 pmd->process_totals()->set_is_peak_rss_resetable(true); |
| 623 } else { | 636 } else { |
| 624 is_rss_peak_resettable_ = false; | 637 is_rss_peak_resettable_ = false; |
| 625 } | 638 } |
| 626 close(clear_refs_fd); | 639 close(clear_refs_fd); |
| 627 } | 640 } |
| 628 #elif defined(MACOSX) | |
| 629 size_t private_bytes; | |
| 630 bool res = process_metrics_->GetMemoryBytes(&private_bytes, | |
| 631 nullptr /* shared_bytes */); | |
| 632 if (res) | |
| 633 pmd->process_totals()->SetExtraFieldInBytes("private_bytes", private_bytes); | |
| 634 #elif defined(OS_WIN) | 641 #elif defined(OS_WIN) |
| 635 if (args.level_of_detail == | 642 if (args.level_of_detail == |
| 636 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) { | 643 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) { |
| 637 uint64_t pss_bytes = 0; | 644 uint64_t pss_bytes = 0; |
| 638 bool res = process_metrics_->GetProportionalSetSizeBytes(&pss_bytes); | 645 bool res = process_metrics_->GetProportionalSetSizeBytes(&pss_bytes); |
| 639 if (res) { | 646 if (res) { |
| 640 base::trace_event::ProcessMemoryMaps::VMRegion region; | 647 base::trace_event::ProcessMemoryMaps::VMRegion region; |
| 641 region.byte_stats_proportional_resident = pss_bytes; | 648 region.byte_stats_proportional_resident = pss_bytes; |
| 642 pmd->process_mmaps()->AddVMRegion(region); | 649 pmd->process_mmaps()->AddVMRegion(region); |
| 643 pmd->set_has_process_mmaps(); | 650 pmd->set_has_process_mmaps(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 #endif | 692 #endif |
| 686 } | 693 } |
| 687 | 694 |
| 688 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { | 695 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { |
| 689 #if defined(OS_LINUX) || defined(OS_ANDROID) | 696 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 690 fast_polling_statm_fd_.reset(); | 697 fast_polling_statm_fd_.reset(); |
| 691 #endif | 698 #endif |
| 692 } | 699 } |
| 693 | 700 |
| 694 } // namespace tracing | 701 } // namespace tracing |
| OLD | NEW |