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 <stddef.h> | 8 #include <stddef.h> |
9 #include <TlHelp32.h> | 9 #include <TlHelp32.h> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 LOG(ERROR) << "Process32First failed: " << GetLastError(); | 64 LOG(ERROR) << "Process32First failed: " << GetLastError(); |
65 return; | 65 return; |
66 } | 66 } |
67 do { | 67 do { |
68 base::ProcessId pid = process_entry.th32ProcessID; | 68 base::ProcessId pid = process_entry.th32ProcessID; |
69 base::win::ScopedHandle process_handle(::OpenProcess( | 69 base::win::ScopedHandle process_handle(::OpenProcess( |
70 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); | 70 PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); |
71 if (!process_handle.IsValid()) | 71 if (!process_handle.IsValid()) |
72 continue; | 72 continue; |
73 if (_wcsicmp(process_data_[0].process_name.c_str(), | 73 if (_wcsicmp(process_data_[0].process_name.c_str(), |
74 process_entry.szExeFile) != 0) | 74 process_entry.szExeFile) != 0) { |
75 continue; | 75 continue; |
| 76 } |
| 77 |
76 // Get Memory Information. | 78 // Get Memory Information. |
77 ProcessMemoryInformation info; | 79 ProcessMemoryInformation info; |
78 info.pid = pid; | 80 info.pid = pid; |
79 if (info.pid == GetCurrentProcessId()) | 81 info.process_type = pid == GetCurrentProcessId() |
80 info.process_type = content::PROCESS_TYPE_BROWSER; | 82 ? content::PROCESS_TYPE_BROWSER |
81 else | 83 : content::PROCESS_TYPE_UNKNOWN; |
82 info.process_type = content::PROCESS_TYPE_UNKNOWN; | |
83 | 84 |
84 std::unique_ptr<base::ProcessMetrics> metrics; | 85 std::unique_ptr<base::ProcessMetrics> metrics = |
85 metrics.reset( | 86 base::ProcessMetrics::CreateProcessMetrics(process_handle.Get()); |
86 base::ProcessMetrics::CreateProcessMetrics(process_handle.Get())); | |
87 metrics->GetCommittedKBytes(&info.committed); | 87 metrics->GetCommittedKBytes(&info.committed); |
88 metrics->GetWorkingSetKBytes(&info.working_set); | 88 metrics->GetWorkingSetKBytes(&info.working_set); |
89 | 89 |
90 // Get Version Information. | 90 // Get Version Information. |
91 info.version = base::ASCIIToUTF16(version_info::GetVersionNumber()); | 91 info.version = base::ASCIIToUTF16(version_info::GetVersionNumber()); |
92 // Check if this is one of the child processes whose data we collected | 92 // Check if this is one of the child processes whose data we collected |
93 // on the IO thread, and if so copy over that data. | 93 // on the IO thread, and if so copy over that data. |
94 for (size_t child = 0; child < child_info.size(); child++) { | 94 for (const ProcessMemoryInformation& child : child_info) { |
95 if (child_info[child].pid != info.pid) | 95 if (child.pid == info.pid) { |
96 continue; | 96 info.titles = child.titles; |
97 info.titles = child_info[child].titles; | 97 info.process_type = child.process_type; |
98 info.process_type = child_info[child].process_type; | 98 break; |
99 break; | 99 } |
100 } | 100 } |
101 | 101 |
102 // Add the process info to our list. | 102 // Add the process info to our list. |
103 process_data_[0].processes.push_back(info); | 103 process_data_[0].processes.push_back(info); |
104 } while (::Process32Next(snapshot.Get(), &process_entry)); | 104 } while (::Process32Next(snapshot.Get(), &process_entry)); |
105 | 105 |
106 // Finally return to the browser thread. | 106 // Finally return to the browser thread. |
107 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
108 BrowserThread::UI, FROM_HERE, | 108 BrowserThread::UI, FROM_HERE, |
109 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); | 109 base::Bind(&MemoryDetails::CollectChildInfoOnUIThread, this)); |
110 } | 110 } |
OLD | NEW |