• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

system/core


Commit MetaInfo

修訂c4c05e3b25c4e2935f5214850b8ff3103f94dc25 (tree)
時間2019-04-11 00:01:06
作者Sandeep Patil <sspatil@goog...>
CommiterSandeep Patil

Log Message

libmeminfo/procrank: Ignore failures when process disappears.

procrank currently fails if a process gets killed while it is reading
the stats. This behavior is a regression from the previous version of
procrank and is often undesired.

Change procrank to silently ignore the process if it detects that it had
been killed while reading the stats. If the process is still around,
then print a warning about it and continue to read stats for other
processes in the system.

Fixes: 130177765
Test: Tested by deliberately killing specific process in ProcessRecord()

constructor

Change-Id: I701808c3226bb9b3a350ccf8e67fb29b59b0d4e0
Merged-In: I701808c3226bb9b3a350ccf8e67fb29b59b0d4e0
Signed-off-by: Sandeep Patil <sspatil@google.com>

Change Summary

差異

--- 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);