| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Returns the peak working set size, in bytes. | 74 // Returns the peak working set size, in bytes. |
| 75 size_t ProcessMetrics::GetPeakWorkingSetSize() const { | 75 size_t ProcessMetrics::GetPeakWorkingSetSize() const { |
| 76 PROCESS_MEMORY_COUNTERS pmc; | 76 PROCESS_MEMORY_COUNTERS pmc; |
| 77 if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) { | 77 if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) { |
| 78 return pmc.PeakWorkingSetSize; | 78 return pmc.PeakWorkingSetSize; |
| 79 } | 79 } |
| 80 return 0; | 80 return 0; |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, | 83 bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, |
| 84 size_t* shared_bytes) { | 84 size_t* shared_bytes) const { |
| 85 // PROCESS_MEMORY_COUNTERS_EX is not supported until XP SP2. | 85 // PROCESS_MEMORY_COUNTERS_EX is not supported until XP SP2. |
| 86 // GetProcessMemoryInfo() will simply fail on prior OS. So the requested | 86 // GetProcessMemoryInfo() will simply fail on prior OS. So the requested |
| 87 // information is simply not available. Hence, we will return 0 on unsupported | 87 // information is simply not available. Hence, we will return 0 on unsupported |
| 88 // OSes. Unlike most Win32 API, we don't need to initialize the "cb" member. | 88 // OSes. Unlike most Win32 API, we don't need to initialize the "cb" member. |
| 89 PROCESS_MEMORY_COUNTERS_EX pmcx; | 89 PROCESS_MEMORY_COUNTERS_EX pmcx; |
| 90 if (private_bytes && | 90 if (private_bytes && |
| 91 GetProcessMemoryInfo(process_, | 91 GetProcessMemoryInfo(process_, |
| 92 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), | 92 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), |
| 93 sizeof(pmcx))) { | 93 sizeof(pmcx))) { |
| 94 *private_bytes = pmcx.PrivateUsage; | 94 *private_bytes = pmcx.PrivateUsage; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 meminfo->total = mem_status.ullTotalPhys / 1024; | 361 meminfo->total = mem_status.ullTotalPhys / 1024; |
| 362 meminfo->free = mem_status.ullAvailPhys / 1024; | 362 meminfo->free = mem_status.ullAvailPhys / 1024; |
| 363 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; | 363 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; |
| 364 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; | 364 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; |
| 365 | 365 |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace base | 369 } // namespace base |
| OLD | NEW |