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

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 23691025: Adding shutdown tracing capabilities (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 "content/browser/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 691
692 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 692 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
693 } 693 }
694 694
695 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { 695 void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
696 696
697 if (!created_threads_) { 697 if (!created_threads_) {
698 // Called early, nothing to do 698 // Called early, nothing to do
699 return; 699 return;
700 } 700 }
701 TRACE_EVENT0("shutdown", "BrowserMainLoop::ShutdownThreadsAndCleanUp")
702
701 // Teardown may start in PostMainMessageLoopRun, and during teardown we 703 // Teardown may start in PostMainMessageLoopRun, and during teardown we
702 // need to be able to perform IO. 704 // need to be able to perform IO.
703 base::ThreadRestrictions::SetIOAllowed(true); 705 base::ThreadRestrictions::SetIOAllowed(true);
704 BrowserThread::PostTask( 706 BrowserThread::PostTask(
705 BrowserThread::IO, FROM_HERE, 707 BrowserThread::IO, FROM_HERE,
706 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 708 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
707 true)); 709 true));
708 710
709 if (parts_) 711 if (parts_) {
712 TRACE_EVENT0("shutdown",
713 "BrowserMainLoop::Subsystem:PostMainMessageLoopRun");
710 parts_->PostMainMessageLoopRun(); 714 parts_->PostMainMessageLoopRun();
715 }
711 716
712 trace_memory_controller_.reset(); 717 {
718 TRACE_EVENT0("shutdown",
James Cook 2013/08/30 22:54:02 You don't need this one - this controller doesn't
Mr4D (OOO till 08-26) 2013/08/31 02:03:44 Since that might change I thought it is better to
719 "BrowserMainLoop::Subsystem:TraceMemoryController");
720 trace_memory_controller_.reset();
721 }
713 722
714 #if !defined(OS_IOS) 723 #if !defined(OS_IOS)
715 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to 724 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
716 // delete related objects on the GPU thread. This must be done before 725 // delete related objects on the GPU thread. This must be done before
717 // stopping the GPU thread. The GPU thread will close IPC channels to renderer 726 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
718 // processes so this has to happen before stopping the IO thread. 727 // processes so this has to happen before stopping the IO thread.
719 GpuProcessHostUIShim::DestroyAll(); 728 {
720 729 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUProcessHostShim");
730 GpuProcessHostUIShim::DestroyAll();
731 }
721 // Cancel pending requests and prevent new requests. 732 // Cancel pending requests and prevent new requests.
722 if (resource_dispatcher_host_) 733 if (resource_dispatcher_host_) {
734 TRACE_EVENT0("shutdown",
735 "BrowserMainLoop::Subsystem:ResourceDispatcherHost");
723 resource_dispatcher_host_.get()->Shutdown(); 736 resource_dispatcher_host_.get()->Shutdown();
737 }
724 738
725 #if defined(USE_AURA) 739 #if defined(USE_AURA)
726 ImageTransportFactory::Terminate(); 740 {
741 TRACE_EVENT0("shutdown",
742 "BrowserMainLoop::Subsystem:ImageTransportFactory");
743 ImageTransportFactory::Terminate();
744 }
727 #endif 745 #endif
728 746
729 // The device monitors are using |system_monitor_| as dependency, so delete 747 // The device monitors are using |system_monitor_| as dependency, so delete
730 // them before |system_monitor_| goes away. 748 // them before |system_monitor_| goes away.
731 // On Mac and windows, the monitor needs to be destroyed on the same thread 749 // On Mac and windows, the monitor needs to be destroyed on the same thread
732 // as they were created. On Linux, the monitor will be deleted when IO thread 750 // as they were created. On Linux, the monitor will be deleted when IO thread
733 // goes away. 751 // goes away.
734 #if defined(OS_WIN) 752 #if defined(OS_WIN)
735 system_message_window_.reset(); 753 system_message_window_.reset();
736 #elif defined(OS_MACOSX) 754 #elif defined(OS_MACOSX)
(...skipping 16 matching lines...) Expand all
753 // 771 //
754 // 772 //
755 // - The IO thread is the only user of the CACHE thread. 773 // - The IO thread is the only user of the CACHE thread.
756 // 774 //
757 // - The PROCESS_LAUNCHER thread must be stopped after IO in case 775 // - The PROCESS_LAUNCHER thread must be stopped after IO in case
758 // the IO thread posted a task to terminate a process on the 776 // the IO thread posted a task to terminate a process on the
759 // process launcher thread. 777 // process launcher thread.
760 // 778 //
761 // - (Not sure why DB stops last.) 779 // - (Not sure why DB stops last.)
762 switch (thread_id) { 780 switch (thread_id) {
763 case BrowserThread::DB: 781 case BrowserThread::DB: {
764 db_thread_.reset(); 782 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread");
783 db_thread_.reset();
784 }
765 break; 785 break;
766 case BrowserThread::FILE_USER_BLOCKING: 786 case BrowserThread::FILE_USER_BLOCKING: {
767 file_user_blocking_thread_.reset(); 787 TRACE_EVENT0("shutdown",
788 "BrowserMainLoop::Subsystem:FileUserBlockingThread");
789 file_user_blocking_thread_.reset();
790 }
768 break; 791 break;
769 case BrowserThread::FILE: 792 case BrowserThread::FILE: {
793 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread");
770 #if !defined(OS_IOS) 794 #if !defined(OS_IOS)
771 // Clean up state that lives on or uses the file_thread_ before 795 // Clean up state that lives on or uses the file_thread_ before
772 // it goes away. 796 // it goes away.
773 if (resource_dispatcher_host_) 797 if (resource_dispatcher_host_)
774 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); 798 resource_dispatcher_host_.get()->save_file_manager()->Shutdown();
775 #endif // !defined(OS_IOS) 799 #endif // !defined(OS_IOS)
776 file_thread_.reset(); 800 file_thread_.reset();
801 }
777 break; 802 break;
778 case BrowserThread::PROCESS_LAUNCHER: 803 case BrowserThread::PROCESS_LAUNCHER: {
779 process_launcher_thread_.reset(); 804 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread");
805 process_launcher_thread_.reset();
806 }
780 break; 807 break;
781 case BrowserThread::CACHE: 808 case BrowserThread::CACHE: {
782 cache_thread_.reset(); 809 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread");
810 cache_thread_.reset();
811 }
783 break; 812 break;
784 case BrowserThread::IO: 813 case BrowserThread::IO: {
785 io_thread_.reset(); 814 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread");
815 io_thread_.reset();
816 }
786 break; 817 break;
787 case BrowserThread::UI: 818 case BrowserThread::UI:
788 case BrowserThread::ID_COUNT: 819 case BrowserThread::ID_COUNT:
789 default: 820 default:
790 NOTREACHED(); 821 NOTREACHED();
791 break; 822 break;
792 } 823 }
793 } 824 }
794 825
795 #if !defined(OS_IOS) 826 #if !defined(OS_IOS)
796 indexed_db_thread_.reset(); 827 {
828 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread");
829 indexed_db_thread_.reset();
830 }
797 #endif 831 #endif
798 832
799 // Close the blocking I/O pool after the other threads. Other threads such 833 // Close the blocking I/O pool after the other threads. Other threads such
800 // as the I/O thread may need to schedule work like closing files or flushing 834 // as the I/O thread may need to schedule work like closing files or flushing
801 // data during shutdown, so the blocking pool needs to be available. There 835 // data during shutdown, so the blocking pool needs to be available. There
802 // may also be slow operations pending that will blcok shutdown, so closing 836 // may also be slow operations pending that will blcok shutdown, so closing
803 // it here (which will block until required operations are complete) gives 837 // it here (which will block until required operations are complete) gives
804 // more head start for those operations to finish. 838 // more head start for those operations to finish.
805 BrowserThreadImpl::ShutdownThreadPool(); 839 {
840 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool");
841 BrowserThreadImpl::ShutdownThreadPool();
842 }
806 843
807 #if !defined(OS_IOS) 844 #if !defined(OS_IOS)
808 // Must happen after the IO thread is shutdown since this may be accessed from 845 // Must happen after the IO thread is shutdown since this may be accessed from
809 // it. 846 // it.
810 BrowserGpuChannelHostFactory::Terminate(); 847 {
848 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory");
849 BrowserGpuChannelHostFactory::Terminate();
850 }
811 851
812 // Must happen after the I/O thread is shutdown since this class lives on the 852 // Must happen after the I/O thread is shutdown since this class lives on the
813 // I/O thread and isn't threadsafe. 853 // I/O thread and isn't threadsafe.
814 GamepadService::GetInstance()->Terminate(); 854 {
815 DeviceInertialSensorService::GetInstance()->Shutdown(); 855 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GamepadService");
816 856 GamepadService::GetInstance()->Terminate();
817 URLDataManager::DeleteDataSources(); 857 }
858 {
859 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:SensorService");
860 DeviceInertialSensorService::GetInstance()->Shutdown();
861 }
862 {
863 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DeleteDataSources");
James Cook 2013/08/30 22:54:02 This seems like a lot of TRACE_EVENT macros in thi
Mr4D (OOO till 08-26) 2013/08/31 02:03:44 I was trying first to move that into the functions
864 URLDataManager::DeleteDataSources();
865 }
818 #endif // !defined(OS_IOS) 866 #endif // !defined(OS_IOS)
819 867
820 if (parts_) 868 if (parts_) {
869 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:PostDestroyThreads");
821 parts_->PostDestroyThreads(); 870 parts_->PostDestroyThreads();
871 }
822 } 872 }
823 873
824 void BrowserMainLoop::InitializeMainThread() { 874 void BrowserMainLoop::InitializeMainThread() {
825 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread") 875 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread")
826 const char* kThreadName = "CrBrowserMain"; 876 const char* kThreadName = "CrBrowserMain";
827 base::PlatformThread::SetName(kThreadName); 877 base::PlatformThread::SetName(kThreadName);
828 if (main_message_loop_) 878 if (main_message_loop_)
829 main_message_loop_->set_thread_name(kThreadName); 879 main_message_loop_->set_thread_name(kThreadName);
830 880
831 // Register the main thread by instantiating it, but don't call any methods. 881 // Register the main thread by instantiating it, but don't call any methods.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 if (parameters_.ui_task) 1039 if (parameters_.ui_task)
990 base::MessageLoopForUI::current()->PostTask(FROM_HERE, 1040 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
991 *parameters_.ui_task); 1041 *parameters_.ui_task);
992 1042
993 base::RunLoop run_loop; 1043 base::RunLoop run_loop;
994 run_loop.Run(); 1044 run_loop.Run();
995 #endif 1045 #endif
996 } 1046 }
997 1047
998 } // namespace content 1048 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698