Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/browser/task_manager/task_manager.cc

Issue 23523024: Fix and re-enable PrerenderTaskManager test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reorder functions Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/number_formatting.h" 8 #include "base/i18n/number_formatting.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 OnItemsRemoved(0, size)); 1156 OnItemsRemoved(0, size));
1157 } 1157 }
1158 last_unique_id_ = 0; 1158 last_unique_id_ = 0;
1159 } 1159 }
1160 1160
1161 void TaskManagerModel::ModelChanged() { 1161 void TaskManagerModel::ModelChanged() {
1162 // Notify the table that the contents have changed for it to redraw. 1162 // Notify the table that the contents have changed for it to redraw.
1163 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); 1163 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged());
1164 } 1164 }
1165 1165
1166 void TaskManagerModel::Refresh() {
1167 goat_salt_ = base::RandUint64();
1168
1169 per_resource_cache_.clear();
1170 per_process_cache_.clear();
1171
1172 // Compute the CPU usage values.
1173 // Note that we compute the CPU usage for all resources (instead of doing it
1174 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last
1175 // time it was called, and not calling it everytime would skew the value the
1176 // next time it is retrieved (as it would be for more than 1 cycle).
1177 for (ResourceList::iterator iter = resources_.begin();
1178 iter != resources_.end(); ++iter) {
1179 base::ProcessHandle process = (*iter)->GetProcess();
1180 PerProcessValues& values(per_process_cache_[process]);
1181 if (values.is_cpu_usage_valid)
1182 continue;
1183
1184 values.is_cpu_usage_valid = true;
1185 MetricsMap::iterator metrics_iter = metrics_map_.find(process);
1186 DCHECK(metrics_iter != metrics_map_.end());
1187 values.cpu_usage = metrics_iter->second->GetCPUUsage();
1188 }
1189
1190 // Send a request to refresh GPU memory consumption values
1191 RefreshVideoMemoryUsageStats();
1192
1193 // Compute the new network usage values.
1194 base::TimeDelta update_time =
1195 base::TimeDelta::FromMilliseconds(kUpdateTimeMs);
1196 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin();
1197 iter != current_byte_count_map_.end(); ++iter) {
1198 PerResourceValues* values = &(per_resource_cache_[iter->first]);
1199 if (update_time > base::TimeDelta::FromSeconds(1))
1200 values->network_usage = iter->second / update_time.InSeconds();
1201 else
1202 values->network_usage = iter->second * (1 / update_time.InSeconds());
1203
1204 // Then we reset the current byte count.
1205 iter->second = 0;
1206 }
1207
1208 // Let resources update themselves if they need to.
1209 for (ResourceList::iterator iter = resources_.begin();
1210 iter != resources_.end(); ++iter) {
1211 (*iter)->Refresh();
1212 }
1213
1214 if (!resources_.empty()) {
1215 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1216 OnItemsChanged(0, ResourceCount()));
1217 }
1218 }
1219
1166 void TaskManagerModel::NotifyResourceTypeStats( 1220 void TaskManagerModel::NotifyResourceTypeStats(
1167 base::ProcessId renderer_id, 1221 base::ProcessId renderer_id,
1168 const WebKit::WebCache::ResourceTypeStats& stats) { 1222 const WebKit::WebCache::ResourceTypeStats& stats) {
1169 for (ResourceList::iterator it = resources_.begin(); 1223 for (ResourceList::iterator it = resources_.begin();
1170 it != resources_.end(); ++it) { 1224 it != resources_.end(); ++it) {
1171 if (base::GetProcId((*it)->GetProcess()) == renderer_id) { 1225 if (base::GetProcId((*it)->GetProcess()) == renderer_id) {
1172 (*it)->NotifyResourceTypeStats(stats); 1226 (*it)->NotifyResourceTypeStats(stats);
1173 } 1227 }
1174 } 1228 }
1175 } 1229 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1323
1270 Refresh(); 1324 Refresh();
1271 1325
1272 // Schedule the next update. 1326 // Schedule the next update.
1273 base::MessageLoop::current()->PostDelayedTask( 1327 base::MessageLoop::current()->PostDelayedTask(
1274 FROM_HERE, 1328 FROM_HERE,
1275 base::Bind(&TaskManagerModel::RefreshCallback, this), 1329 base::Bind(&TaskManagerModel::RefreshCallback, this),
1276 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); 1330 base::TimeDelta::FromMilliseconds(kUpdateTimeMs));
1277 } 1331 }
1278 1332
1279 void TaskManagerModel::Refresh() {
1280 goat_salt_ = base::RandUint64();
1281
1282 per_resource_cache_.clear();
1283 per_process_cache_.clear();
1284
1285 // Compute the CPU usage values.
1286 // Note that we compute the CPU usage for all resources (instead of doing it
1287 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last
1288 // time it was called, and not calling it everytime would skew the value the
1289 // next time it is retrieved (as it would be for more than 1 cycle).
1290 for (ResourceList::iterator iter = resources_.begin();
1291 iter != resources_.end(); ++iter) {
1292 base::ProcessHandle process = (*iter)->GetProcess();
1293 PerProcessValues& values(per_process_cache_[process]);
1294 if (values.is_cpu_usage_valid)
1295 continue;
1296
1297 values.is_cpu_usage_valid = true;
1298 MetricsMap::iterator metrics_iter = metrics_map_.find(process);
1299 DCHECK(metrics_iter != metrics_map_.end());
1300 values.cpu_usage = metrics_iter->second->GetCPUUsage();
1301 }
1302
1303 // Send a request to refresh GPU memory consumption values
1304 RefreshVideoMemoryUsageStats();
1305
1306 // Compute the new network usage values.
1307 base::TimeDelta update_time =
1308 base::TimeDelta::FromMilliseconds(kUpdateTimeMs);
1309 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin();
1310 iter != current_byte_count_map_.end(); ++iter) {
1311 PerResourceValues* values = &(per_resource_cache_[iter->first]);
1312 if (update_time > base::TimeDelta::FromSeconds(1))
1313 values->network_usage = iter->second / update_time.InSeconds();
1314 else
1315 values->network_usage = iter->second * (1 / update_time.InSeconds());
1316
1317 // Then we reset the current byte count.
1318 iter->second = 0;
1319 }
1320
1321 // Let resources update themselves if they need to.
1322 for (ResourceList::iterator iter = resources_.begin();
1323 iter != resources_.end(); ++iter) {
1324 (*iter)->Refresh();
1325 }
1326
1327 if (!resources_.empty()) {
1328 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1329 OnItemsChanged(0, ResourceCount()));
1330 }
1331 }
1332
1333 void TaskManagerModel::RefreshVideoMemoryUsageStats() { 1333 void TaskManagerModel::RefreshVideoMemoryUsageStats() {
1334 if (pending_video_memory_usage_stats_update_) 1334 if (pending_video_memory_usage_stats_update_)
1335 return; 1335 return;
1336 1336
1337 if (!video_memory_usage_stats_observer_.get()) { 1337 if (!video_memory_usage_stats_observer_.get()) {
1338 video_memory_usage_stats_observer_.reset( 1338 video_memory_usage_stats_observer_.reset(
1339 new TaskManagerModelGpuDataManagerObserver()); 1339 new TaskManagerModelGpuDataManagerObserver());
1340 } 1340 }
1341 pending_video_memory_usage_stats_update_ = true; 1341 pending_video_memory_usage_stats_update_ = true;
1342 content::GpuDataManager::GetInstance()->RequestVideoMemoryUsageStatsUpdate(); 1342 content::GpuDataManager::GetInstance()->RequestVideoMemoryUsageStatsUpdate();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 params.window_action = chrome::NavigateParams::SHOW_WINDOW; 1558 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
1559 chrome::Navigate(&params); 1559 chrome::Navigate(&params);
1560 } 1560 }
1561 1561
1562 TaskManager::TaskManager() 1562 TaskManager::TaskManager()
1563 : model_(new TaskManagerModel(this)) { 1563 : model_(new TaskManagerModel(this)) {
1564 } 1564 }
1565 1565
1566 TaskManager::~TaskManager() { 1566 TaskManager::~TaskManager() {
1567 } 1567 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698