| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef PROCESS_INFO_H_ | 5 #ifndef PROCESS_INFO_H_ |
| 6 #define PROCESS_INFO_H_ | 6 #define PROCESS_INFO_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | |
| 10 | 9 |
| 11 #include "process_memory_stats.h" | 10 #include "process_memory_stats.h" |
| 12 | 11 |
| 13 // Reads various process stats and details from /proc/pid/. | 12 struct ThreadInfo { |
| 14 class ProcessInfo { | 13 int tid; |
| 15 public: | 14 char name[16]; |
| 16 struct ThreadInfo { | 15 }; |
| 17 char name[128] = {}; | |
| 18 }; | |
| 19 using ThreadInfoMap = std::map<int, std::unique_ptr<ThreadInfo>>; | |
| 20 | 16 |
| 21 // Returns true if |pid| is a process (|pid| == TGID), false if it's just a | 17 struct ProcessInfo { |
| 22 // thread of another process, or if |pid| doesn't exist at all. | 18 int pid; |
| 23 static bool IsProcess(int pid); | 19 bool in_kernel; |
| 20 bool is_app; |
| 21 char name[256]; |
| 22 char exe[256]; |
| 23 std::map<int, ThreadInfo> threads; |
| 24 }; |
| 24 | 25 |
| 25 explicit ProcessInfo(int pid); | 26 struct ProcessSnapshot { |
| 26 | 27 int pid; |
| 27 bool ReadProcessName(); | 28 ProcessMemoryStats memory; |
| 28 bool ReadThreadNames(); | 29 // OOM badness and tolerance (oom_adj is deprecated). |
| 29 bool ReadOOMStats(); | 30 int oom_score; |
| 30 bool ReadPageFaultsAndCPUTimeStats(); | 31 int oom_score_adj; |
| 31 | 32 // Page faults. |
| 32 ProcessMemoryStats* memory() { return &memory_; } | 33 unsigned long minor_faults; |
| 33 const ProcessMemoryStats* memory() const { return &memory_; } | 34 unsigned long major_faults; |
| 34 const ThreadInfoMap* threads() const { return &threads_; } | 35 // Time spent in userspace and in the kernel. |
| 35 const char* name() const { return name_; } | 36 unsigned long utime; |
| 36 const char* exe() const { return exe_; } | 37 unsigned long stime; |
| 37 | |
| 38 int oom_adj() const { return oom_adj_; } | |
| 39 int oom_score_adj() const { return oom_score_adj_; } | |
| 40 int oom_score() const { return oom_score_; } | |
| 41 | |
| 42 unsigned long minflt() const { return minflt_; } | |
| 43 unsigned long majflt() const { return majflt_; } | |
| 44 unsigned long utime() const { return utime_; } | |
| 45 unsigned long stime() const { return stime_; } | |
| 46 unsigned long long start_time() const { return start_time_; } | |
| 47 | |
| 48 private: | |
| 49 ProcessInfo(const ProcessInfo&) = delete; | |
| 50 void operator=(const ProcessInfo&) = delete; | |
| 51 | |
| 52 ProcessMemoryStats memory_; | |
| 53 | |
| 54 ThreadInfoMap threads_; | |
| 55 char name_[128] = {}; | |
| 56 char exe_[128] = {}; | |
| 57 | |
| 58 int oom_adj_ = 0; | |
| 59 int oom_score_adj_ = 0; | |
| 60 int oom_score_ = 0; | |
| 61 | |
| 62 unsigned long minflt_ = 0; | |
| 63 unsigned long majflt_ = 0; | |
| 64 unsigned long utime_ = 0; // CPU time in user mode. | |
| 65 unsigned long stime_ = 0; // CPU time in kernel mode. | |
| 66 unsigned long long start_time_ = 0; // CPU time in kernel mode. | |
| 67 | |
| 68 const int pid_; | |
| 69 }; | 38 }; |
| 70 | 39 |
| 71 #endif // PROCESS_INFO_H_ | 40 #endif // PROCESS_INFO_H_ |
| OLD | NEW |