| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <psapi.h> | 8 #include <psapi.h> |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 9 #include <winternl.h> | 11 #include <winternl.h> |
| 10 | 12 |
| 11 #include <algorithm> | 13 #include <algorithm> |
| 12 | 14 |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 201 } |
| 200 } | 202 } |
| 201 | 203 |
| 202 ws_usage->priv = ws_private * PAGESIZE_KB; | 204 ws_usage->priv = ws_private * PAGESIZE_KB; |
| 203 ws_usage->shareable = ws_shareable * PAGESIZE_KB; | 205 ws_usage->shareable = ws_shareable * PAGESIZE_KB; |
| 204 ws_usage->shared = ws_shared * PAGESIZE_KB; | 206 ws_usage->shared = ws_shared * PAGESIZE_KB; |
| 205 free(buffer); | 207 free(buffer); |
| 206 return true; | 208 return true; |
| 207 } | 209 } |
| 208 | 210 |
| 209 static uint64 FileTimeToUTC(const FILETIME& ftime) { | 211 static uint64_t FileTimeToUTC(const FILETIME& ftime) { |
| 210 LARGE_INTEGER li; | 212 LARGE_INTEGER li; |
| 211 li.LowPart = ftime.dwLowDateTime; | 213 li.LowPart = ftime.dwLowDateTime; |
| 212 li.HighPart = ftime.dwHighDateTime; | 214 li.HighPart = ftime.dwHighDateTime; |
| 213 return li.QuadPart; | 215 return li.QuadPart; |
| 214 } | 216 } |
| 215 | 217 |
| 216 double ProcessMetrics::GetCPUUsage() { | 218 double ProcessMetrics::GetCPUUsage() { |
| 217 FILETIME creation_time; | 219 FILETIME creation_time; |
| 218 FILETIME exit_time; | 220 FILETIME exit_time; |
| 219 FILETIME kernel_time; | 221 FILETIME kernel_time; |
| 220 FILETIME user_time; | 222 FILETIME user_time; |
| 221 | 223 |
| 222 if (!GetProcessTimes(process_, &creation_time, &exit_time, | 224 if (!GetProcessTimes(process_, &creation_time, &exit_time, |
| 223 &kernel_time, &user_time)) { | 225 &kernel_time, &user_time)) { |
| 224 // We don't assert here because in some cases (such as in the Task Manager) | 226 // We don't assert here because in some cases (such as in the Task Manager) |
| 225 // we may call this function on a process that has just exited but we have | 227 // we may call this function on a process that has just exited but we have |
| 226 // not yet received the notification. | 228 // not yet received the notification. |
| 227 return 0; | 229 return 0; |
| 228 } | 230 } |
| 229 int64 system_time = (FileTimeToUTC(kernel_time) + FileTimeToUTC(user_time)) / | 231 int64_t system_time = |
| 230 processor_count_; | 232 (FileTimeToUTC(kernel_time) + FileTimeToUTC(user_time)) / |
| 233 processor_count_; |
| 231 TimeTicks time = TimeTicks::Now(); | 234 TimeTicks time = TimeTicks::Now(); |
| 232 | 235 |
| 233 if (last_system_time_ == 0) { | 236 if (last_system_time_ == 0) { |
| 234 // First call, just set the last values. | 237 // First call, just set the last values. |
| 235 last_system_time_ = system_time; | 238 last_system_time_ = system_time; |
| 236 last_cpu_time_ = time; | 239 last_cpu_time_ = time; |
| 237 return 0; | 240 return 0; |
| 238 } | 241 } |
| 239 | 242 |
| 240 int64 system_time_delta = system_time - last_system_time_; | 243 int64_t system_time_delta = system_time - last_system_time_; |
| 241 // FILETIME is in 100-nanosecond units, so this needs microseconds times 10. | 244 // FILETIME is in 100-nanosecond units, so this needs microseconds times 10. |
| 242 int64 time_delta = (time - last_cpu_time_).InMicroseconds() * 10; | 245 int64_t time_delta = (time - last_cpu_time_).InMicroseconds() * 10; |
| 243 DCHECK_NE(0U, time_delta); | 246 DCHECK_NE(0U, time_delta); |
| 244 if (time_delta == 0) | 247 if (time_delta == 0) |
| 245 return 0; | 248 return 0; |
| 246 | 249 |
| 247 | 250 |
| 248 last_system_time_ = system_time; | 251 last_system_time_ = system_time; |
| 249 last_cpu_time_ = time; | 252 last_cpu_time_ = time; |
| 250 | 253 |
| 251 return static_cast<double>(system_time_delta * 100.0) / time_delta; | 254 return static_cast<double>(system_time_delta * 100.0) / time_delta; |
| 252 } | 255 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 321 |
| 319 meminfo->total = mem_status.ullTotalPhys / 1024; | 322 meminfo->total = mem_status.ullTotalPhys / 1024; |
| 320 meminfo->free = mem_status.ullAvailPhys / 1024; | 323 meminfo->free = mem_status.ullAvailPhys / 1024; |
| 321 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; | 324 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; |
| 322 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; | 325 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; |
| 323 | 326 |
| 324 return true; | 327 return true; |
| 325 } | 328 } |
| 326 | 329 |
| 327 } // namespace base | 330 } // namespace base |
| OLD | NEW |