| 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> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const int PAGESIZE_KB = 4; | 24 const int PAGESIZE_KB = 4; |
| 25 | 25 |
| 26 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)( | 26 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)( |
| 27 SYSTEM_INFORMATION_CLASS SystemInformationClass, | 27 SYSTEM_INFORMATION_CLASS SystemInformationClass, |
| 28 PVOID SystemInformation, | 28 PVOID SystemInformation, |
| 29 ULONG SystemInformationLength, | 29 ULONG SystemInformationLength, |
| 30 PULONG ReturnLength); | 30 PULONG ReturnLength); |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 SystemMemoryInfoKB::SystemMemoryInfoKB() |
| 35 : total(0), free(0), swap_total(0), swap_free(0) {} |
| 36 |
| 37 SystemMemoryInfoKB::SystemMemoryInfoKB(const SystemMemoryInfoKB& other) = |
| 38 default; |
| 39 |
| 34 ProcessMetrics::~ProcessMetrics() { } | 40 ProcessMetrics::~ProcessMetrics() { } |
| 35 | 41 |
| 36 // static | 42 // static |
| 37 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( | 43 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( |
| 38 ProcessHandle process) { | 44 ProcessHandle process) { |
| 39 return WrapUnique(new ProcessMetrics(process)); | 45 return WrapUnique(new ProcessMetrics(process)); |
| 40 } | 46 } |
| 41 | 47 |
| 42 size_t ProcessMetrics::GetPagefileUsage() const { | 48 size_t ProcessMetrics::GetPagefileUsage() const { |
| 43 PROCESS_MEMORY_COUNTERS pmc; | 49 PROCESS_MEMORY_COUNTERS pmc; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 342 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
| 337 } | 343 } |
| 338 | 344 |
| 339 size_t GetPageSize() { | 345 size_t GetPageSize() { |
| 340 return PAGESIZE_KB * 1024; | 346 return PAGESIZE_KB * 1024; |
| 341 } | 347 } |
| 342 | 348 |
| 343 // This function uses the following mapping between MEMORYSTATUSEX and | 349 // This function uses the following mapping between MEMORYSTATUSEX and |
| 344 // SystemMemoryInfoKB: | 350 // SystemMemoryInfoKB: |
| 345 // ullTotalPhys ==> total | 351 // ullTotalPhys ==> total |
| 346 // ullAvailPhys ==> avail_phys | 352 // ullAvailPhys ==> free |
| 347 // ullTotalPageFile ==> swap_total | 353 // ullTotalPageFile ==> swap_total |
| 348 // ullAvailPageFile ==> swap_free | 354 // ullAvailPageFile ==> swap_free |
| 349 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { | 355 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { |
| 350 MEMORYSTATUSEX mem_status; | 356 MEMORYSTATUSEX mem_status; |
| 351 mem_status.dwLength = sizeof(mem_status); | 357 mem_status.dwLength = sizeof(mem_status); |
| 352 if (!::GlobalMemoryStatusEx(&mem_status)) | 358 if (!::GlobalMemoryStatusEx(&mem_status)) |
| 353 return false; | 359 return false; |
| 354 | 360 |
| 355 meminfo->total = mem_status.ullTotalPhys / 1024; | 361 meminfo->total = mem_status.ullTotalPhys / 1024; |
| 356 meminfo->avail_phys = mem_status.ullAvailPhys / 1024; | 362 meminfo->free = mem_status.ullAvailPhys / 1024; |
| 357 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; | 363 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; |
| 358 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; | 364 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; |
| 359 | 365 |
| 360 return true; | 366 return true; |
| 361 } | 367 } |
| 362 | 368 |
| 363 } // namespace base | 369 } // namespace base |
| OLD | NEW |