OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <winternl.h> | 8 #include <winternl.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 | 10 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 434 } |
435 return 0; | 435 return 0; |
436 } | 436 } |
437 | 437 |
438 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { | 438 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { |
439 MEMORY_BASIC_INFORMATION mbi = {0}; | 439 MEMORY_BASIC_INFORMATION mbi = {0}; |
440 size_t committed_private = 0; | 440 size_t committed_private = 0; |
441 size_t committed_mapped = 0; | 441 size_t committed_mapped = 0; |
442 size_t committed_image = 0; | 442 size_t committed_image = 0; |
443 void* base_address = NULL; | 443 void* base_address = NULL; |
444 while (VirtualQueryEx(process_, base_address, &mbi, | 444 while (VirtualQueryEx(process_, base_address, &mbi, sizeof(mbi)) == |
445 sizeof(MEMORY_BASIC_INFORMATION)) == | 445 sizeof(mbi)) { |
446 sizeof(MEMORY_BASIC_INFORMATION)) { | 446 if (mbi.State == MEM_COMMIT) { |
447 if (mbi.State == MEM_COMMIT) { | 447 if (mbi.Type == MEM_PRIVATE) { |
448 if (mbi.Type == MEM_PRIVATE) { | 448 committed_private += mbi.RegionSize; |
449 committed_private += mbi.RegionSize; | 449 } else if (mbi.Type == MEM_MAPPED) { |
450 } else if (mbi.Type == MEM_MAPPED) { | 450 committed_mapped += mbi.RegionSize; |
451 committed_mapped += mbi.RegionSize; | 451 } else if (mbi.Type == MEM_IMAGE) { |
452 } else if (mbi.Type == MEM_IMAGE) { | 452 committed_image += mbi.RegionSize; |
453 committed_image += mbi.RegionSize; | 453 } else { |
454 } else { | 454 NOTREACHED(); |
455 NOTREACHED(); | |
456 } | |
457 } | 455 } |
458 base_address = (static_cast<BYTE*>(mbi.BaseAddress)) + mbi.RegionSize; | 456 } |
| 457 void* new_base = (static_cast<BYTE*>(mbi.BaseAddress)) + mbi.RegionSize; |
| 458 // Avoid infinite loop by weird MEMORY_BASIC_INFORMATION. |
| 459 // If we query 64bit processes in a 32bit process, VirtualQueryEx() |
| 460 // returns such data. |
| 461 if (new_base <= base_address) { |
| 462 usage->image = 0; |
| 463 usage->mapped = 0; |
| 464 usage->priv = 0; |
| 465 return; |
| 466 } |
| 467 base_address = new_base; |
459 } | 468 } |
460 usage->image = committed_image / 1024; | 469 usage->image = committed_image / 1024; |
461 usage->mapped = committed_mapped / 1024; | 470 usage->mapped = committed_mapped / 1024; |
462 usage->priv = committed_private / 1024; | 471 usage->priv = committed_private / 1024; |
463 } | 472 } |
464 | 473 |
465 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { | 474 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { |
466 size_t ws_private = 0; | 475 size_t ws_private = 0; |
467 size_t ws_shareable = 0; | 476 size_t ws_shareable = 0; |
468 size_t ws_shared = 0; | 477 size_t ws_shared = 0; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 void EnableTerminationOnHeapCorruption() { | 658 void EnableTerminationOnHeapCorruption() { |
650 // Ignore the result code. Supported on XP SP3 and Vista. | 659 // Ignore the result code. Supported on XP SP3 and Vista. |
651 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 660 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
652 } | 661 } |
653 | 662 |
654 void RaiseProcessToHighPriority() { | 663 void RaiseProcessToHighPriority() { |
655 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 664 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
656 } | 665 } |
657 | 666 |
658 } // namespace base | 667 } // namespace base |
OLD | NEW |