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 "chrome/browser/task_manager.h" | 5 #include "chrome/browser/task_manager.h" |
6 | 6 |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "base/stats_table.h" | 8 #include "base/stats_table.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/app/theme/theme_resources.h" | 10 #include "chrome/app/theme/theme_resources.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 int TaskManagerTableModel::RowCount() { | 89 int TaskManagerTableModel::RowCount() { |
90 return static_cast<int>(resources_.size()); | 90 return static_cast<int>(resources_.size()); |
91 } | 91 } |
92 | 92 |
93 std::wstring TaskManagerTableModel::GetText(int row, int col_id) { | 93 std::wstring TaskManagerTableModel::GetText(int row, int col_id) { |
94 // Let's find out if we are the first item in our group. | 94 // Let's find out if we are the first item in our group. |
95 TaskManager::Resource* resource = resources_[row]; | 95 TaskManager::Resource* resource = resources_[row]; |
96 ResourceList* group = group_map_[resource->GetProcess()]; | 96 ResourceList* group = group_map_[resource->GetProcess()]; |
97 DCHECK(group && !group->empty()); | 97 DCHECK(group && !group->empty()); |
98 bool first_in_group = ((*group)[0] == resource); | 98 bool first_in_group = ((*group)[0] == resource); |
99 process_util::ProcessMetrics* process_metrics = NULL; | 99 base::ProcessMetrics* process_metrics = NULL; |
100 if (first_in_group) { | 100 if (first_in_group) { |
101 MetricsMap::iterator iter = metrics_map_.find(resource->GetProcess()); | 101 MetricsMap::iterator iter = metrics_map_.find(resource->GetProcess()); |
102 DCHECK(iter != metrics_map_.end()); | 102 DCHECK(iter != metrics_map_.end()); |
103 process_metrics = iter->second; | 103 process_metrics = iter->second; |
104 } | 104 } |
105 | 105 |
106 switch (col_id) { | 106 switch (col_id) { |
107 case IDS_TASK_MANAGER_PAGE_COLUMN: // Process | 107 case IDS_TASK_MANAGER_PAGE_COLUMN: // Process |
108 return resource->GetTitle(); | 108 return resource->GetTitle(); |
109 | 109 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: // Memory | 141 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: // Memory |
142 if (!first_in_group) | 142 if (!first_in_group) |
143 return std::wstring(); | 143 return std::wstring(); |
144 return l10n_util::GetStringF( | 144 return l10n_util::GetStringF( |
145 IDS_TASK_MANAGER_MEM_CELL_TEXT, | 145 IDS_TASK_MANAGER_MEM_CELL_TEXT, |
146 FormatNumber(GetPhysicalMemory(process_metrics))); | 146 FormatNumber(GetPhysicalMemory(process_metrics))); |
147 | 147 |
148 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: | 148 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: |
149 if (!first_in_group) | 149 if (!first_in_group) |
150 return std::wstring(); | 150 return std::wstring(); |
151 return IntToWString(process_util::GetProcId(resource->GetProcess())); | 151 return IntToWString(base::GetProcId(resource->GetProcess())); |
152 | 152 |
153 case kGoatsTeleportedColumn: // Goats Teleported. | 153 case kGoatsTeleportedColumn: // Goats Teleported. |
154 goats_teleported_ += rand(); | 154 goats_teleported_ += rand(); |
155 return FormatNumber(goats_teleported_); | 155 return FormatNumber(goats_teleported_); |
156 | 156 |
157 default: | 157 default: |
158 return IntToWString(GetStatsValue(resource, col_id)); | 158 return IntToWString(GetStatsValue(resource, col_id)); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 int64 TaskManagerTableModel::GetNetworkUsage(TaskManager::Resource* resource) { | 162 int64 TaskManagerTableModel::GetNetworkUsage(TaskManager::Resource* resource) { |
163 int64 net_usage = GetNetworkUsageForResource(resource); | 163 int64 net_usage = GetNetworkUsageForResource(resource); |
164 if (net_usage == 0 && !resource->SupportNetworkUsage()) | 164 if (net_usage == 0 && !resource->SupportNetworkUsage()) |
165 return -1; | 165 return -1; |
166 return net_usage; | 166 return net_usage; |
167 } | 167 } |
168 | 168 |
169 int TaskManagerTableModel::GetCPUUsage(TaskManager::Resource* resource) { | 169 int TaskManagerTableModel::GetCPUUsage(TaskManager::Resource* resource) { |
170 CPUUsageMap::const_iterator iter = | 170 CPUUsageMap::const_iterator iter = |
171 cpu_usage_map_.find(resource->GetProcess()); | 171 cpu_usage_map_.find(resource->GetProcess()); |
172 if (iter == cpu_usage_map_.end()) | 172 if (iter == cpu_usage_map_.end()) |
173 return 0; | 173 return 0; |
174 return iter->second; | 174 return iter->second; |
175 } | 175 } |
176 | 176 |
177 size_t TaskManagerTableModel::GetPrivateMemory( | 177 size_t TaskManagerTableModel::GetPrivateMemory( |
178 process_util::ProcessMetrics* process_metrics) { | 178 base::ProcessMetrics* process_metrics) { |
179 return process_metrics->GetPrivateBytes() / 1024; | 179 return process_metrics->GetPrivateBytes() / 1024; |
180 } | 180 } |
181 | 181 |
182 size_t TaskManagerTableModel::GetSharedMemory( | 182 size_t TaskManagerTableModel::GetSharedMemory( |
183 process_util::ProcessMetrics* process_metrics) { | 183 base::ProcessMetrics* process_metrics) { |
184 process_util::WorkingSetKBytes ws_usage; | 184 base::WorkingSetKBytes ws_usage; |
185 process_metrics->GetWorkingSetKBytes(&ws_usage); | 185 process_metrics->GetWorkingSetKBytes(&ws_usage); |
186 return ws_usage.shared; | 186 return ws_usage.shared; |
187 } | 187 } |
188 | 188 |
189 size_t TaskManagerTableModel::GetPhysicalMemory( | 189 size_t TaskManagerTableModel::GetPhysicalMemory( |
190 process_util::ProcessMetrics* process_metrics) { | 190 base::ProcessMetrics* process_metrics) { |
191 // Memory = working_set.private + working_set.shareable. | 191 // Memory = working_set.private + working_set.shareable. |
192 // We exclude the shared memory. | 192 // We exclude the shared memory. |
193 size_t total_kbytes = process_metrics->GetWorkingSetSize() / 1024; | 193 size_t total_kbytes = process_metrics->GetWorkingSetSize() / 1024; |
194 process_util::WorkingSetKBytes ws_usage; | 194 base::WorkingSetKBytes ws_usage; |
195 process_metrics->GetWorkingSetKBytes(&ws_usage); | 195 process_metrics->GetWorkingSetKBytes(&ws_usage); |
196 total_kbytes -= ws_usage.shared; | 196 total_kbytes -= ws_usage.shared; |
197 return total_kbytes; | 197 return total_kbytes; |
198 } | 198 } |
199 | 199 |
200 int TaskManagerTableModel::GetStatsValue(TaskManager::Resource* resource, | 200 int TaskManagerTableModel::GetStatsValue(TaskManager::Resource* resource, |
201 int col_id) { | 201 int col_id) { |
202 StatsTable* table = StatsTable::current(); | 202 StatsTable* table = StatsTable::current(); |
203 if (table != NULL) { | 203 if (table != NULL) { |
204 const wchar_t* counter = table->GetRowName(col_id); | 204 const wchar_t* counter = table->GetRowName(col_id); |
205 if (counter != NULL && counter[0] != '\0') { | 205 if (counter != NULL && counter[0] != '\0') { |
206 return table->GetCounterValue(counter, | 206 return table->GetCounterValue(counter, |
207 process_util::GetProcId(resource->GetProcess())); | 207 base::GetProcId(resource->GetProcess())); |
208 } else { | 208 } else { |
209 NOTREACHED() << "Invalid column."; | 209 NOTREACHED() << "Invalid column."; |
210 } | 210 } |
211 } | 211 } |
212 return 0; | 212 return 0; |
213 } | 213 } |
214 | 214 |
215 SkBitmap TaskManagerTableModel::GetIcon(int row) { | 215 SkBitmap TaskManagerTableModel::GetIcon(int row) { |
216 DCHECK(row < RowCount()); | 216 DCHECK(row < RowCount()); |
217 SkBitmap icon = resources_[row]->GetIcon(); | 217 SkBitmap icon = resources_[row]->GetIcon(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 // Insert the new entry right after the last entry of its group. | 338 // Insert the new entry right after the last entry of its group. |
339 ResourceList::iterator iter = | 339 ResourceList::iterator iter = |
340 std::find(resources_.begin(), | 340 std::find(resources_.begin(), |
341 resources_.end(), | 341 resources_.end(), |
342 (*group_entries)[group_entries->size() - 2]); | 342 (*group_entries)[group_entries->size() - 2]); |
343 DCHECK(iter != resources_.end()); | 343 DCHECK(iter != resources_.end()); |
344 new_entry_index = static_cast<int>(iter - resources_.begin()); | 344 new_entry_index = static_cast<int>(iter - resources_.begin()); |
345 resources_.insert(++iter, resource); | 345 resources_.insert(++iter, resource); |
346 } | 346 } |
347 process_util::ProcessMetrics* pm = | 347 base::ProcessMetrics* pm = |
348 process_util::ProcessMetrics::CreateProcessMetrics(process); | 348 base::ProcessMetrics::CreateProcessMetrics(process); |
349 metrics_map_[process] = pm; | 349 metrics_map_[process] = pm; |
350 | 350 |
351 // Notify the table that the contents have changed for it to redraw. | 351 // Notify the table that the contents have changed for it to redraw. |
352 DCHECK(observer_); | 352 DCHECK(observer_); |
353 observer_->OnItemsAdded(new_entry_index, 1); | 353 observer_->OnItemsAdded(new_entry_index, 1); |
354 } | 354 } |
355 | 355 |
356 void TaskManagerTableModel::RemoveResource(TaskManager::Resource* resource) { | 356 void TaskManagerTableModel::RemoveResource(TaskManager::Resource* resource) { |
357 HANDLE process = resource->GetProcess(); | 357 HANDLE process = resource->GetProcess(); |
358 | 358 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 496 |
497 case IDS_TASK_MANAGER_NET_COLUMN: | 497 case IDS_TASK_MANAGER_NET_COLUMN: |
498 return ValueCompare<int64>(GetNetworkUsage(resources_[row1]), | 498 return ValueCompare<int64>(GetNetworkUsage(resources_[row1]), |
499 GetNetworkUsage(resources_[row2])); | 499 GetNetworkUsage(resources_[row2])); |
500 | 500 |
501 case IDS_TASK_MANAGER_CPU_COLUMN: | 501 case IDS_TASK_MANAGER_CPU_COLUMN: |
502 return ValueCompare<int>(GetCPUUsage(resources_[row1]), | 502 return ValueCompare<int>(GetCPUUsage(resources_[row1]), |
503 GetCPUUsage(resources_[row2])); | 503 GetCPUUsage(resources_[row2])); |
504 | 504 |
505 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: { | 505 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: { |
506 process_util::ProcessMetrics* pm1; | 506 base::ProcessMetrics* pm1; |
507 process_util::ProcessMetrics* pm2; | 507 base::ProcessMetrics* pm2; |
508 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) | 508 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) |
509 return 0; | 509 return 0; |
510 return ValueCompare<size_t>(GetPrivateMemory(pm1), | 510 return ValueCompare<size_t>(GetPrivateMemory(pm1), |
511 GetPrivateMemory(pm2)); | 511 GetPrivateMemory(pm2)); |
512 } | 512 } |
513 | 513 |
514 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: { | 514 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: { |
515 process_util::ProcessMetrics* pm1; | 515 base::ProcessMetrics* pm1; |
516 process_util::ProcessMetrics* pm2; | 516 base::ProcessMetrics* pm2; |
517 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) | 517 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) |
518 return 0; | 518 return 0; |
519 return ValueCompare<size_t>(GetSharedMemory(pm1), | 519 return ValueCompare<size_t>(GetSharedMemory(pm1), |
520 GetSharedMemory(pm2)); | 520 GetSharedMemory(pm2)); |
521 } | 521 } |
522 | 522 |
523 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: { | 523 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: { |
524 process_util::ProcessMetrics* pm1; | 524 base::ProcessMetrics* pm1; |
525 process_util::ProcessMetrics* pm2; | 525 base::ProcessMetrics* pm2; |
526 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) | 526 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) |
527 return 0; | 527 return 0; |
528 return ValueCompare<size_t>(GetPhysicalMemory(pm1), | 528 return ValueCompare<size_t>(GetPhysicalMemory(pm1), |
529 GetPhysicalMemory(pm2)); | 529 GetPhysicalMemory(pm2)); |
530 } | 530 } |
531 | 531 |
532 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: { | 532 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: { |
533 int proc1_id = process_util::GetProcId(resources_[row1]->GetProcess()); | 533 int proc1_id = base::GetProcId(resources_[row1]->GetProcess()); |
534 int proc2_id = process_util::GetProcId(resources_[row2]->GetProcess()); | 534 int proc2_id = base::GetProcId(resources_[row2]->GetProcess()); |
535 return ValueCompare<int>(proc1_id, proc2_id); | 535 return ValueCompare<int>(proc1_id, proc2_id); |
536 } | 536 } |
537 | 537 |
538 case kGoatsTeleportedColumn: | 538 case kGoatsTeleportedColumn: |
539 return 0; // Don't bother, numbers are random. | 539 return 0; // Don't bother, numbers are random. |
540 | 540 |
541 default: | 541 default: |
542 return ValueCompare<int>(GetStatsValue(resources_[row1], column_id), | 542 return ValueCompare<int>(GetStatsValue(resources_[row1], column_id), |
543 GetStatsValue(resources_[row2], column_id)); | 543 GetStatsValue(resources_[row2], column_id)); |
544 } | 544 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 NewRunnableMethod( | 625 NewRunnableMethod( |
626 this, | 626 this, |
627 &TaskManagerTableModel::BytesRead, | 627 &TaskManagerTableModel::BytesRead, |
628 BytesReadParam(job->request()->origin_pid(), | 628 BytesReadParam(job->request()->origin_pid(), |
629 render_process_host_id, routing_id, | 629 render_process_host_id, routing_id, |
630 byte_count))); | 630 byte_count))); |
631 } | 631 } |
632 | 632 |
633 bool TaskManagerTableModel::GetProcessMetricsForRows( | 633 bool TaskManagerTableModel::GetProcessMetricsForRows( |
634 int row1, int row2, | 634 int row1, int row2, |
635 process_util::ProcessMetrics** proc_metrics1, | 635 base::ProcessMetrics** proc_metrics1, |
636 process_util::ProcessMetrics** proc_metrics2) { | 636 base::ProcessMetrics** proc_metrics2) { |
637 | 637 |
638 DCHECK(row1 < static_cast<int>(resources_.size()) && | 638 DCHECK(row1 < static_cast<int>(resources_.size()) && |
639 row2 < static_cast<int>(resources_.size())); | 639 row2 < static_cast<int>(resources_.size())); |
640 *proc_metrics1 = NULL; | 640 *proc_metrics1 = NULL; |
641 *proc_metrics2 = NULL; | 641 *proc_metrics2 = NULL; |
642 | 642 |
643 MetricsMap::iterator iter = metrics_map_.find(resources_[row1]->GetProcess()); | 643 MetricsMap::iterator iter = metrics_map_.find(resources_[row1]->GetProcess()); |
644 if (iter == metrics_map_.end()) | 644 if (iter == metrics_map_.end()) |
645 return false; | 645 return false; |
646 *proc_metrics1 = iter->second; | 646 *proc_metrics1 = iter->second; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 | 1095 |
1096 views::View* TaskManager::GetContentsView() { | 1096 views::View* TaskManager::GetContentsView() { |
1097 return contents_.get(); | 1097 return contents_.get(); |
1098 } | 1098 } |
1099 | 1099 |
1100 // static | 1100 // static |
1101 TaskManager* TaskManager::GetInstance() { | 1101 TaskManager* TaskManager::GetInstance() { |
1102 return Singleton<TaskManager>::get(); | 1102 return Singleton<TaskManager>::get(); |
1103 } | 1103 } |
1104 | 1104 |
OLD | NEW |