OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
9 #include <mach/shared_region.h> | 9 #include <mach/shared_region.h> |
10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 if (private_bytes) | 203 if (private_bytes) |
204 *private_bytes = private_pages_count * PAGE_SIZE; | 204 *private_bytes = private_pages_count * PAGE_SIZE; |
205 if (shared_bytes) | 205 if (shared_bytes) |
206 *shared_bytes = shared_pages_count * PAGE_SIZE; | 206 *shared_bytes = shared_pages_count * PAGE_SIZE; |
207 | 207 |
208 return true; | 208 return true; |
209 } | 209 } |
210 | 210 |
211 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { | 211 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { |
| 212 WorkingSetKBytes unused; |
| 213 if (!GetCommittedAndWorkingSetKBytes(usage, &unused)) { |
| 214 *usage = CommittedKBytes(); |
| 215 } |
212 } | 216 } |
213 | 217 |
214 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { | 218 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { |
215 size_t priv = GetWorkingSetSize(); | 219 CommittedKBytes unused; |
216 if (!priv) | 220 return GetCommittedAndWorkingSetKBytes(&unused, ws_usage); |
| 221 } |
| 222 |
| 223 bool ProcessMetrics::GetCommittedAndWorkingSetKBytes( |
| 224 CommittedKBytes* usage, |
| 225 WorkingSetKBytes* ws_usage) const { |
| 226 task_basic_info_64 task_info_data; |
| 227 if (!GetTaskInfo(TaskForPid(process_), &task_info_data)) |
217 return false; | 228 return false; |
218 ws_usage->priv = priv / 1024; | 229 |
| 230 usage->priv = task_info_data.virtual_size / 1024; |
| 231 usage->mapped = 0; |
| 232 usage->image = 0; |
| 233 |
| 234 ws_usage->priv = task_info_data.resident_size / 1024; |
219 ws_usage->shareable = 0; | 235 ws_usage->shareable = 0; |
220 ws_usage->shared = 0; | 236 ws_usage->shared = 0; |
| 237 |
221 return true; | 238 return true; |
222 } | 239 } |
223 | 240 |
224 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ | 241 #define TIME_VALUE_TO_TIMEVAL(a, r) do { \ |
225 (r)->tv_sec = (a)->seconds; \ | 242 (r)->tv_sec = (a)->seconds; \ |
226 (r)->tv_usec = (a)->microseconds; \ | 243 (r)->tv_usec = (a)->microseconds; \ |
227 } while (0) | 244 } while (0) |
228 | 245 |
229 double ProcessMetrics::GetCPUUsage() { | 246 double ProcessMetrics::GetCPUUsage() { |
230 mach_port_t task = TaskForPid(process_); | 247 mach_port_t task = TaskForPid(process_); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 &count); | 352 &count); |
336 if (kr != KERN_SUCCESS) { | 353 if (kr != KERN_SUCCESS) { |
337 MACH_DLOG(WARNING, kr) << "host_statistics"; | 354 MACH_DLOG(WARNING, kr) << "host_statistics"; |
338 return 0; | 355 return 0; |
339 } | 356 } |
340 | 357 |
341 return (data.active_count * PAGE_SIZE) / 1024; | 358 return (data.active_count * PAGE_SIZE) / 1024; |
342 } | 359 } |
343 | 360 |
344 } // namespace base | 361 } // namespace base |
OLD | NEW |