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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 pgmajfault_per_sec = 0; | 507 pgmajfault_per_sec = 0; |
508 | 508 |
509 #ifdef OS_CHROMEOS | 509 #ifdef OS_CHROMEOS |
510 shmem = 0; | 510 shmem = 0; |
511 slab = 0; | 511 slab = 0; |
512 gem_objects = -1; | 512 gem_objects = -1; |
513 gem_size = -1; | 513 gem_size = -1; |
514 #endif | 514 #endif |
515 } | 515 } |
516 | 516 |
517 Value* SystemMemoryInfoKB::AsValue() const { | |
nduca
2013/08/14 18:08:58
this hsould be in process_metrics.cc with #ifdefs
| |
518 DictionaryValue* res = new base::DictionaryValue(); | |
519 | |
520 res->SetInteger("total", total); | |
521 res->SetInteger("free", free); | |
522 res->SetInteger("buffers", buffers); | |
523 res->SetInteger("cached", cached); | |
524 res->SetInteger("active_anon", active_anon); | |
525 res->SetInteger("inactive_anon", inactive_anon); | |
526 res->SetInteger("active_file", active_file); | |
527 res->SetInteger("inactive_file", inactive_file); | |
528 res->SetInteger("swap_total", swap_total); | |
529 res->SetInteger("swap_free", swap_free); | |
530 res->SetInteger("swap_used", swap_total - swap_free); | |
531 res->SetInteger("dirty", dirty); | |
532 res->SetInteger("pswpin", pswpin); | |
533 res->SetInteger("pswpout", pswpout); | |
534 res->SetInteger("pgmajfault", pgmajfault); | |
535 res->SetInteger("bytes_swpin_per_sec", bytes_swpin_per_sec); | |
536 res->SetInteger("bytes_swpout_per_sec", bytes_swpout_per_sec); | |
537 res->SetInteger("pgmajfault_per_sec", pgmajfault_per_sec); | |
538 #ifdef OS_CHROMEOS | |
539 res->SetInteger("shmem", shmem); | |
540 res->SetInteger("slab", slab); | |
541 res->SetInteger("gem_objects", gem_objects); | |
542 res->SetInteger("gem_size", gem_size); | |
543 #endif | |
544 | |
545 return res; | |
546 } | |
547 | |
517 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 548 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
518 // Synchronously reading files in /proc is safe. | 549 // Synchronously reading files in /proc is safe. |
519 ThreadRestrictions::ScopedAllowIO allow_io; | 550 ThreadRestrictions::ScopedAllowIO allow_io; |
520 | 551 |
521 // Used memory is: total - free - buffers - caches | 552 // Used memory is: total - free - buffers - caches |
522 FilePath meminfo_file("/proc/meminfo"); | 553 FilePath meminfo_file("/proc/meminfo"); |
523 std::string meminfo_data; | 554 std::string meminfo_data; |
524 if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) { | 555 if (!file_util::ReadFileToString(meminfo_file, &meminfo_data)) { |
525 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); | 556 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); |
526 return false; | 557 return false; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 writes_merged = 0; | 665 writes_merged = 0; |
635 sectors_written = 0; | 666 sectors_written = 0; |
636 write_time = 0; | 667 write_time = 0; |
637 io = 0; | 668 io = 0; |
638 io_time = 0; | 669 io_time = 0; |
639 weighted_io_time = 0; | 670 weighted_io_time = 0; |
640 bytes_read_per_sec = 0; | 671 bytes_read_per_sec = 0; |
641 bytes_written_per_sec = 0; | 672 bytes_written_per_sec = 0; |
642 } | 673 } |
643 | 674 |
675 Value* SystemDiskInfo::AsValue() const { | |
676 DictionaryValue* res = new base::DictionaryValue(); | |
677 | |
678 res->SetInteger("bytes_read_per_sec",bytes_read_per_sec); | |
679 res->SetInteger("bytes_written_per_sec", bytes_written_per_sec); | |
680 | |
681 return res; | |
682 } | |
683 | |
644 bool ValidDiskName(const std::string& candidate) { | 684 bool ValidDiskName(const std::string& candidate) { |
645 if (candidate.length() < 3) | 685 if (candidate.length() < 3) |
646 return false; | 686 return false; |
647 if (candidate.substr(0,2) == "sd" || candidate.substr(0,2) == "hd") { | 687 if (candidate.substr(0,2) == "sd" || candidate.substr(0,2) == "hd") { |
648 // [sh]d[a-z]+ case | 688 // [sh]d[a-z]+ case |
649 for (size_t i = 2; i < candidate.length(); i++) { | 689 for (size_t i = 2; i < candidate.length(); i++) { |
650 if (!islower(candidate[i])) | 690 if (!islower(candidate[i])) |
651 return false; | 691 return false; |
652 } | 692 } |
653 } else { | 693 } else { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 diskinfo->io += io; | 779 diskinfo->io += io; |
740 diskinfo->io_time += io_time; | 780 diskinfo->io_time += io_time; |
741 diskinfo->weighted_io_time += weighted_io_time; | 781 diskinfo->weighted_io_time += weighted_io_time; |
742 } | 782 } |
743 } | 783 } |
744 | 784 |
745 return true; | 785 return true; |
746 } | 786 } |
747 | 787 |
748 #if defined(OS_CHROMEOS) | 788 #if defined(OS_CHROMEOS) |
789 Value* SwapInfo::AsValue() const { | |
790 DictionaryValue* res = new base::DictionaryValue(); | |
791 | |
792 res->SetInteger("num_reads", num_reads); | |
793 res->SetInteger("num_writes", num_writes); | |
794 res->SetInteger("orig_data_size", orig_data_size); | |
795 res->SetInteger("compr_data_size", compr_data_size); | |
796 res->SetInteger("mem_used_total", mem_used_total); | |
797 if (compr_data_size > 0) { | |
nduca
2013/08/14 18:08:58
one line ifs dont get braces
| |
798 res->SetInteger("compression_ratio", orig_data_size / compr_data_size); | |
799 } | |
800 | |
801 return res; | |
802 } | |
803 | |
749 void GetSwapInfo(SwapInfo* swap_info) { | 804 void GetSwapInfo(SwapInfo* swap_info) { |
750 // Synchronously reading files in /sys/block/zram0 is safe. | 805 // Synchronously reading files in /sys/block/zram0 is safe. |
751 ThreadRestrictions::ScopedAllowIO allow_io; | 806 ThreadRestrictions::ScopedAllowIO allow_io; |
752 | 807 |
753 base::FilePath zram_path("/sys/block/zram0"); | 808 base::FilePath zram_path("/sys/block/zram0"); |
754 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); | 809 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); |
755 if (orig_data_size <= 4096) { | 810 if (orig_data_size <= 4096) { |
756 // A single page is compressed at startup, and has a high compression | 811 // A single page is compressed at startup, and has a high compression |
757 // ratio. We ignore this as it doesn't indicate any real swapping. | 812 // ratio. We ignore this as it doesn't indicate any real swapping. |
758 swap_info->orig_data_size = 0; | 813 swap_info->orig_data_size = 0; |
759 swap_info->num_reads = 0; | 814 swap_info->num_reads = 0; |
760 swap_info->num_writes = 0; | 815 swap_info->num_writes = 0; |
761 swap_info->compr_data_size = 0; | 816 swap_info->compr_data_size = 0; |
762 swap_info->mem_used_total = 0; | 817 swap_info->mem_used_total = 0; |
763 return; | 818 return; |
764 } | 819 } |
765 swap_info->orig_data_size = orig_data_size; | 820 swap_info->orig_data_size = orig_data_size; |
766 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); | 821 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); |
767 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); | 822 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); |
768 swap_info->compr_data_size = | 823 swap_info->compr_data_size = |
769 ReadFileToUint64(zram_path.Append("compr_data_size")); | 824 ReadFileToUint64(zram_path.Append("compr_data_size")); |
770 swap_info->mem_used_total = | 825 swap_info->mem_used_total = |
771 ReadFileToUint64(zram_path.Append("mem_used_total")); | 826 ReadFileToUint64(zram_path.Append("mem_used_total")); |
772 } | 827 } |
773 #endif // defined(OS_CHROMEOS) | 828 #endif // defined(OS_CHROMEOS) |
774 | 829 |
775 } // namespace base | 830 } // namespace base |
OLD | NEW |