OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/chrome_process_util.h" | 5 #include "chrome/test/base/chrome_process_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
14 #include "base/process/process_iterator.h" | 14 #include "base/process/process_iterator.h" |
| 15 #include "base/process/process_metrics.h" |
| 16 #include "base/stl_util.h" |
15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
17 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
19 #include "content/public/common/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
20 | 22 |
21 using base::TimeDelta; | 23 using base::TimeDelta; |
22 using base::TimeTicks; | 24 using base::TimeTicks; |
23 | 25 |
24 void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) { | 26 void TerminateAllChromeProcesses(const ChromeProcessList& process_pids) { |
25 ChromeProcessList::const_iterator it; | 27 for (auto pid : process_pids) { |
26 for (it = process_pids.begin(); it != process_pids.end(); ++it) { | 28 base::Process process = base::Process::Open(pid); |
27 base::Process process = base::Process::Open(*it); | |
28 if (process.IsValid()) { | 29 if (process.IsValid()) { |
29 // Ignore processes for which we can't open the handle. We don't | 30 // Ignore processes for which we can't open the handle. We don't |
30 // guarantee that all processes will terminate, only try to do so. | 31 // guarantee that all processes will terminate, only try to do so. |
31 process.Terminate(content::RESULT_CODE_KILLED, true); | 32 process.Terminate(content::RESULT_CODE_KILLED, true); |
32 } | 33 } |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 class ChildProcessFilter : public base::ProcessFilter { | 37 class ChildProcessFilter : public base::ProcessFilter { |
37 public: | 38 public: |
38 explicit ChildProcessFilter(base::ProcessId parent_pid) | 39 explicit ChildProcessFilter(base::ProcessId parent_pid) |
39 : parent_pids_(&parent_pid, (&parent_pid) + 1) {} | 40 : parent_pids_(&parent_pid, (&parent_pid) + 1) {} |
40 | 41 |
41 explicit ChildProcessFilter(const std::vector<base::ProcessId>& parent_pids) | 42 explicit ChildProcessFilter(const std::vector<base::ProcessId>& parent_pids) |
42 : parent_pids_(parent_pids.begin(), parent_pids.end()) {} | 43 : parent_pids_(parent_pids.begin(), parent_pids.end()) {} |
43 | 44 |
44 bool Includes(const base::ProcessEntry& entry) const override { | 45 bool Includes(const base::ProcessEntry& entry) const override { |
45 return parent_pids_.find(entry.parent_pid()) != parent_pids_.end(); | 46 return ContainsKey(parent_pids_, entry.parent_pid()); |
46 } | 47 } |
47 | 48 |
48 private: | 49 private: |
49 const std::set<base::ProcessId> parent_pids_; | 50 const std::set<base::ProcessId> parent_pids_; |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); | 52 DISALLOW_COPY_AND_ASSIGN(ChildProcessFilter); |
52 }; | 53 }; |
53 | 54 |
54 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { | 55 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid) { |
55 const base::FilePath::CharType* executable_name = | 56 const base::FilePath::CharType* executable_name = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 size_t ChromeTestProcessMetrics::GetWorkingSetSize() { | 104 size_t ChromeTestProcessMetrics::GetWorkingSetSize() { |
104 return process_metrics_->GetWorkingSetSize(); | 105 return process_metrics_->GetWorkingSetSize(); |
105 } | 106 } |
106 | 107 |
107 #endif // !defined(OS_MACOSX) | 108 #endif // !defined(OS_MACOSX) |
108 | 109 |
109 ChromeTestProcessMetrics::~ChromeTestProcessMetrics() {} | 110 ChromeTestProcessMetrics::~ChromeTestProcessMetrics() {} |
110 | 111 |
111 ChromeTestProcessMetrics::ChromeTestProcessMetrics( | 112 ChromeTestProcessMetrics::ChromeTestProcessMetrics( |
112 base::ProcessHandle process) { | 113 base::ProcessHandle process) { |
113 #if !defined(OS_MACOSX) | 114 #if defined(OS_MACOSX) |
114 process_metrics_.reset( | 115 process_metrics_ = |
115 base::ProcessMetrics::CreateProcessMetrics(process)); | 116 base::ProcessMetrics::CreateProcessMetrics(process, nullptr); |
116 #else | 117 #else |
117 process_metrics_.reset( | 118 process_metrics_ = base::ProcessMetrics::CreateProcessMetrics(process); |
118 base::ProcessMetrics::CreateProcessMetrics(process, NULL)); | |
119 #endif | 119 #endif |
120 process_handle_ = process; | 120 process_handle_ = process; |
121 } | 121 } |
| 122 |
| 123 size_t ChromeTestProcessMetrics::GetPeakPagefileUsage() { |
| 124 return process_metrics_->GetPeakPagefileUsage(); |
| 125 } |
| 126 |
| 127 size_t ChromeTestProcessMetrics::GetPeakWorkingSetSize() { |
| 128 return process_metrics_->GetPeakWorkingSetSize(); |
| 129 } |
| 130 |
| 131 bool ChromeTestProcessMetrics::GetIOCounters(base::IoCounters* io_counters) { |
| 132 return process_metrics_->GetIOCounters(io_counters); |
| 133 } |
OLD | NEW |