| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 pgmajfault = 0; | 503 pgmajfault = 0; |
| 504 | 504 |
| 505 #ifdef OS_CHROMEOS | 505 #ifdef OS_CHROMEOS |
| 506 shmem = 0; | 506 shmem = 0; |
| 507 slab = 0; | 507 slab = 0; |
| 508 gem_objects = -1; | 508 gem_objects = -1; |
| 509 gem_size = -1; | 509 gem_size = -1; |
| 510 #endif | 510 #endif |
| 511 } | 511 } |
| 512 | 512 |
| 513 scoped_ptr<Value> SystemMemoryInfoKB::ToValue() const { |
| 514 scoped_ptr<DictionaryValue> res(new base::DictionaryValue()); |
| 515 |
| 516 res->SetInteger("total", total); |
| 517 res->SetInteger("free", free); |
| 518 res->SetInteger("buffers", buffers); |
| 519 res->SetInteger("cached", cached); |
| 520 res->SetInteger("active_anon", active_anon); |
| 521 res->SetInteger("inactive_anon", inactive_anon); |
| 522 res->SetInteger("active_file", active_file); |
| 523 res->SetInteger("inactive_file", inactive_file); |
| 524 res->SetInteger("swap_total", swap_total); |
| 525 res->SetInteger("swap_free", swap_free); |
| 526 res->SetInteger("swap_used", swap_total - swap_free); |
| 527 res->SetInteger("dirty", dirty); |
| 528 res->SetInteger("pswpin", pswpin); |
| 529 res->SetInteger("pswpout", pswpout); |
| 530 res->SetInteger("pgmajfault", pgmajfault); |
| 531 #ifdef OS_CHROMEOS |
| 532 res->SetInteger("shmem", shmem); |
| 533 res->SetInteger("slab", slab); |
| 534 res->SetInteger("gem_objects", gem_objects); |
| 535 res->SetInteger("gem_size", gem_size); |
| 536 #endif |
| 537 |
| 538 return res.PassAs<Value>(); |
| 539 } |
| 540 |
| 513 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 541 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
| 514 // Synchronously reading files in /proc is safe. | 542 // Synchronously reading files in /proc is safe. |
| 515 ThreadRestrictions::ScopedAllowIO allow_io; | 543 ThreadRestrictions::ScopedAllowIO allow_io; |
| 516 | 544 |
| 517 // Used memory is: total - free - buffers - caches | 545 // Used memory is: total - free - buffers - caches |
| 518 FilePath meminfo_file("/proc/meminfo"); | 546 FilePath meminfo_file("/proc/meminfo"); |
| 519 std::string meminfo_data; | 547 std::string meminfo_data; |
| 520 if (!ReadFileToString(meminfo_file, &meminfo_data)) { | 548 if (!ReadFileToString(meminfo_file, &meminfo_data)) { |
| 521 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); | 549 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); |
| 522 return false; | 550 return false; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 read_time = 0; | 660 read_time = 0; |
| 633 writes = 0; | 661 writes = 0; |
| 634 writes_merged = 0; | 662 writes_merged = 0; |
| 635 sectors_written = 0; | 663 sectors_written = 0; |
| 636 write_time = 0; | 664 write_time = 0; |
| 637 io = 0; | 665 io = 0; |
| 638 io_time = 0; | 666 io_time = 0; |
| 639 weighted_io_time = 0; | 667 weighted_io_time = 0; |
| 640 } | 668 } |
| 641 | 669 |
| 670 scoped_ptr<Value> SystemDiskInfo::ToValue() const { |
| 671 scoped_ptr<DictionaryValue> res(new base::DictionaryValue()); |
| 672 |
| 673 // Write out uint64 variables as doubles. |
| 674 // Note: this may discard some precision, but for JS there's no other option. |
| 675 res->SetDouble("reads", static_cast<double>(reads)); |
| 676 res->SetDouble("reads_merged", static_cast<double>(reads_merged)); |
| 677 res->SetDouble("sectors_read", static_cast<double>(sectors_read)); |
| 678 res->SetDouble("read_time", static_cast<double>(read_time)); |
| 679 res->SetDouble("writes", static_cast<double>(writes)); |
| 680 res->SetDouble("writes_merged", static_cast<double>(writes_merged)); |
| 681 res->SetDouble("sectors_written", static_cast<double>(sectors_written)); |
| 682 res->SetDouble("write_time", static_cast<double>(write_time)); |
| 683 res->SetDouble("io", static_cast<double>(io)); |
| 684 res->SetDouble("io_time", static_cast<double>(io_time)); |
| 685 res->SetDouble("weighted_io_time", static_cast<double>(weighted_io_time)); |
| 686 |
| 687 return res.PassAs<Value>(); |
| 688 } |
| 689 |
| 642 bool IsValidDiskName(const std::string& candidate) { | 690 bool IsValidDiskName(const std::string& candidate) { |
| 643 if (candidate.length() < 3) | 691 if (candidate.length() < 3) |
| 644 return false; | 692 return false; |
| 645 if (candidate.substr(0,2) == "sd" || candidate.substr(0,2) == "hd") { | 693 if (candidate.substr(0,2) == "sd" || candidate.substr(0,2) == "hd") { |
| 646 // [sh]d[a-z]+ case | 694 // [sh]d[a-z]+ case |
| 647 for (size_t i = 2; i < candidate.length(); i++) { | 695 for (size_t i = 2; i < candidate.length(); i++) { |
| 648 if (!islower(candidate[i])) | 696 if (!islower(candidate[i])) |
| 649 return false; | 697 return false; |
| 650 } | 698 } |
| 651 } else { | 699 } else { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 diskinfo->io += io; | 785 diskinfo->io += io; |
| 738 diskinfo->io_time += io_time; | 786 diskinfo->io_time += io_time; |
| 739 diskinfo->weighted_io_time += weighted_io_time; | 787 diskinfo->weighted_io_time += weighted_io_time; |
| 740 } | 788 } |
| 741 } | 789 } |
| 742 | 790 |
| 743 return true; | 791 return true; |
| 744 } | 792 } |
| 745 | 793 |
| 746 #if defined(OS_CHROMEOS) | 794 #if defined(OS_CHROMEOS) |
| 795 scoped_ptr<Value> SwapInfo::ToValue() const { |
| 796 scoped_ptr<DictionaryValue> res(new DictionaryValue()); |
| 797 |
| 798 // Write out uint64 variables as doubles. |
| 799 // Note: this may discard some precision, but for JS there's no other option. |
| 800 res->SetDouble("num_reads", static_cast<double>(num_reads)); |
| 801 res->SetDouble("num_writes", static_cast<double>(num_writes)); |
| 802 res->SetDouble("orig_data_size", static_cast<double>(orig_data_size)); |
| 803 res->SetDouble("compr_data_size", static_cast<double>(compr_data_size)); |
| 804 res->SetDouble("mem_used_total", static_cast<double>(mem_used_total)); |
| 805 if (compr_data_size > 0) |
| 806 res->SetDouble("compression_ratio", static_cast<double>(orig_data_size) / |
| 807 static_cast<double>(compr_data_size)); |
| 808 else |
| 809 res->SetDouble("compression_ratio", 0); |
| 810 |
| 811 return res.PassAs<Value>(); |
| 812 } |
| 813 |
| 747 void GetSwapInfo(SwapInfo* swap_info) { | 814 void GetSwapInfo(SwapInfo* swap_info) { |
| 748 // Synchronously reading files in /sys/block/zram0 is safe. | 815 // Synchronously reading files in /sys/block/zram0 is safe. |
| 749 ThreadRestrictions::ScopedAllowIO allow_io; | 816 ThreadRestrictions::ScopedAllowIO allow_io; |
| 750 | 817 |
| 751 base::FilePath zram_path("/sys/block/zram0"); | 818 base::FilePath zram_path("/sys/block/zram0"); |
| 752 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); | 819 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); |
| 753 if (orig_data_size <= 4096) { | 820 if (orig_data_size <= 4096) { |
| 754 // A single page is compressed at startup, and has a high compression | 821 // A single page is compressed at startup, and has a high compression |
| 755 // ratio. We ignore this as it doesn't indicate any real swapping. | 822 // ratio. We ignore this as it doesn't indicate any real swapping. |
| 756 swap_info->orig_data_size = 0; | 823 swap_info->orig_data_size = 0; |
| 757 swap_info->num_reads = 0; | 824 swap_info->num_reads = 0; |
| 758 swap_info->num_writes = 0; | 825 swap_info->num_writes = 0; |
| 759 swap_info->compr_data_size = 0; | 826 swap_info->compr_data_size = 0; |
| 760 swap_info->mem_used_total = 0; | 827 swap_info->mem_used_total = 0; |
| 761 return; | 828 return; |
| 762 } | 829 } |
| 763 swap_info->orig_data_size = orig_data_size; | 830 swap_info->orig_data_size = orig_data_size; |
| 764 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); | 831 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); |
| 765 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); | 832 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); |
| 766 swap_info->compr_data_size = | 833 swap_info->compr_data_size = |
| 767 ReadFileToUint64(zram_path.Append("compr_data_size")); | 834 ReadFileToUint64(zram_path.Append("compr_data_size")); |
| 768 swap_info->mem_used_total = | 835 swap_info->mem_used_total = |
| 769 ReadFileToUint64(zram_path.Append("mem_used_total")); | 836 ReadFileToUint64(zram_path.Append("mem_used_total")); |
| 770 } | 837 } |
| 771 #endif // defined(OS_CHROMEOS) | 838 #endif // defined(OS_CHROMEOS) |
| 772 | 839 |
| 773 } // namespace base | 840 } // namespace base |
| OLD | NEW |