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> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 #include <utility> |
13 | 14 |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/process/internal_linux.h" | 17 #include "base/process/internal_linux.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
19 #include "base/strings/string_tokenizer.h" | 20 #include "base/strings/string_tokenizer.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/sys_info.h" | 22 #include "base/sys_info.h" |
22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 res->SetInteger("pswpin", pswpin); | 538 res->SetInteger("pswpin", pswpin); |
538 res->SetInteger("pswpout", pswpout); | 539 res->SetInteger("pswpout", pswpout); |
539 res->SetInteger("pgmajfault", pgmajfault); | 540 res->SetInteger("pgmajfault", pgmajfault); |
540 #ifdef OS_CHROMEOS | 541 #ifdef OS_CHROMEOS |
541 res->SetInteger("shmem", shmem); | 542 res->SetInteger("shmem", shmem); |
542 res->SetInteger("slab", slab); | 543 res->SetInteger("slab", slab); |
543 res->SetInteger("gem_objects", gem_objects); | 544 res->SetInteger("gem_objects", gem_objects); |
544 res->SetInteger("gem_size", gem_size); | 545 res->SetInteger("gem_size", gem_size); |
545 #endif | 546 #endif |
546 | 547 |
547 return res.Pass(); | 548 return std::move(res); |
548 } | 549 } |
549 | 550 |
550 // exposed for testing | 551 // exposed for testing |
551 bool ParseProcMeminfo(const std::string& meminfo_data, | 552 bool ParseProcMeminfo(const std::string& meminfo_data, |
552 SystemMemoryInfoKB* meminfo) { | 553 SystemMemoryInfoKB* meminfo) { |
553 // The format of /proc/meminfo is: | 554 // The format of /proc/meminfo is: |
554 // | 555 // |
555 // MemTotal: 8235324 kB | 556 // MemTotal: 8235324 kB |
556 // MemFree: 1628304 kB | 557 // MemFree: 1628304 kB |
557 // Buffers: 429596 kB | 558 // Buffers: 429596 kB |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 res->SetDouble("sectors_read", static_cast<double>(sectors_read)); | 741 res->SetDouble("sectors_read", static_cast<double>(sectors_read)); |
741 res->SetDouble("read_time", static_cast<double>(read_time)); | 742 res->SetDouble("read_time", static_cast<double>(read_time)); |
742 res->SetDouble("writes", static_cast<double>(writes)); | 743 res->SetDouble("writes", static_cast<double>(writes)); |
743 res->SetDouble("writes_merged", static_cast<double>(writes_merged)); | 744 res->SetDouble("writes_merged", static_cast<double>(writes_merged)); |
744 res->SetDouble("sectors_written", static_cast<double>(sectors_written)); | 745 res->SetDouble("sectors_written", static_cast<double>(sectors_written)); |
745 res->SetDouble("write_time", static_cast<double>(write_time)); | 746 res->SetDouble("write_time", static_cast<double>(write_time)); |
746 res->SetDouble("io", static_cast<double>(io)); | 747 res->SetDouble("io", static_cast<double>(io)); |
747 res->SetDouble("io_time", static_cast<double>(io_time)); | 748 res->SetDouble("io_time", static_cast<double>(io_time)); |
748 res->SetDouble("weighted_io_time", static_cast<double>(weighted_io_time)); | 749 res->SetDouble("weighted_io_time", static_cast<double>(weighted_io_time)); |
749 | 750 |
750 return res.Pass(); | 751 return std::move(res); |
751 } | 752 } |
752 | 753 |
753 bool IsValidDiskName(const std::string& candidate) { | 754 bool IsValidDiskName(const std::string& candidate) { |
754 if (candidate.length() < 3) | 755 if (candidate.length() < 3) |
755 return false; | 756 return false; |
756 if (candidate[1] == 'd' && | 757 if (candidate[1] == 'd' && |
757 (candidate[0] == 'h' || candidate[0] == 's' || candidate[0] == 'v')) { | 758 (candidate[0] == 'h' || candidate[0] == 's' || candidate[0] == 'v')) { |
758 // [hsv]d[a-z]+ case | 759 // [hsv]d[a-z]+ case |
759 for (size_t i = 2; i < candidate.length(); ++i) { | 760 for (size_t i = 2; i < candidate.length(); ++i) { |
760 if (!islower(candidate[i])) | 761 if (!islower(candidate[i])) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 res->SetDouble("num_writes", static_cast<double>(num_writes)); | 866 res->SetDouble("num_writes", static_cast<double>(num_writes)); |
866 res->SetDouble("orig_data_size", static_cast<double>(orig_data_size)); | 867 res->SetDouble("orig_data_size", static_cast<double>(orig_data_size)); |
867 res->SetDouble("compr_data_size", static_cast<double>(compr_data_size)); | 868 res->SetDouble("compr_data_size", static_cast<double>(compr_data_size)); |
868 res->SetDouble("mem_used_total", static_cast<double>(mem_used_total)); | 869 res->SetDouble("mem_used_total", static_cast<double>(mem_used_total)); |
869 if (compr_data_size > 0) | 870 if (compr_data_size > 0) |
870 res->SetDouble("compression_ratio", static_cast<double>(orig_data_size) / | 871 res->SetDouble("compression_ratio", static_cast<double>(orig_data_size) / |
871 static_cast<double>(compr_data_size)); | 872 static_cast<double>(compr_data_size)); |
872 else | 873 else |
873 res->SetDouble("compression_ratio", 0); | 874 res->SetDouble("compression_ratio", 0); |
874 | 875 |
875 return res.Pass(); | 876 return std::move(res); |
876 } | 877 } |
877 | 878 |
878 void GetSwapInfo(SwapInfo* swap_info) { | 879 void GetSwapInfo(SwapInfo* swap_info) { |
879 // Synchronously reading files in /sys/block/zram0 does not hit the disk. | 880 // Synchronously reading files in /sys/block/zram0 does not hit the disk. |
880 ThreadRestrictions::ScopedAllowIO allow_io; | 881 ThreadRestrictions::ScopedAllowIO allow_io; |
881 | 882 |
882 FilePath zram_path("/sys/block/zram0"); | 883 FilePath zram_path("/sys/block/zram0"); |
883 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); | 884 uint64 orig_data_size = ReadFileToUint64(zram_path.Append("orig_data_size")); |
884 if (orig_data_size <= 4096) { | 885 if (orig_data_size <= 4096) { |
885 // A single page is compressed at startup, and has a high compression | 886 // A single page is compressed at startup, and has a high compression |
(...skipping 18 matching lines...) Expand all Loading... |
904 #if defined(OS_LINUX) | 905 #if defined(OS_LINUX) |
905 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 906 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
906 uint64 wake_ups; | 907 uint64 wake_ups; |
907 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 908 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
908 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 909 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
909 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 910 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
910 } | 911 } |
911 #endif // defined(OS_LINUX) | 912 #endif // defined(OS_LINUX) |
912 | 913 |
913 } // namespace base | 914 } // namespace base |
OLD | NEW |