• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


Commit MetaInfo

Révision06766e197d2a7a66c5b0818d1e306d9c855a6e7f (tree)
l'heure2019-04-11 03:28:55
AuteurTreeHugger Robot <treehugger-gerrit@goog...>
CommiterAndroid (Google) Code Review

Message de Log

Merge "libmeminfo/procrank: Ignore failures when process disappears." into qt-dev

Change Summary

Modification

--- a/libmeminfo/tools/procrank.cpp
+++ b/libmeminfo/tools/procrank.cpp
@@ -14,11 +14,17 @@
1414 * limitations under the License.
1515 */
1616
17+#include <android-base/file.h>
18+#include <android-base/parseint.h>
19+#include <android-base/stringprintf.h>
20+#include <android-base/strings.h>
1721 #include <dirent.h>
1822 #include <errno.h>
1923 #include <inttypes.h>
2024 #include <linux/kernel-page-flags.h>
2125 #include <linux/oom.h>
26+#include <meminfo/procmeminfo.h>
27+#include <meminfo/sysmeminfo.h>
2228 #include <stdio.h>
2329 #include <stdlib.h>
2430 #include <sys/types.h>
@@ -29,14 +35,6 @@
2935 #include <sstream>
3036 #include <vector>
3137
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-
4038 using ::android::meminfo::MemUsage;
4139 using ::android::meminfo::ProcMemInfo;
4240
@@ -460,8 +458,16 @@ int main(int argc, char* argv[]) {
460458 auto mark_swap_usage = [&](pid_t pid) -> bool {
461459 ProcessRecord proc(pid, show_wss, pgflags, pgflags_mask);
462460 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;
465471 }
466472
467473 // Skip processes with no memory mappings
@@ -479,9 +485,9 @@ int main(int argc, char* argv[]) {
479485 return true;
480486 };
481487
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.
485491 if (!read_all_pids(&pids, mark_swap_usage)) {
486492 std::cerr << "Failed to read all pids from the system" << std::endl;
487493 exit(EXIT_FAILURE);