| 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 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
| 30 #include "chrome/test/base/chrome_process_util.h" | 30 #include "chrome/test/base/chrome_process_util.h" |
| 31 #include "content/public/browser/browser_child_process_host.h" | 31 #include "content/public/browser/browser_child_process_host.h" |
| 32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/load_notification_details.h" |
| 33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 | 37 |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| 38 using extensions::Extension; | 39 using extensions::Extension; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 const uint32 kAccessFlags = base::kProcessAccessDuplicateHandle | | 42 const uint32 kAccessFlags = base::kProcessAccessDuplicateHandle | |
| 42 base::kProcessAccessQueryInformation | | 43 base::kProcessAccessQueryInformation | |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 140 |
| 140 // Crashes | 141 // Crashes |
| 141 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, | 142 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
| 142 content::NotificationService::AllSources()); | 143 content::NotificationService::AllSources()); |
| 143 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 144 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 144 content::NotificationService::AllSources()); | 145 content::NotificationService::AllSources()); |
| 145 | 146 |
| 146 // Profiles (for unclean exit) | 147 // Profiles (for unclean exit) |
| 147 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 148 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 148 content::NotificationService::AllSources()); | 149 content::NotificationService::AllSources()); |
| 150 |
| 151 // Page load times |
| 152 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 153 content::NotificationService::AllSources()); |
| 149 } | 154 } |
| 150 | 155 |
| 151 // We check if profiles exited cleanly initialization time in case they were | 156 // We check if profiles exited cleanly initialization time in case they were |
| 152 // loaded prior to PerformanceMonitor's initialization. Later profiles will be | 157 // loaded prior to PerformanceMonitor's initialization. Later profiles will be |
| 153 // checked through the PROFILE_ADDED notification. | 158 // checked through the PROFILE_ADDED notification. |
| 154 void PerformanceMonitor::CheckForUncleanExits() { | 159 void PerformanceMonitor::CheckForUncleanExits() { |
| 155 std::vector<Profile*> profiles = | 160 std::vector<Profile*> profiles = |
| 156 g_browser_process->profile_manager()->GetLoadedProfiles(); | 161 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 157 | 162 |
| 158 for (std::vector<Profile*>::const_iterator iter = profiles.begin(); | 163 for (std::vector<Profile*>::const_iterator iter = profiles.begin(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 FROM_HERE, | 226 FROM_HERE, |
| 222 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, | 227 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, |
| 223 base::Unretained(this), | 228 base::Unretained(this), |
| 224 base::Passed(event.Pass()))); | 229 base::Passed(event.Pass()))); |
| 225 } | 230 } |
| 226 | 231 |
| 227 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { | 232 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { |
| 228 database_->AddEvent(*event.get()); | 233 database_->AddEvent(*event.get()); |
| 229 } | 234 } |
| 230 | 235 |
| 236 void PerformanceMonitor::AddMetricOnBackgroundThread(MetricType type, |
| 237 const std::string& value) { |
| 238 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 239 database_->AddMetric(type, value); |
| 240 } |
| 241 |
| 231 void PerformanceMonitor::NotifyInitialized() { | 242 void PerformanceMonitor::NotifyInitialized() { |
| 232 content::NotificationService::current()->Notify( | 243 content::NotificationService::current()->Notify( |
| 233 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, | 244 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, |
| 234 content::Source<PerformanceMonitor>(this), | 245 content::Source<PerformanceMonitor>(this), |
| 235 content::NotificationService::NoDetails()); | 246 content::NotificationService::NoDetails()); |
| 236 } | 247 } |
| 237 | 248 |
| 238 void PerformanceMonitor::GatherStatisticsOnBackgroundThread() { | 249 void PerformanceMonitor::GatherStatisticsOnBackgroundThread() { |
| 239 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 240 | 251 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 BrowserThread::PostBlockingPoolSequencedTask( | 423 BrowserThread::PostBlockingPoolSequencedTask( |
| 413 Database::kDatabaseSequenceToken, | 424 Database::kDatabaseSequenceToken, |
| 414 FROM_HERE, | 425 FROM_HERE, |
| 415 base::Bind( | 426 base::Bind( |
| 416 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, | 427 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, |
| 417 base::Unretained(this), | 428 base::Unretained(this), |
| 418 profile->GetDebugName())); | 429 profile->GetDebugName())); |
| 419 } | 430 } |
| 420 break; | 431 break; |
| 421 } | 432 } |
| 433 case content::NOTIFICATION_LOAD_STOP: { |
| 434 const content::LoadNotificationDetails* load_details = |
| 435 content::Details<content::LoadNotificationDetails>(details).ptr(); |
| 436 if (!load_details) |
| 437 break; |
| 438 BrowserThread::PostBlockingPoolSequencedTask( |
| 439 Database::kDatabaseSequenceToken, |
| 440 FROM_HERE, |
| 441 base::Bind( |
| 442 &PerformanceMonitor::AddMetricOnBackgroundThread, |
| 443 base::Unretained(this), |
| 444 METRIC_PAGE_LOAD_TIME, |
| 445 base::Int64ToString(load_details->load_time.ToInternalValue()))); |
| 446 break; |
| 447 } |
| 422 default: { | 448 default: { |
| 423 NOTREACHED(); | 449 NOTREACHED(); |
| 424 break; | 450 break; |
| 425 } | 451 } |
| 426 } | 452 } |
| 427 } | 453 } |
| 428 | 454 |
| 429 void PerformanceMonitor::AddExtensionEvent(EventType type, | 455 void PerformanceMonitor::AddExtensionEvent(EventType type, |
| 430 const Extension* extension) { | 456 const Extension* extension) { |
| 431 DCHECK(type == EVENT_EXTENSION_INSTALL || | 457 DCHECK(type == EVENT_EXTENSION_INSTALL || |
| (...skipping 20 matching lines...) Expand all Loading... |
| 452 | 478 |
| 453 // Determine the type of crash. | 479 // Determine the type of crash. |
| 454 EventType type = | 480 EventType type = |
| 455 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? | 481 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? |
| 456 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; | 482 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; |
| 457 | 483 |
| 458 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); | 484 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); |
| 459 } | 485 } |
| 460 | 486 |
| 461 } // namespace performance_monitor | 487 } // namespace performance_monitor |
| OLD | NEW |