OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <userenv.h> | 10 #include <userenv.h> |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 PROCESS_MEMORY_COUNTERS_EX pmcx; | 724 PROCESS_MEMORY_COUNTERS_EX pmcx; |
725 if (private_bytes && | 725 if (private_bytes && |
726 GetProcessMemoryInfo(process_, | 726 GetProcessMemoryInfo(process_, |
727 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), | 727 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), |
728 sizeof(pmcx))) { | 728 sizeof(pmcx))) { |
729 *private_bytes = pmcx.PrivateUsage; | 729 *private_bytes = pmcx.PrivateUsage; |
730 } | 730 } |
731 | 731 |
732 if (shared_bytes) { | 732 if (shared_bytes) { |
733 WorkingSetKBytes ws_usage; | 733 WorkingSetKBytes ws_usage; |
734 if (!GetWorkingSetKBytes(&ws_usage)) | 734 if (!GetWorkingSetKBytes(&ws_usage)) { |
735 LOG(ERROR) << "GetMemoryBytes return false"; | |
Devlin
2012/07/24 15:30:48
Debug statements generally don't go in CL's.
mitchellwrosen
2012/07/27 19:24:51
I know. It was an accident =P
| |
735 return false; | 736 return false; |
737 } | |
736 | 738 |
737 *shared_bytes = ws_usage.shared * 1024; | 739 *shared_bytes = ws_usage.shared * 1024; |
738 } | 740 } |
739 | 741 |
740 return true; | 742 return true; |
741 } | 743 } |
742 | 744 |
743 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { | 745 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { |
744 MEMORY_BASIC_INFORMATION mbi = {0}; | 746 MEMORY_BASIC_INFORMATION mbi = {0}; |
745 size_t committed_private = 0; | 747 size_t committed_private = 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 DWORD buffer_size = sizeof(PSAPI_WORKING_SET_INFORMATION) + | 793 DWORD buffer_size = sizeof(PSAPI_WORKING_SET_INFORMATION) + |
792 (number_of_entries * sizeof(PSAPI_WORKING_SET_BLOCK)); | 794 (number_of_entries * sizeof(PSAPI_WORKING_SET_BLOCK)); |
793 | 795 |
794 // if we can't expand the buffer, don't leak the previous | 796 // if we can't expand the buffer, don't leak the previous |
795 // contents or pass a NULL pointer to QueryWorkingSet | 797 // contents or pass a NULL pointer to QueryWorkingSet |
796 PSAPI_WORKING_SET_INFORMATION* new_buffer = | 798 PSAPI_WORKING_SET_INFORMATION* new_buffer = |
797 reinterpret_cast<PSAPI_WORKING_SET_INFORMATION*>( | 799 reinterpret_cast<PSAPI_WORKING_SET_INFORMATION*>( |
798 realloc(buffer, buffer_size)); | 800 realloc(buffer, buffer_size)); |
799 if (!new_buffer) { | 801 if (!new_buffer) { |
800 free(buffer); | 802 free(buffer); |
803 LOG(ERROR) << "GetWorkingSetKBytes returning false 1"; | |
801 return false; | 804 return false; |
802 } | 805 } |
803 buffer = new_buffer; | 806 buffer = new_buffer; |
804 | 807 |
805 // Call the function once to get number of items | 808 // Call the function once to get number of items |
806 if (QueryWorkingSet(process_, buffer, buffer_size)) | 809 if (QueryWorkingSet(process_, buffer, buffer_size)) |
807 break; // Success | 810 break; // Success |
808 | 811 |
809 if (GetLastError() != ERROR_BAD_LENGTH) { | 812 if (GetLastError() != ERROR_BAD_LENGTH) { |
810 free(buffer); | 813 free(buffer); |
814 LOG(ERROR) << "GetWorkingSetKBytes: GetLastError() == " << GetLastError(); | |
815 LOG(ERROR) << "GetWorkingSetKBytes returning false 2"; | |
811 return false; | 816 return false; |
812 } | 817 } |
813 | 818 |
814 number_of_entries = static_cast<DWORD>(buffer->NumberOfEntries); | 819 number_of_entries = static_cast<DWORD>(buffer->NumberOfEntries); |
815 | 820 |
816 // Maybe some entries are being added right now. Increase the buffer to | 821 // Maybe some entries are being added right now. Increase the buffer to |
817 // take that into account. | 822 // take that into account. |
818 number_of_entries = static_cast<DWORD>(number_of_entries * 1.25); | 823 number_of_entries = static_cast<DWORD>(number_of_entries * 1.25); |
819 | 824 |
820 if (--retries == 0) { | 825 if (--retries == 0) { |
821 free(buffer); // If we're looping, eventually fail. | 826 free(buffer); // If we're looping, eventually fail. |
827 LOG(ERROR) << "GetWorkingSetKBytes returning false 3"; | |
822 return false; | 828 return false; |
823 } | 829 } |
824 } | 830 } |
825 | 831 |
826 // On windows 2000 the function returns 1 even when the buffer is too small. | 832 // On windows 2000 the function returns 1 even when the buffer is too small. |
827 // The number of entries that we are going to parse is the minimum between the | 833 // The number of entries that we are going to parse is the minimum between the |
828 // size we allocated and the real number of entries. | 834 // size we allocated and the real number of entries. |
829 number_of_entries = | 835 number_of_entries = |
830 std::min(number_of_entries, static_cast<DWORD>(buffer->NumberOfEntries)); | 836 std::min(number_of_entries, static_cast<DWORD>(buffer->NumberOfEntries)); |
831 for (unsigned int i = 0; i < number_of_entries; i++) { | 837 for (unsigned int i = 0; i < number_of_entries; i++) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 | 1020 |
1015 PERFORMANCE_INFORMATION info; | 1021 PERFORMANCE_INFORMATION info; |
1016 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1022 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
1017 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1023 DLOG(ERROR) << "Failed to fetch internal performance info."; |
1018 return 0; | 1024 return 0; |
1019 } | 1025 } |
1020 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1026 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
1021 } | 1027 } |
1022 | 1028 |
1023 } // namespace base | 1029 } // namespace base |
OLD | NEW |