| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/process/process_iterator.h" | 14 #include "base/process/process_iterator.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/browser_shutdown.h" | 20 #include "chrome/browser/browser_shutdown.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/extensions/crx_installer.h" | |
| 23 #include "chrome/browser/performance_monitor/constants.h" | 22 #include "chrome/browser/performance_monitor/constants.h" |
| 24 #include "chrome/browser/performance_monitor/performance_monitor_util.h" | 23 #include "chrome/browser/performance_monitor/performance_monitor_util.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_iterator.h" | 27 #include "chrome/browser/ui/browser_iterator.h" |
| 29 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/chrome_version_info.h" | 29 #include "chrome/common/chrome_version_info.h" |
| 31 #include "chrome/common/extensions/extension_constants.h" | |
| 32 #include "content/public/browser/browser_child_process_host.h" | 30 #include "content/public/browser/browser_child_process_host.h" |
| 33 #include "content/public/browser/browser_child_process_host_iterator.h" | 31 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 34 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/child_process_data.h" | 33 #include "content/public/browser/child_process_data.h" |
| 36 #include "content/public/browser/load_notification_details.h" | 34 #include "content/public/browser/load_notification_details.h" |
| 37 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
| 39 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/render_widget_host.h" | 38 #include "content/public/browser/render_widget_host.h" |
| 41 #include "content/public/browser/render_widget_host_iterator.h" | 39 #include "content/public/browser/render_widget_host_iterator.h" |
| 42 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 43 #include "extensions/common/extension.h" | |
| 44 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
| 45 | 42 |
| 43 #if defined(ENABLE_EXTENSIONS) |
| 44 #include "chrome/browser/extensions/crx_installer.h" |
| 45 #include "chrome/common/extensions/extension_constants.h" |
| 46 #include "extensions/common/extension.h" |
| 47 #endif |
| 48 |
| 46 using content::BrowserThread; | 49 using content::BrowserThread; |
| 50 |
| 51 #if defined(ENABLE_EXTENSIONS) |
| 47 using extensions::Extension; | 52 using extensions::Extension; |
| 48 using extensions::UnloadedExtensionInfo; | 53 using extensions::UnloadedExtensionInfo; |
| 54 #endif |
| 49 | 55 |
| 50 namespace performance_monitor { | 56 namespace performance_monitor { |
| 51 | 57 |
| 52 namespace { | 58 namespace { |
| 53 | 59 |
| 54 #if !defined(OS_ANDROID) | 60 #if !defined(OS_ANDROID) |
| 55 std::string TimeToString(base::Time time) { | 61 std::string TimeToString(base::Time time) { |
| 56 int64 time_int64 = time.ToInternalValue(); | 62 int64 time_int64 = time.ToInternalValue(); |
| 57 return base::Int64ToString(time_int64); | 63 return base::Int64ToString(time_int64); |
| 58 } | 64 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 BrowserThread::IO, | 399 BrowserThread::IO, |
| 394 FROM_HERE, | 400 FROM_HERE, |
| 395 base::Bind(&PerformanceMonitor::GatherMetricsMapOnIOThread, | 401 base::Bind(&PerformanceMonitor::GatherMetricsMapOnIOThread, |
| 396 base::Unretained(this), | 402 base::Unretained(this), |
| 397 current_update_sequence)); | 403 current_update_sequence)); |
| 398 } | 404 } |
| 399 | 405 |
| 400 void PerformanceMonitor::MarkProcessAsAlive(const base::ProcessHandle& handle, | 406 void PerformanceMonitor::MarkProcessAsAlive(const base::ProcessHandle& handle, |
| 401 int process_type, | 407 int process_type, |
| 402 int current_update_sequence) { | 408 int current_update_sequence) { |
| 403 | |
| 404 if (handle == 0) { | 409 if (handle == 0) { |
| 405 // Process may not be valid yet. | 410 // Process may not be valid yet. |
| 406 return; | 411 return; |
| 407 } | 412 } |
| 408 | 413 |
| 409 MetricsMap::iterator process_metrics_iter = metrics_map_.find(handle); | 414 MetricsMap::iterator process_metrics_iter = metrics_map_.find(handle); |
| 410 if (process_metrics_iter == metrics_map_.end()) { | 415 if (process_metrics_iter == metrics_map_.end()) { |
| 411 // If we're not already watching the process, let's initialize it. | 416 // If we're not already watching the process, let's initialize it. |
| 412 metrics_map_[handle] | 417 metrics_map_[handle] |
| 413 .Initialize(handle, process_type, current_update_sequence); | 418 .Initialize(handle, process_type, current_update_sequence); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (initialized_ && !request.url().SchemeIsFile()) | 558 if (initialized_ && !request.url().SchemeIsFile()) |
| 554 performance_data_for_io_thread_.network_bytes_read += bytes_read; | 559 performance_data_for_io_thread_.network_bytes_read += bytes_read; |
| 555 } | 560 } |
| 556 | 561 |
| 557 void PerformanceMonitor::Observe(int type, | 562 void PerformanceMonitor::Observe(int type, |
| 558 const content::NotificationSource& source, | 563 const content::NotificationSource& source, |
| 559 const content::NotificationDetails& details) { | 564 const content::NotificationDetails& details) { |
| 560 DCHECK(database_logging_enabled_); | 565 DCHECK(database_logging_enabled_); |
| 561 | 566 |
| 562 switch (type) { | 567 switch (type) { |
| 568 #if defined(ENABLE_EXTENSIONS) |
| 563 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { | 569 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { |
| 564 AddExtensionEvent( | 570 AddExtensionEvent( |
| 565 EVENT_EXTENSION_INSTALL, | 571 EVENT_EXTENSION_INSTALL, |
| 566 content::Details<const extensions::InstalledExtensionInfo>(details)-> | 572 content::Details<const extensions::InstalledExtensionInfo>(details)-> |
| 567 extension); | 573 extension); |
| 568 break; | 574 break; |
| 569 } | 575 } |
| 570 case extensions::NOTIFICATION_EXTENSION_ENABLED: { | 576 case extensions::NOTIFICATION_EXTENSION_ENABLED: { |
| 571 AddExtensionEvent(EVENT_EXTENSION_ENABLE, | 577 AddExtensionEvent(EVENT_EXTENSION_ENABLE, |
| 572 content::Details<Extension>(details).ptr()); | 578 content::Details<Extension>(details).ptr()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 595 installer->install_cause() == extension_misc::INSTALL_CAUSE_UPDATE) { | 601 installer->install_cause() == extension_misc::INSTALL_CAUSE_UPDATE) { |
| 596 AddExtensionEvent(EVENT_EXTENSION_UPDATE, extension); | 602 AddExtensionEvent(EVENT_EXTENSION_UPDATE, extension); |
| 597 } | 603 } |
| 598 break; | 604 break; |
| 599 } | 605 } |
| 600 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { | 606 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { |
| 601 AddExtensionEvent(EVENT_EXTENSION_UNINSTALL, | 607 AddExtensionEvent(EVENT_EXTENSION_UNINSTALL, |
| 602 content::Details<Extension>(details).ptr()); | 608 content::Details<Extension>(details).ptr()); |
| 603 break; | 609 break; |
| 604 } | 610 } |
| 611 #endif // defined(ENABLE_EXTENSIONS) |
| 605 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: { | 612 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: { |
| 606 std::string url; | 613 std::string url; |
| 607 content::RenderWidgetHost* widget = | 614 content::RenderWidgetHost* widget = |
| 608 content::Source<content::RenderWidgetHost>(source).ptr(); | 615 content::Source<content::RenderWidgetHost>(source).ptr(); |
| 609 if (widget->IsRenderView()) { | 616 if (widget->IsRenderView()) { |
| 610 content::RenderViewHost* view = content::RenderViewHost::From(widget); | 617 content::RenderViewHost* view = content::RenderViewHost::From(widget); |
| 611 MaybeGetURLFromRenderView(view, &url); | 618 MaybeGetURLFromRenderView(view, &url); |
| 612 } | 619 } |
| 613 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), | 620 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), |
| 614 EVENT_RENDERER_HANG, | 621 EVENT_RENDERER_HANG, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 load_details->load_time.ToInternalValue())))); | 659 load_details->load_time.ToInternalValue())))); |
| 653 break; | 660 break; |
| 654 } | 661 } |
| 655 default: { | 662 default: { |
| 656 NOTREACHED(); | 663 NOTREACHED(); |
| 657 break; | 664 break; |
| 658 } | 665 } |
| 659 } | 666 } |
| 660 } | 667 } |
| 661 | 668 |
| 669 #if defined(ENABLE_EXTENSIONS) |
| 662 void PerformanceMonitor::AddExtensionEvent(EventType type, | 670 void PerformanceMonitor::AddExtensionEvent(EventType type, |
| 663 const Extension* extension) { | 671 const Extension* extension) { |
| 664 DCHECK(type == EVENT_EXTENSION_INSTALL || | 672 DCHECK(type == EVENT_EXTENSION_INSTALL || |
| 665 type == EVENT_EXTENSION_UNINSTALL || | 673 type == EVENT_EXTENSION_UNINSTALL || |
| 666 type == EVENT_EXTENSION_UPDATE || | 674 type == EVENT_EXTENSION_UPDATE || |
| 667 type == EVENT_EXTENSION_ENABLE || | 675 type == EVENT_EXTENSION_ENABLE || |
| 668 type == EVENT_EXTENSION_DISABLE); | 676 type == EVENT_EXTENSION_DISABLE); |
| 669 AddEvent(util::CreateExtensionEvent(type, | 677 AddEvent(util::CreateExtensionEvent(type, |
| 670 base::Time::Now(), | 678 base::Time::Now(), |
| 671 extension->id(), | 679 extension->id(), |
| 672 extension->name(), | 680 extension->name(), |
| 673 extension->url().spec(), | 681 extension->url().spec(), |
| 674 extension->location(), | 682 extension->location(), |
| 675 extension->VersionString(), | 683 extension->VersionString(), |
| 676 extension->description())); | 684 extension->description())); |
| 677 } | 685 } |
| 686 #endif // defined(ENABLE_EXTENSIONS) |
| 678 | 687 |
| 679 void PerformanceMonitor::AddRendererClosedEvent( | 688 void PerformanceMonitor::AddRendererClosedEvent( |
| 680 content::RenderProcessHost* host, | 689 content::RenderProcessHost* host, |
| 681 const content::RenderProcessHost::RendererClosedDetails& details) { | 690 const content::RenderProcessHost::RendererClosedDetails& details) { |
| 682 // We only care if this is an invalid termination. | 691 // We only care if this is an invalid termination. |
| 683 if (details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION || | 692 if (details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION || |
| 684 details.status == base::TERMINATION_STATUS_STILL_RUNNING) | 693 details.status == base::TERMINATION_STATUS_STILL_RUNNING) |
| 685 return; | 694 return; |
| 686 | 695 |
| 687 // Determine the type of crash. | 696 // Determine the type of crash. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 709 if (!url_list.empty()) | 718 if (!url_list.empty()) |
| 710 url_list += ", "; | 719 url_list += ", "; |
| 711 | 720 |
| 712 url_list += url; | 721 url_list += url; |
| 713 } | 722 } |
| 714 | 723 |
| 715 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), type, url_list)); | 724 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), type, url_list)); |
| 716 } | 725 } |
| 717 | 726 |
| 718 } // namespace performance_monitor | 727 } // namespace performance_monitor |
| OLD | NEW |