Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/sysctl.h> | 8 #include <sys/sysctl.h> |
| 9 #include <sys/user.h> | 9 #include <sys/user.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | |
| 13 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 | 17 |
| 17 ProcessMetrics::ProcessMetrics(ProcessHandle process) | 18 ProcessMetrics::ProcessMetrics(ProcessHandle process) |
| 18 : process_(process), | 19 : process_(process), |
| 20 processor_count_(SysInfo::NumberOfProcessors()), | |
| 19 last_system_time_(0), | 21 last_system_time_(0), |
| 20 last_cpu_(0) { | 22 last_cpu_(0) {} |
| 21 processor_count_ = base::SysInfo::NumberOfProcessors(); | |
| 22 } | |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { | 25 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( |
| 26 return new ProcessMetrics(process); | 26 ProcessHandle process) { |
| 27 return WrapUnique(new ProcessMetrics(process)); | |
|
dcheng
2016/07/26 05:21:38
Nit: base::MakeUnique while you're changing this?
Lei Zhang
2016/07/26 05:53:02
I guess you missed my comment. How do we deal with
| |
| 27 } | 28 } |
| 28 | 29 |
| 29 size_t ProcessMetrics::GetPagefileUsage() const { | 30 size_t ProcessMetrics::GetPagefileUsage() const { |
| 30 struct kinfo_proc info; | 31 struct kinfo_proc info; |
| 31 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ }; | 32 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_ }; |
| 32 size_t length = sizeof(info); | 33 size_t length = sizeof(info); |
| 33 | 34 |
| 34 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) | 35 if (sysctl(mib, arraysize(mib), &info, &length, NULL, 0) < 0) |
| 35 return 0; | 36 return 0; |
| 36 | 37 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 NULL, 0) < 0) { | 116 NULL, 0) < 0) { |
| 116 return 0; | 117 return 0; |
| 117 } | 118 } |
| 118 | 119 |
| 119 pagesize = getpagesize(); | 120 pagesize = getpagesize(); |
| 120 | 121 |
| 121 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); | 122 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); |
| 122 } | 123 } |
| 123 | 124 |
| 124 } // namespace base | 125 } // namespace base |
| OLD | NEW |