| 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 "chrome/browser/memory_details.h" | 5 #include "chrome/browser/memory_details.h" |
| 6 | 6 |
| 7 #include <psapi.h> | 7 #include <psapi.h> |
| 8 #include <TlHelp32.h> | 8 #include <TlHelp32.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::win::OSInfo::WindowsArchitecture windows_architecture = | 78 base::win::OSInfo::WindowsArchitecture windows_architecture = |
| 79 base::win::OSInfo::GetInstance()->architecture(); | 79 base::win::OSInfo::GetInstance()->architecture(); |
| 80 | 80 |
| 81 base::win::ScopedHandle snapshot( | 81 base::win::ScopedHandle snapshot( |
| 82 ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); | 82 ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); |
| 83 PROCESSENTRY32 process_entry = {sizeof(PROCESSENTRY32)}; | 83 PROCESSENTRY32 process_entry = {sizeof(PROCESSENTRY32)}; |
| 84 if (!snapshot.Get()) { | 84 if (!snapshot.Get()) { |
| 85 LOG(ERROR) << "CreateToolhelp32Snaphot failed: " << GetLastError(); | 85 LOG(ERROR) << "CreateToolhelp32Snaphot failed: " << GetLastError(); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 if (!::Process32First(snapshot, &process_entry)) { | 88 if (!::Process32First(snapshot.Get(), &process_entry)) { |
| 89 LOG(ERROR) << "Process32First failed: " << GetLastError(); | 89 LOG(ERROR) << "Process32First failed: " << GetLastError(); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 do { | 92 do { |
| 93 base::ProcessId pid = process_entry.th32ProcessID; | 93 base::ProcessId pid = process_entry.th32ProcessID; |
| 94 base::win::ScopedHandle process_handle(::OpenProcess( | 94 base::win::ScopedHandle process_handle(::OpenProcess( |
| 95 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); | 95 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); |
| 96 if (!process_handle.Get()) | 96 if (!process_handle.IsValid()) |
| 97 continue; | 97 continue; |
| 98 bool is_64bit_process = | 98 bool is_64bit_process = |
| 99 ((windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) || | 99 ((windows_architecture == base::win::OSInfo::X64_ARCHITECTURE) || |
| 100 (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE)) && | 100 (windows_architecture == base::win::OSInfo::IA64_ARCHITECTURE)) && |
| 101 (base::win::OSInfo::GetWOW64StatusForProcess(process_handle) == | 101 (base::win::OSInfo::GetWOW64StatusForProcess(process_handle.Get()) == |
| 102 base::win::OSInfo::WOW64_DISABLED); | 102 base::win::OSInfo::WOW64_DISABLED); |
| 103 for (unsigned int index2 = 0; index2 < process_data_.size(); index2++) { | 103 for (unsigned int index2 = 0; index2 < process_data_.size(); index2++) { |
| 104 if (_wcsicmp(process_data_[index2].process_name.c_str(), | 104 if (_wcsicmp(process_data_[index2].process_name.c_str(), |
| 105 process_entry.szExeFile) != 0) | 105 process_entry.szExeFile) != 0) |
| 106 continue; | 106 continue; |
| 107 if (index2 == IE_BROWSER && is_64bit_process) | 107 if (index2 == IE_BROWSER && is_64bit_process) |
| 108 continue; // Should use IE_64BIT_BROWSER | 108 continue; // Should use IE_64BIT_BROWSER |
| 109 // Get Memory Information. | 109 // Get Memory Information. |
| 110 ProcessMemoryInformation info; | 110 ProcessMemoryInformation info; |
| 111 info.pid = pid; | 111 info.pid = pid; |
| 112 if (info.pid == GetCurrentProcessId()) | 112 if (info.pid == GetCurrentProcessId()) |
| 113 info.process_type = content::PROCESS_TYPE_BROWSER; | 113 info.process_type = content::PROCESS_TYPE_BROWSER; |
| 114 else | 114 else |
| 115 info.process_type = content::PROCESS_TYPE_UNKNOWN; | 115 info.process_type = content::PROCESS_TYPE_UNKNOWN; |
| 116 | 116 |
| 117 scoped_ptr<base::ProcessMetrics> metrics; | 117 scoped_ptr<base::ProcessMetrics> metrics; |
| 118 metrics.reset(base::ProcessMetrics::CreateProcessMetrics(process_handle)); | 118 metrics.reset(base::ProcessMetrics::CreateProcessMetrics( |
| 119 process_handle.Get())); |
| 119 metrics->GetCommittedKBytes(&info.committed); | 120 metrics->GetCommittedKBytes(&info.committed); |
| 120 metrics->GetWorkingSetKBytes(&info.working_set); | 121 metrics->GetWorkingSetKBytes(&info.working_set); |
| 121 | 122 |
| 122 // Get Version Information. | 123 // Get Version Information. |
| 123 TCHAR name[MAX_PATH]; | 124 TCHAR name[MAX_PATH]; |
| 124 if (index2 == CHROME_BROWSER || index2 == CHROME_NACL_PROCESS) { | 125 if (index2 == CHROME_BROWSER || index2 == CHROME_NACL_PROCESS) { |
| 125 chrome::VersionInfo version_info; | 126 chrome::VersionInfo version_info; |
| 126 if (version_info.is_valid()) | 127 if (version_info.is_valid()) |
| 127 info.version = base::ASCIIToWide(version_info.Version()); | 128 info.version = base::ASCIIToWide(version_info.Version()); |
| 128 // Check if this is one of the child processes whose data we collected | 129 // Check if this is one of the child processes whose data we collected |
| 129 // on the IO thread, and if so copy over that data. | 130 // on the IO thread, and if so copy over that data. |
| 130 for (size_t child = 0; child < child_info.size(); child++) { | 131 for (size_t child = 0; child < child_info.size(); child++) { |
| 131 if (child_info[child].pid != info.pid) | 132 if (child_info[child].pid != info.pid) |
| 132 continue; | 133 continue; |
| 133 info.titles = child_info[child].titles; | 134 info.titles = child_info[child].titles; |
| 134 info.process_type = child_info[child].process_type; | 135 info.process_type = child_info[child].process_type; |
| 135 break; | 136 break; |
| 136 } | 137 } |
| 137 } else if (GetModuleFileNameEx(process_handle, NULL, name, | 138 } else if (GetModuleFileNameEx(process_handle.Get(), NULL, name, |
| 138 MAX_PATH - 1)) { | 139 MAX_PATH - 1)) { |
| 139 std::wstring str_name(name); | 140 std::wstring str_name(name); |
| 140 scoped_ptr<FileVersionInfo> version_info( | 141 scoped_ptr<FileVersionInfo> version_info( |
| 141 FileVersionInfo::CreateFileVersionInfo(base::FilePath(str_name))); | 142 FileVersionInfo::CreateFileVersionInfo(base::FilePath(str_name))); |
| 142 if (version_info != NULL) { | 143 if (version_info != NULL) { |
| 143 info.version = version_info->product_version(); | 144 info.version = version_info->product_version(); |
| 144 info.product_name = version_info->product_name(); | 145 info.product_name = version_info->product_name(); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 // Add the process info to our list. | 149 // Add the process info to our list. |
| 149 if (index2 == CHROME_NACL_PROCESS) { | 150 if (index2 == CHROME_NACL_PROCESS) { |
| 150 // Add NaCl processes to Chrome's list | 151 // Add NaCl processes to Chrome's list |
| 151 process_data_[CHROME_BROWSER].processes.push_back(info); | 152 process_data_[CHROME_BROWSER].processes.push_back(info); |
| 152 } else { | 153 } else { |
| 153 process_data_[index2].processes.push_back(info); | 154 process_data_[index2].processes.push_back(info); |
| 154 } | 155 } |
| 155 break; | 156 break; |
| 156 } | 157 } |
| 157 } while (::Process32Next(snapshot, &process_entry)); | 158 } while (::Process32Next(snapshot.Get(), &process_entry)); |
| 158 | 159 |
| 159 // Finally return to the browser thread. | 160 // Finally return to the browser thread. |
| 160 BrowserThread::PostTask( | 161 BrowserThread::PostTask( |
| 161 BrowserThread::UI, FROM_HERE, | 162 BrowserThread::UI, FROM_HERE, |
| 162 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); | 163 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); |
| 163 } | 164 } |
| OLD | NEW |