Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: base/process/process_metrics_win.cc

Issue 2558043007: Fix free memory calculation. (Closed)
Patch Set: Fix integer overflow in unittest. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_metrics_unittest.cc ('k') | base/sys_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
40 ProcessMetrics::~ProcessMetrics() { } 34 ProcessMetrics::~ProcessMetrics() { }
41 35
42 // static 36 // static
43 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( 37 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
44 ProcessHandle process) { 38 ProcessHandle process) {
45 return WrapUnique(new ProcessMetrics(process)); 39 return WrapUnique(new ProcessMetrics(process));
46 } 40 }
47 41
48 size_t ProcessMetrics::GetPagefileUsage() const { 42 size_t ProcessMetrics::GetPagefileUsage() const {
49 PROCESS_MEMORY_COUNTERS pmc; 43 PROCESS_MEMORY_COUNTERS pmc;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 return (info.CommitTotal * system_info.dwPageSize) / 1024; 336 return (info.CommitTotal * system_info.dwPageSize) / 1024;
343 } 337 }
344 338
345 size_t GetPageSize() { 339 size_t GetPageSize() {
346 return PAGESIZE_KB * 1024; 340 return PAGESIZE_KB * 1024;
347 } 341 }
348 342
349 // This function uses the following mapping between MEMORYSTATUSEX and 343 // This function uses the following mapping between MEMORYSTATUSEX and
350 // SystemMemoryInfoKB: 344 // SystemMemoryInfoKB:
351 // ullTotalPhys ==> total 345 // ullTotalPhys ==> total
352 // ullAvailPhys ==> free 346 // ullAvailPhys ==> avail_phys
353 // ullTotalPageFile ==> swap_total 347 // ullTotalPageFile ==> swap_total
354 // ullAvailPageFile ==> swap_free 348 // ullAvailPageFile ==> swap_free
355 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 349 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
356 MEMORYSTATUSEX mem_status; 350 MEMORYSTATUSEX mem_status;
357 mem_status.dwLength = sizeof(mem_status); 351 mem_status.dwLength = sizeof(mem_status);
358 if (!::GlobalMemoryStatusEx(&mem_status)) 352 if (!::GlobalMemoryStatusEx(&mem_status))
359 return false; 353 return false;
360 354
361 meminfo->total = mem_status.ullTotalPhys / 1024; 355 meminfo->total = mem_status.ullTotalPhys / 1024;
362 meminfo->free = mem_status.ullAvailPhys / 1024; 356 meminfo->avail_phys = mem_status.ullAvailPhys / 1024;
363 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; 357 meminfo->swap_total = mem_status.ullTotalPageFile / 1024;
364 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; 358 meminfo->swap_free = mem_status.ullAvailPageFile / 1024;
365 359
366 return true; 360 return true;
367 } 361 }
368 362
369 } // namespace base 363 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_metrics_unittest.cc ('k') | base/sys_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698