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/browser/process_info_snapshot.h" | 5 #include "chrome/browser/process_info_snapshot.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
7 #include <sys/sysctl.h> | 9 #include <sys/sysctl.h> |
8 | 10 |
9 #include <sstream> | 11 #include <sstream> |
10 | 12 |
11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #include "base/macros.h" |
15 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
16 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
18 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
19 | 22 |
20 // Default constructor. | 23 // Default constructor. |
21 ProcessInfoSnapshot::ProcessInfoSnapshot() { } | 24 ProcessInfoSnapshot::ProcessInfoSnapshot() { } |
22 | 25 |
23 // Destructor: just call |Reset()| to release everything. | 26 // Destructor: just call |Reset()| to release everything. |
24 ProcessInfoSnapshot::~ProcessInfoSnapshot() { | 27 ProcessInfoSnapshot::~ProcessInfoSnapshot() { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 const base::FilePath kProgram("/bin/ps"); | 135 const base::FilePath kProgram("/bin/ps"); |
133 base::CommandLine command_line(kProgram); | 136 base::CommandLine command_line(kProgram); |
134 | 137 |
135 // Get resident set size, virtual memory size. | 138 // Get resident set size, virtual memory size. |
136 command_line.AppendArg("-o"); | 139 command_line.AppendArg("-o"); |
137 command_line.AppendArg("pid=,rss=,vsz="); | 140 command_line.AppendArg("pid=,rss=,vsz="); |
138 // Only display the specified PIDs. | 141 // Only display the specified PIDs. |
139 for (std::vector<base::ProcessId>::const_iterator it = pid_list.begin(); | 142 for (std::vector<base::ProcessId>::const_iterator it = pid_list.begin(); |
140 it != pid_list.end(); ++it) { | 143 it != pid_list.end(); ++it) { |
141 command_line.AppendArg("-p"); | 144 command_line.AppendArg("-p"); |
142 command_line.AppendArg(base::Int64ToString(static_cast<int64>(*it))); | 145 command_line.AppendArg(base::Int64ToString(static_cast<int64_t>(*it))); |
143 } | 146 } |
144 | 147 |
145 std::string output; | 148 std::string output; |
146 // Limit output read to a megabyte for safety. | 149 // Limit output read to a megabyte for safety. |
147 if (!base::GetAppOutputRestricted(command_line, &output, 1024 * 1024)) { | 150 if (!base::GetAppOutputRestricted(command_line, &output, 1024 * 1024)) { |
148 LOG(ERROR) << "Failure running " << kProgram.value() << " to acquire data."; | 151 LOG(ERROR) << "Failure running " << kProgram.value() << " to acquire data."; |
149 return false; | 152 return false; |
150 } | 153 } |
151 | 154 |
152 std::istringstream in(output, std::istringstream::in); | 155 std::istringstream in(output, std::istringstream::in); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 ws_usage->shareable = 0; | 401 ws_usage->shareable = 0; |
399 ws_usage->shared = 0; | 402 ws_usage->shared = 0; |
400 return false; | 403 return false; |
401 } | 404 } |
402 | 405 |
403 ws_usage->priv = proc_info.rprvt / 1024; | 406 ws_usage->priv = proc_info.rprvt / 1024; |
404 ws_usage->shareable = proc_info.rss / 1024; | 407 ws_usage->shareable = proc_info.rss / 1024; |
405 ws_usage->shared = proc_info.rshrd / 1024; | 408 ws_usage->shared = proc_info.rshrd / 1024; |
406 return true; | 409 return true; |
407 } | 410 } |
OLD | NEW |