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

Side by Side Diff: base/process/process_metrics_linux.cc

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

Powered by Google App Engine
This is Rietveld 408576698