system/core
Révision | 06766e197d2a7a66c5b0818d1e306d9c855a6e7f (tree) |
---|---|
l'heure | 2019-04-11 03:28:55 |
Auteur | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge "libmeminfo/procrank: Ignore failures when process disappears." into qt-dev
@@ -14,11 +14,17 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | +#include <android-base/file.h> | |
18 | +#include <android-base/parseint.h> | |
19 | +#include <android-base/stringprintf.h> | |
20 | +#include <android-base/strings.h> | |
17 | 21 | #include <dirent.h> |
18 | 22 | #include <errno.h> |
19 | 23 | #include <inttypes.h> |
20 | 24 | #include <linux/kernel-page-flags.h> |
21 | 25 | #include <linux/oom.h> |
26 | +#include <meminfo/procmeminfo.h> | |
27 | +#include <meminfo/sysmeminfo.h> | |
22 | 28 | #include <stdio.h> |
23 | 29 | #include <stdlib.h> |
24 | 30 | #include <sys/types.h> |
@@ -29,14 +35,6 @@ | ||
29 | 35 | #include <sstream> |
30 | 36 | #include <vector> |
31 | 37 | |
32 | -#include <android-base/file.h> | |
33 | -#include <android-base/parseint.h> | |
34 | -#include <android-base/stringprintf.h> | |
35 | -#include <android-base/strings.h> | |
36 | - | |
37 | -#include <meminfo/procmeminfo.h> | |
38 | -#include <meminfo/sysmeminfo.h> | |
39 | - | |
40 | 38 | using ::android::meminfo::MemUsage; |
41 | 39 | using ::android::meminfo::ProcMemInfo; |
42 | 40 |
@@ -460,8 +458,16 @@ int main(int argc, char* argv[]) { | ||
460 | 458 | auto mark_swap_usage = [&](pid_t pid) -> bool { |
461 | 459 | ProcessRecord proc(pid, show_wss, pgflags, pgflags_mask); |
462 | 460 | if (!proc.valid()) { |
463 | - std::cerr << "Failed to create process record for: " << pid << std::endl; | |
464 | - return false; | |
461 | + // Check to see if the process is still around, skip the process if the proc | |
462 | + // directory is inaccessible. It was most likely killed while creating the process | |
463 | + // record | |
464 | + std::string procdir = ::android::base::StringPrintf("/proc/%d", pid); | |
465 | + if (access(procdir.c_str(), F_OK | R_OK)) return true; | |
466 | + | |
467 | + // Warn if we failed to gather process stats even while it is still alive. | |
468 | + // Return success here, so we continue to print stats for other processes. | |
469 | + std::cerr << "warning: failed to create process record for: " << pid << std::endl; | |
470 | + return true; | |
465 | 471 | } |
466 | 472 | |
467 | 473 | // Skip processes with no memory mappings |
@@ -479,9 +485,9 @@ int main(int argc, char* argv[]) { | ||
479 | 485 | return true; |
480 | 486 | }; |
481 | 487 | |
482 | - // Get a list of all pids currently running in the system in | |
483 | - // 1st pass through all processes. Mark each swap offset used by the process as we find them | |
484 | - // for calculating proportional swap usage later. | |
488 | + // Get a list of all pids currently running in the system in 1st pass through all processes. | |
489 | + // Mark each swap offset used by the process as we find them for calculating proportional | |
490 | + // swap usage later. | |
485 | 491 | if (!read_all_pids(&pids, mark_swap_usage)) { |
486 | 492 | std::cerr << "Failed to read all pids from the system" << std::endl; |
487 | 493 | exit(EXIT_FAILURE); |