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/macros.h" |
5 #include "base/process/process_metrics.h" | 6 #include "base/process/process_metrics.h" |
6 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
7 #include <sys/param.h> | 10 #include <sys/param.h> |
8 #include <sys/sysctl.h> | 11 #include <sys/sysctl.h> |
9 | 12 |
10 namespace base { | 13 namespace base { |
11 | 14 |
12 // static | 15 // static |
13 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { | 16 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { |
14 return new ProcessMetrics(process); | 17 return new ProcessMetrics(process); |
15 } | 18 } |
16 | 19 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 double ProcessMetrics::GetCPUUsage() { | 111 double ProcessMetrics::GetCPUUsage() { |
109 TimeTicks time = TimeTicks::Now(); | 112 TimeTicks time = TimeTicks::Now(); |
110 | 113 |
111 if (last_cpu_ == 0) { | 114 if (last_cpu_ == 0) { |
112 // First call, just set the last values. | 115 // First call, just set the last values. |
113 last_cpu_time_ = time; | 116 last_cpu_time_ = time; |
114 last_cpu_ = GetProcessCPU(process_); | 117 last_cpu_ = GetProcessCPU(process_); |
115 return 0; | 118 return 0; |
116 } | 119 } |
117 | 120 |
118 int64 time_delta = (time - last_cpu_time_).InMicroseconds(); | 121 int64_t time_delta = (time - last_cpu_time_).InMicroseconds(); |
119 DCHECK_NE(time_delta, 0); | 122 DCHECK_NE(time_delta, 0); |
120 | 123 |
121 if (time_delta == 0) | 124 if (time_delta == 0) |
122 return 0; | 125 return 0; |
123 | 126 |
124 int cpu = GetProcessCPU(process_); | 127 int cpu = GetProcessCPU(process_); |
125 | 128 |
126 last_cpu_time_ = time; | 129 last_cpu_time_ = time; |
127 last_cpu_ = cpu; | 130 last_cpu_ = cpu; |
128 | 131 |
(...skipping 23 matching lines...) Expand all Loading... |
152 mem_total = vmtotal.t_vm; | 155 mem_total = vmtotal.t_vm; |
153 mem_free = vmtotal.t_free; | 156 mem_free = vmtotal.t_free; |
154 mem_inactive = vmtotal.t_vm - vmtotal.t_avm; | 157 mem_inactive = vmtotal.t_vm - vmtotal.t_avm; |
155 | 158 |
156 pagesize = getpagesize(); | 159 pagesize = getpagesize(); |
157 | 160 |
158 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); | 161 return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize); |
159 } | 162 } |
160 | 163 |
161 } // namespace base | 164 } // namespace base |
OLD | NEW |