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/performance_monitor/performance_monitor.h" | 5 #include "chrome/browser/performance_monitor/performance_monitor.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 FROM_HERE, | 271 FROM_HERE, |
272 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, | 272 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, |
273 base::Unretained(this), | 273 base::Unretained(this), |
274 base::Passed(event.Pass()))); | 274 base::Passed(event.Pass()))); |
275 } | 275 } |
276 | 276 |
277 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { | 277 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { |
278 database_->AddEvent(*event.get()); | 278 database_->AddEvent(*event.get()); |
279 } | 279 } |
280 | 280 |
281 void PerformanceMonitor::AddMetricOnBackgroundThread(MetricType type, | 281 void PerformanceMonitor::AddMetricOnBackgroundThread(Metric metric) { |
282 const std::string& value) { | |
283 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 282 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
284 database_->AddMetric(type, value); | 283 database_->AddMetric(metric); |
285 } | 284 } |
286 | 285 |
287 void PerformanceMonitor::NotifyInitialized() { | 286 void PerformanceMonitor::NotifyInitialized() { |
288 content::NotificationService::current()->Notify( | 287 content::NotificationService::current()->Notify( |
289 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, | 288 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, |
290 content::Source<PerformanceMonitor>(this), | 289 content::Source<PerformanceMonitor>(this), |
291 content::NotificationService::NoDetails()); | 290 content::NotificationService::NoDetails()); |
292 | 291 |
293 initialized_ = true; | 292 initialized_ = true; |
294 } | 293 } |
(...skipping 10 matching lines...) Expand all Loading... |
305 } | 304 } |
306 | 305 |
307 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() { | 306 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() { |
308 if (metrics_map_->size()) { | 307 if (metrics_map_->size()) { |
309 double cpu_usage = 0; | 308 double cpu_usage = 0; |
310 for (MetricsMap::const_iterator iter = metrics_map_->begin(); | 309 for (MetricsMap::const_iterator iter = metrics_map_->begin(); |
311 iter != metrics_map_->end(); ++iter) { | 310 iter != metrics_map_->end(); ++iter) { |
312 cpu_usage += iter->second->GetCPUUsage(); | 311 cpu_usage += iter->second->GetCPUUsage(); |
313 } | 312 } |
314 | 313 |
315 database_->AddMetric(METRIC_CPU_USAGE, base::DoubleToString(cpu_usage)); | 314 database_->AddMetric(Metric(METRIC_CPU_USAGE, |
| 315 base::Time::Now(), |
| 316 cpu_usage)); |
316 } | 317 } |
317 } | 318 } |
318 | 319 |
319 void PerformanceMonitor::GatherMemoryUsageOnBackgroundThread() { | 320 void PerformanceMonitor::GatherMemoryUsageOnBackgroundThread() { |
320 size_t private_memory_sum = 0; | 321 size_t private_memory_sum = 0; |
321 size_t shared_memory_sum = 0; | 322 size_t shared_memory_sum = 0; |
322 for (MetricsMap::const_iterator iter = metrics_map_->begin(); | 323 for (MetricsMap::const_iterator iter = metrics_map_->begin(); |
323 iter != metrics_map_->end(); ++iter) { | 324 iter != metrics_map_->end(); ++iter) { |
324 size_t private_memory = 0; | 325 size_t private_memory = 0; |
325 size_t shared_memory = 0; | 326 size_t shared_memory = 0; |
326 if (iter->second->GetMemoryBytes(&private_memory, &shared_memory)) { | 327 if (iter->second->GetMemoryBytes(&private_memory, &shared_memory)) { |
327 private_memory_sum += private_memory; | 328 private_memory_sum += private_memory; |
328 shared_memory_sum += shared_memory; | 329 shared_memory_sum += shared_memory; |
329 } else { | 330 } else { |
330 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; | 331 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; |
331 } | 332 } |
332 } | 333 } |
333 | 334 |
334 database_->AddMetric(METRIC_PRIVATE_MEMORY_USAGE, | 335 database_->AddMetric(Metric(METRIC_PRIVATE_MEMORY_USAGE, |
335 base::Uint64ToString(private_memory_sum)); | 336 base::Time::Now(), |
336 database_->AddMetric(METRIC_SHARED_MEMORY_USAGE, | 337 static_cast<double>(private_memory_sum))); |
337 base::Uint64ToString(shared_memory_sum)); | 338 database_->AddMetric(Metric(METRIC_SHARED_MEMORY_USAGE, |
| 339 base::Time::Now(), |
| 340 static_cast<double>(shared_memory_sum))); |
338 } | 341 } |
339 | 342 |
340 void PerformanceMonitor::UpdateMetricsMapOnBackgroundThread() { | 343 void PerformanceMonitor::UpdateMetricsMapOnBackgroundThread() { |
341 MetricsMap* new_map = new MetricsMap; | 344 MetricsMap* new_map = new MetricsMap; |
342 | 345 |
343 base::ProcessId browser_pid = base::GetCurrentProcId(); | 346 base::ProcessId browser_pid = base::GetCurrentProcId(); |
344 ChromeProcessList chrome_processes(GetRunningChromeProcesses(browser_pid)); | 347 ChromeProcessList chrome_processes(GetRunningChromeProcesses(browser_pid)); |
345 for (ChromeProcessList::const_iterator pid_iter = chrome_processes.begin(); | 348 for (ChromeProcessList::const_iterator pid_iter = chrome_processes.begin(); |
346 pid_iter != chrome_processes.end(); ++pid_iter) { | 349 pid_iter != chrome_processes.end(); ++pid_iter) { |
347 base::ProcessHandle handle; | 350 base::ProcessHandle handle; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 FROM_HERE, | 428 FROM_HERE, |
426 base::Bind(&PerformanceMonitor::InsertIOData, | 429 base::Bind(&PerformanceMonitor::InsertIOData, |
427 base::Unretained(this), | 430 base::Unretained(this), |
428 performance_data_for_io_thread_)); | 431 performance_data_for_io_thread_)); |
429 } | 432 } |
430 | 433 |
431 void PerformanceMonitor::InsertIOData( | 434 void PerformanceMonitor::InsertIOData( |
432 PerformanceDataForIOThread performance_data_for_io_thread) { | 435 PerformanceDataForIOThread performance_data_for_io_thread) { |
433 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
434 database_->AddMetric( | 437 database_->AddMetric( |
435 METRIC_NETWORK_BYTES_READ, | 438 Metric(METRIC_NETWORK_BYTES_READ, |
436 base::Uint64ToString(performance_data_for_io_thread.network_bytes_read)); | 439 base::Time::Now(), |
| 440 static_cast<double>( |
| 441 performance_data_for_io_thread.network_bytes_read))); |
437 } | 442 } |
438 | 443 |
439 void PerformanceMonitor::BytesReadOnIOThread(const net::URLRequest& request, | 444 void PerformanceMonitor::BytesReadOnIOThread(const net::URLRequest& request, |
440 const int bytes_read) { | 445 const int bytes_read) { |
441 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 446 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
442 | 447 |
443 if (initialized_ && !request.url().SchemeIsFile()) | 448 if (initialized_ && !request.url().SchemeIsFile()) |
444 performance_data_for_io_thread_.network_bytes_read += bytes_read; | 449 performance_data_for_io_thread_.network_bytes_read += bytes_read; |
445 } | 450 } |
446 | 451 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 const content::LoadNotificationDetails* load_details = | 519 const content::LoadNotificationDetails* load_details = |
515 content::Details<content::LoadNotificationDetails>(details).ptr(); | 520 content::Details<content::LoadNotificationDetails>(details).ptr(); |
516 if (!load_details) | 521 if (!load_details) |
517 break; | 522 break; |
518 BrowserThread::PostBlockingPoolSequencedTask( | 523 BrowserThread::PostBlockingPoolSequencedTask( |
519 Database::kDatabaseSequenceToken, | 524 Database::kDatabaseSequenceToken, |
520 FROM_HERE, | 525 FROM_HERE, |
521 base::Bind( | 526 base::Bind( |
522 &PerformanceMonitor::AddMetricOnBackgroundThread, | 527 &PerformanceMonitor::AddMetricOnBackgroundThread, |
523 base::Unretained(this), | 528 base::Unretained(this), |
524 METRIC_PAGE_LOAD_TIME, | 529 Metric(METRIC_PAGE_LOAD_TIME, |
525 base::Int64ToString(load_details->load_time.ToInternalValue()))); | 530 base::Time::Now(), |
| 531 static_cast<double>( |
| 532 load_details->load_time.ToInternalValue())))); |
526 break; | 533 break; |
527 } | 534 } |
528 default: { | 535 default: { |
529 NOTREACHED(); | 536 NOTREACHED(); |
530 break; | 537 break; |
531 } | 538 } |
532 } | 539 } |
533 } | 540 } |
534 | 541 |
535 void PerformanceMonitor::AddExtensionEvent(EventType type, | 542 void PerformanceMonitor::AddExtensionEvent(EventType type, |
(...skipping 22 matching lines...) Expand all Loading... |
558 | 565 |
559 // Determine the type of crash. | 566 // Determine the type of crash. |
560 EventType type = | 567 EventType type = |
561 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? | 568 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? |
562 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; | 569 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; |
563 | 570 |
564 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); | 571 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); |
565 } | 572 } |
566 | 573 |
567 } // namespace performance_monitor | 574 } // namespace performance_monitor |
OLD | NEW |