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 #ifndef CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ | 5 #ifndef CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ |
6 #define CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ | 6 #define CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
15 #include "base/process/process_metrics.h" | 15 #include "base/process/process_metrics.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 | 17 |
18 typedef std::vector<base::ProcessId> ChromeProcessList; | 18 using ChromeProcessList = std::vector<base::ProcessId>; |
19 | 19 |
20 // Returns a vector of PIDs of all chrome processes (main and renderers etc) | 20 // Returns a vector of PIDs of all chrome processes (main and renderers etc) |
21 // based on |browser_pid|, the PID of the main browser process. | 21 // based on |browser_pid|, the PID of the main browser process. |
22 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid); | 22 ChromeProcessList GetRunningChromeProcesses(base::ProcessId browser_pid); |
23 | 23 |
24 // Attempts to terminate all chrome processes in |process_list|. | 24 // Attempts to terminate all chrome processes in |process_list|. |
25 void TerminateAllChromeProcesses(const ChromeProcessList& process_list); | 25 void TerminateAllChromeProcesses(const ChromeProcessList& process_list); |
26 | 26 |
27 // A wrapper class for tests to use in fetching process metrics. | 27 // A wrapper class for tests to use in fetching process metrics. |
28 // Delegates everything we need to base::ProcessMetrics, except | 28 // Delegates everything we need to base::ProcessMetrics, except |
29 // memory stats on Mac (which have to parse ps output due to privilege | 29 // memory stats on Mac (which have to parse ps output due to privilege |
30 // restrictions, behavior we don't want in base). Long-term, if | 30 // restrictions, behavior we don't want in base). Long-term, if |
31 // the production base::ProcessMetrics gets updated to return | 31 // the production base::ProcessMetrics gets updated to return |
32 // acceptable metrics on Mac, this class should disappear. | 32 // acceptable metrics on Mac, this class should disappear. |
33 class ChromeTestProcessMetrics { | 33 class ChromeTestProcessMetrics { |
34 public: | 34 public: |
35 static ChromeTestProcessMetrics* CreateProcessMetrics( | 35 static ChromeTestProcessMetrics* CreateProcessMetrics( |
36 base::ProcessHandle process) { | 36 base::ProcessHandle process) { |
37 return new ChromeTestProcessMetrics(process); | 37 return new ChromeTestProcessMetrics(process); |
38 } | 38 } |
39 | 39 |
40 size_t GetPagefileUsage(); | 40 size_t GetPagefileUsage(); |
41 | 41 |
42 size_t GetWorkingSetSize(); | 42 size_t GetWorkingSetSize(); |
43 | 43 |
44 size_t GetPeakPagefileUsage() { | 44 size_t GetPeakPagefileUsage(); |
45 return process_metrics_->GetPeakPagefileUsage(); | |
46 } | |
47 | 45 |
48 size_t GetPeakWorkingSetSize() { | 46 size_t GetPeakWorkingSetSize(); |
49 return process_metrics_->GetPeakWorkingSetSize(); | |
50 } | |
51 | 47 |
52 bool GetIOCounters(base::IoCounters* io_counters) { | 48 bool GetIOCounters(base::IoCounters* io_counters); |
53 return process_metrics_->GetIOCounters(io_counters); | |
54 } | |
55 | 49 |
56 base::ProcessHandle process_handle_; | 50 base::ProcessHandle process_handle_; |
57 | 51 |
58 ~ChromeTestProcessMetrics(); | 52 ~ChromeTestProcessMetrics(); |
59 | 53 |
60 private: | 54 private: |
61 explicit ChromeTestProcessMetrics(base::ProcessHandle process); | 55 explicit ChromeTestProcessMetrics(base::ProcessHandle process); |
62 | 56 |
63 std::unique_ptr<base::ProcessMetrics> process_metrics_; | 57 std::unique_ptr<base::ProcessMetrics> process_metrics_; |
64 | 58 |
(...skipping 10 matching lines...) Expand all Loading... |
75 // here because we don't want code spawning processes like this in base, where | 69 // here because we don't want code spawning processes like this in base, where |
76 // someone writing cross platform code might use it without realizing that it's | 70 // someone writing cross platform code might use it without realizing that it's |
77 // a heavyweight call on the Mac. | 71 // a heavyweight call on the Mac. |
78 | 72 |
79 struct MacChromeProcessInfo { | 73 struct MacChromeProcessInfo { |
80 base::ProcessId pid; | 74 base::ProcessId pid; |
81 int rsz_in_kb; | 75 int rsz_in_kb; |
82 int vsz_in_kb; | 76 int vsz_in_kb; |
83 }; | 77 }; |
84 | 78 |
85 typedef std::vector<MacChromeProcessInfo> MacChromeProcessInfoList; | 79 using MacChromeProcessInfoList = std::vector<MacChromeProcessInfo>; |
86 | 80 |
87 // Any ProcessId that info can't be found for will be left out. | 81 // Any ProcessId that info can't be found for will be left out. |
88 MacChromeProcessInfoList GetRunningMacProcessInfo( | 82 MacChromeProcessInfoList GetRunningMacProcessInfo( |
89 const ChromeProcessList& process_list); | 83 const ChromeProcessList& process_list); |
90 | 84 |
91 #endif // defined(OS_MACOSX) | 85 #endif // defined(OS_MACOSX) |
92 | 86 |
93 #endif // CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ | 87 #endif // CHROME_TEST_BASE_CHROME_PROCESS_UTIL_H_ |
OLD | NEW |