Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/tracing/common/process_metrics_memory_dump_provider.cc

Issue 2740423002: mac: Fix calulation for number of resident pages in a process. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 #if defined(OS_MACOSX)
600 size_t private_bytes;
601 size_t shared_bytes;
602 if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes))
603 return false;
604 const uint64_t rss_bytes = rss_bytes_for_testing
605 ? rss_bytes_for_testing
606 : private_bytes + shared_bytes;
Mark Mentovai 2017/03/13 18:13:33 Same here.
erikchen 2017/03/13 21:00:42 Done.
607 pmd->process_totals()->SetExtraFieldInBytes("private_bytes", private_bytes);
Primiano Tucci (use gerrit) 2017/03/13 13:59:34 does this shows up in the UI as is or we need an u
erikchen 2017/03/13 21:00:42 Yes it does. I forgot to include this in the ori
608 pmd->process_totals()->SetExtraFieldInBytes("shared_bytes", shared_bytes);
609 #else
599 const uint64_t rss_bytes = rss_bytes_for_testing 610 const uint64_t rss_bytes = rss_bytes_for_testing
600 ? rss_bytes_for_testing 611 ? rss_bytes_for_testing
601 : process_metrics_->GetWorkingSetSize(); 612 : process_metrics_->GetWorkingSetSize();
Primiano Tucci (use gerrit) 2017/03/13 13:59:34 maybe you can factor out the ? rss_bytes_for_testi
erikchen 2017/03/13 21:00:42 Done.
613 #endif // defined(OS_MACOSX)
602 614
603 // rss_bytes will be 0 if the process ended while dumping. 615 // rss_bytes will be 0 if the process ended while dumping.
604 if (!rss_bytes) 616 if (!rss_bytes)
605 return false; 617 return false;
606 618
607 uint64_t peak_rss_bytes = 0; 619 uint64_t peak_rss_bytes = 0;
608 620
609 #if !defined(OS_IOS) 621 #if !defined(OS_IOS)
610 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize(); 622 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
611 #if defined(OS_LINUX) || defined(OS_ANDROID) 623 #if defined(OS_LINUX) || defined(OS_ANDROID)
612 if (is_rss_peak_resettable_) { 624 if (is_rss_peak_resettable_) {
613 std::string clear_refs_file = 625 std::string clear_refs_file =
614 "/proc/" + 626 "/proc/" +
615 (process_ == base::kNullProcessId ? "self" 627 (process_ == base::kNullProcessId ? "self"
616 : base::IntToString(process_)) + 628 : base::IntToString(process_)) +
617 "/clear_refs"; 629 "/clear_refs";
618 int clear_refs_fd = open(clear_refs_file.c_str(), O_WRONLY); 630 int clear_refs_fd = open(clear_refs_file.c_str(), O_WRONLY);
619 if (clear_refs_fd > 0 && 631 if (clear_refs_fd > 0 &&
620 base::WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand, 632 base::WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand,
621 sizeof(kClearPeakRssCommand))) { 633 sizeof(kClearPeakRssCommand))) {
622 pmd->process_totals()->set_is_peak_rss_resetable(true); 634 pmd->process_totals()->set_is_peak_rss_resetable(true);
623 } else { 635 } else {
624 is_rss_peak_resettable_ = false; 636 is_rss_peak_resettable_ = false;
625 } 637 }
626 close(clear_refs_fd); 638 close(clear_refs_fd);
627 } 639 }
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) 640 #elif defined(OS_WIN)
635 if (args.level_of_detail == 641 if (args.level_of_detail ==
636 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) { 642 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {
637 uint64_t pss_bytes = 0; 643 uint64_t pss_bytes = 0;
638 bool res = process_metrics_->GetProportionalSetSizeBytes(&pss_bytes); 644 bool res = process_metrics_->GetProportionalSetSizeBytes(&pss_bytes);
639 if (res) { 645 if (res) {
640 base::trace_event::ProcessMemoryMaps::VMRegion region; 646 base::trace_event::ProcessMemoryMaps::VMRegion region;
641 region.byte_stats_proportional_resident = pss_bytes; 647 region.byte_stats_proportional_resident = pss_bytes;
642 pmd->process_mmaps()->AddVMRegion(region); 648 pmd->process_mmaps()->AddVMRegion(region);
643 pmd->set_has_process_mmaps(); 649 pmd->set_has_process_mmaps();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 #endif 691 #endif
686 } 692 }
687 693
688 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { 694 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() {
689 #if defined(OS_LINUX) || defined(OS_ANDROID) 695 #if defined(OS_LINUX) || defined(OS_ANDROID)
690 fast_polling_statm_fd_.reset(); 696 fast_polling_statm_fd_.reset();
691 #endif 697 #endif
692 } 698 }
693 699
694 } // namespace tracing 700 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698