| 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // We iterate through the whole file because the position of the | 680 // We iterate through the whole file because the position of the |
| 681 // fields are dependent on the kernel version and configuration. | 681 // fields are dependent on the kernel version and configuration. |
| 682 | 682 |
| 683 for (const StringPiece& line : SplitStringPiece( | 683 for (const StringPiece& line : SplitStringPiece( |
| 684 vmstat_data, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) { | 684 vmstat_data, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) { |
| 685 std::vector<StringPiece> tokens = SplitStringPiece( | 685 std::vector<StringPiece> tokens = SplitStringPiece( |
| 686 line, " ", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); | 686 line, " ", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY); |
| 687 if (tokens.size() != 2) | 687 if (tokens.size() != 2) |
| 688 continue; | 688 continue; |
| 689 | 689 |
| 690 uint64_t val; |
| 691 if (!StringToUint64(tokens[1], &val)) |
| 692 continue; |
| 693 |
| 690 if (tokens[0] == "pswpin") { | 694 if (tokens[0] == "pswpin") { |
| 691 StringToInt(tokens[1], &meminfo->pswpin); | 695 meminfo->pswpin = val; |
| 692 } else if (tokens[0] == "pswpout") { | 696 } else if (tokens[0] == "pswpout") { |
| 693 StringToInt(tokens[1], &meminfo->pswpout); | 697 meminfo->pswpout = val; |
| 694 } else if (tokens[0] == "pgmajfault") { | 698 } else if (tokens[0] == "pgmajfault") { |
| 695 StringToInt(tokens[1], &meminfo->pgmajfault); | 699 meminfo->pgmajfault = val; |
| 696 } | 700 } |
| 697 } | 701 } |
| 698 | 702 |
| 699 return true; | 703 return true; |
| 700 } | 704 } |
| 701 | 705 |
| 702 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 706 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
| 703 // Synchronously reading files in /proc and /sys are safe. | 707 // Synchronously reading files in /proc and /sys are safe. |
| 704 ThreadRestrictions::ScopedAllowIO allow_io; | 708 ThreadRestrictions::ScopedAllowIO allow_io; |
| 705 | 709 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 #if defined(OS_LINUX) | 962 #if defined(OS_LINUX) |
| 959 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 963 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
| 960 uint64_t wake_ups; | 964 uint64_t wake_ups; |
| 961 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 965 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
| 962 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 966 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
| 963 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 967 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
| 964 } | 968 } |
| 965 #endif // defined(OS_LINUX) | 969 #endif // defined(OS_LINUX) |
| 966 | 970 |
| 967 } // namespace base | 971 } // namespace base |
| OLD | NEW |