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 <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 // We iterate through the whole file because the position of the | 669 // We iterate through the whole file because the position of the |
670 // fields are dependent on the kernel version and configuration. | 670 // fields are dependent on the kernel version and configuration. |
671 | 671 |
672 for (const StringPiece& line : SplitStringPiece( | 672 for (const StringPiece& line : SplitStringPiece( |
673 vmstat_data, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) { | 673 vmstat_data, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) { |
674 std::vector<StringPiece> tokens = SplitStringPiece( | 674 std::vector<StringPiece> tokens = SplitStringPiece( |
675 line, " ", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); | 675 line, " ", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); |
676 if (tokens.size() != 2) | 676 if (tokens.size() != 2) |
677 continue; | 677 continue; |
678 | 678 |
679 uint64_t val; | |
680 if (!StringToUint64(tokens[1], &val)) | |
681 continue; | |
682 | |
679 if (tokens[0] == "pswpin") { | 683 if (tokens[0] == "pswpin") { |
680 StringToInt(tokens[1], &meminfo->pswpin); | 684 meminfo->pswpin = val; |
Lei Zhang
2016/07/28 18:38:05
Can we just make pswpin and friends uint64_t? Aren
| |
681 } else if (tokens[0] == "pswpout") { | 685 } else if (tokens[0] == "pswpout") { |
682 StringToInt(tokens[1], &meminfo->pswpout); | 686 meminfo->pswpout = val; |
683 } else if (tokens[0] == "pgmajfault") { | 687 } else if (tokens[0] == "pgmajfault") { |
684 StringToInt(tokens[1], &meminfo->pgmajfault); | 688 meminfo->pgmajfault = val; |
685 } | 689 } |
686 } | 690 } |
687 | 691 |
688 return true; | 692 return true; |
689 } | 693 } |
690 | 694 |
691 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 695 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
692 // Synchronously reading files in /proc and /sys are safe. | 696 // Synchronously reading files in /proc and /sys are safe. |
693 ThreadRestrictions::ScopedAllowIO allow_io; | 697 ThreadRestrictions::ScopedAllowIO allow_io; |
694 | 698 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 #if defined(OS_LINUX) | 951 #if defined(OS_LINUX) |
948 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 952 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
949 uint64_t wake_ups; | 953 uint64_t wake_ups; |
950 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 954 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
951 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 955 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
952 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 956 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
953 } | 957 } |
954 #endif // defined(OS_LINUX) | 958 #endif // defined(OS_LINUX) |
955 | 959 |
956 } // namespace base | 960 } // namespace base |
OLD | NEW |