diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-25 22:18:06 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-25 22:18:06 +0000 |
commit | 700bf620e83311f8a21f60cfb8dc292ec0780a31 (patch) | |
tree | 18351992efd69e8e5077dcb76874a6684fb30431 | |
parent | 65bd67d12cbbf73a0c7842750bd30639ddad2306 (diff) | |
download | chromium_src-700bf620e83311f8a21f60cfb8dc292ec0780a31.zip chromium_src-700bf620e83311f8a21f60cfb8dc292ec0780a31.tar.gz chromium_src-700bf620e83311f8a21f60cfb8dc292ec0780a31.tar.bz2 |
Remove the profiling system. This wasn't being used and complicated some parts of the code (I'm trying to clean up WebContents). We can ressurect this if we have a better plan for doing profiling that needs to live in the browser.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1341 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/SConscript.unit_tests | 2 | ||||
-rw-r--r-- | chrome/browser/SConscript | 2 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 24 | ||||
-rw-r--r-- | chrome/browser/navigation_entry.h | 7 | ||||
-rw-r--r-- | chrome/browser/navigation_profiler.cc | 309 | ||||
-rw-r--r-- | chrome/browser/navigation_profiler.h | 195 | ||||
-rw-r--r-- | chrome/browser/navigation_profiler_unittest.cc | 125 | ||||
-rw-r--r-- | chrome/browser/network_status_view.cc | 166 | ||||
-rw-r--r-- | chrome/browser/network_status_view.h | 44 | ||||
-rw-r--r-- | chrome/browser/page_load_tracker.cc | 230 | ||||
-rw-r--r-- | chrome/browser/page_load_tracker.h | 171 | ||||
-rw-r--r-- | chrome/browser/page_load_tracker_unittest.cc | 147 | ||||
-rw-r--r-- | chrome/browser/resource_dispatcher_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 83 | ||||
-rw-r--r-- | chrome/browser/web_contents.h | 31 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 12 |
16 files changed, 8 insertions, 1544 deletions
diff --git a/chrome/SConscript.unit_tests b/chrome/SConscript.unit_tests index 05b9353..32fb4a0 100644 --- a/chrome/SConscript.unit_tests +++ b/chrome/SConscript.unit_tests @@ -160,10 +160,8 @@ unit_test_files = [ 'browser/metrics_log_unittest.cc', 'browser/metrics_response_unittest.cc', 'browser/navigation_controller_unittest.cc', - 'browser/navigation_profiler_unittest.cc', 'browser/net/dns_host_info_unittest.cc', 'browser/net/dns_master_unittest.cc', - 'browser/page_load_tracker_unittest.cc', 'browser/password_form_manager_unittest.cc', 'browser/printing/page_number_unittest.cc', 'browser/printing/page_overlays_unittest.cc', diff --git a/chrome/browser/SConscript b/chrome/browser/SConscript index 9d6694c..e5499ca 100644 --- a/chrome/browser/SConscript +++ b/chrome/browser/SConscript @@ -201,7 +201,6 @@ input_files = [ 'navigation_controller.cc', 'navigation_entry.cc', 'navigation_performance_viewer.cc', - 'navigation_profiler.cc', 'net/dns_global.cc', 'net/dns_host_info.cc', 'net/dns_master.cc', @@ -209,7 +208,6 @@ input_files = [ 'network_status_view.cc', 'google_update.cc', 'page_info_window.cc', - 'page_load_tracker.cc', 'page_state.cc', 'password_form_manager.cc', 'password_manager.cc', diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 0747b6f..cb2ee81 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -866,22 +866,6 @@ > </File> <File - RelativePath=".\navigation_performance_viewer.cc" - > - </File> - <File - RelativePath=".\navigation_performance_viewer.h" - > - </File> - <File - RelativePath=".\navigation_profiler.cc" - > - </File> - <File - RelativePath=".\navigation_profiler.h" - > - </File> - <File RelativePath=".\network_status_view.cc" > </File> @@ -890,14 +874,6 @@ > </File> <File - RelativePath=".\page_load_tracker.cc" - > - </File> - <File - RelativePath=".\page_load_tracker.h" - > - </File> - <File RelativePath=".\page_navigator.h" > </File> diff --git a/chrome/browser/navigation_entry.h b/chrome/browser/navigation_entry.h index 10006cc..0b5073f 100644 --- a/chrome/browser/navigation_entry.h +++ b/chrome/browser/navigation_entry.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_NAVIGATION_ENTRY_H__ -#define CHROME_BROWSER_NAVIGATION_ENTRY_H__ +#ifndef CHROME_BROWSER_NAVIGATION_ENTRY_H_ +#define CHROME_BROWSER_NAVIGATION_ENTRY_H_ #include "base/basictypes.h" #include "base/scoped_ptr.h" @@ -284,5 +284,4 @@ class NavigationEntry { bool restored_; }; -#endif // CHROME_BROWSER_NAVIGATION_ENTRY_H__ - +#endif // CHROME_BROWSER_NAVIGATION_ENTRY_H_ diff --git a/chrome/browser/navigation_profiler.cc b/chrome/browser/navigation_profiler.cc deleted file mode 100644 index e7d5746..0000000 --- a/chrome/browser/navigation_profiler.cc +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// The majority of NavigationProfiler is not implemented. The global -// profiling flag is set false so no actual profiling is done at -// WebContents and URLRequestJob. - -#include "chrome/browser/browser_process.h" -#include "chrome/browser/navigation_performance_viewer.h" -#include "chrome/browser/navigation_profiler.h" -#include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_util.h" -#include "chrome/browser/web_contents.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_job.h" -#include "net/url_request/url_request_job_tracker.h" - -NavigationProfiler g_navigation_profiler; - -NavigationProfiler::NavigationProfiler() - : session_id_(0), - is_profiling_(false) { -} - -NavigationProfiler::~NavigationProfiler() { - Reset(); -} - -void NavigationProfiler::Reset() { - ResetActivePageList(); - ResetVisitedPageList(); -} - -int NavigationProfiler::StartProfiling() { - bool new_session = false; - - int session; - { - AutoLock locked(access_lock_); - - if (!is_profiling()) { - Reset(); - new_session = true; - ++session_id_; - } - - session = session_id(); - } - - if (new_session) { - Thread* thread = g_browser_process->io_thread(); - - // In the case of concurent StartProfiling calls, there might be several - // messages dispatched to IO thread. Only the message with matching - // session_id_ will have effect. - if (thread) - thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &NavigationProfiler::StartProfilingInIOThread, session)); - } - - return session; -} - -void NavigationProfiler::StopProfiling(int session) { - bool stop_session = false; - - { - AutoLock locked(access_lock_); - - if (is_profiling() && session == session_id()) { - stop_session = true; - } - - // Move pages currently in active page list to visited page list so their - // status can be reported. - for (NavigationProfiler::PageTrackerIterator i = active_page_list_.begin(); - i != active_page_list_.end(); - ++i) { - PageLoadTracker* page = *i; - visited_page_list_.push_back(page); - } - active_page_list_.clear(); - } - - if (stop_session) { - Thread* thread = g_browser_process->io_thread(); - if (thread) - thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &NavigationProfiler::StopProfilingInIOThread, session)); - } -} - -void NavigationProfiler::StartProfilingInIOThread(int session) { - AutoLock locked(access_lock_); - - if (!is_profiling() && session == session_id()) { - g_url_request_job_tracker.AddObserver(this); - is_profiling_ = true; - } -} - -void NavigationProfiler::StopProfilingInIOThread(int session) { - AutoLock locked(access_lock_); - - if (is_profiling() && session == session_id()) { - g_url_request_job_tracker.RemoveObserver(this); - is_profiling_ = false; - } -} - -int NavigationProfiler::RetrieveVisitedPages( - NavigationPerformanceViewer* viewer) { - - AutoLock locked(access_lock_); - - if (!viewer) - return 0; - - int num_pages = 0; - - if (viewer->session_id() == session_id()) { - while (!visited_page_list_.empty()) { - PageLoadTracker* page = visited_page_list_.back(); - viewer->AddPage(page); - num_pages++; - visited_page_list_.pop_back(); - } - } - - return num_pages; -} - -void NavigationProfiler::ResetVisitedPageList() { - AutoLock locked(access_lock_); - - for (NavigationProfiler::PageTrackerIterator i = visited_page_list_.begin(); - i != visited_page_list_.end(); - ++i) { - delete (*i); - } - - visited_page_list_.clear(); -} - -void NavigationProfiler::ResetActivePageList() { - AutoLock locked(access_lock_); - - for (NavigationProfiler::PageTrackerIterator i = active_page_list_.begin(); - i != active_page_list_.end(); - ++i) { - delete (*i); - } - - active_page_list_.clear(); -} - -void NavigationProfiler::AddActivePage(PageLoadTracker* page) { - if (!is_profiling()) - return; - - if (!page) - return; - - // If the tab already has an active PageLoadTracker, remove it. - RemoveActivePage(page->render_process_host_id(), page->routing_id()); - - { - AutoLock locked(access_lock_); - active_page_list_.push_back(page); - } -} - -void NavigationProfiler::MoveActivePageToVisited(int render_process_host_id, - int routing_id) { - AutoLock locked(access_lock_); - - if (!is_profiling()) - return; - - PageTrackerIterator i = - GetPageLoadTrackerByIDUnsafe(render_process_host_id, routing_id); - - PageLoadTracker* page = NULL; - if (i != active_page_list_.end()) { - page = *i; - active_page_list_.erase(i); - } - - if (page) { - visited_page_list_.push_back(page); - } -} - -void NavigationProfiler::RemoveActivePage(int render_process_host_id, - int routing_id) { - AutoLock locked(access_lock_); - - if (!is_profiling()) - return; - - PageTrackerIterator i = - GetPageLoadTrackerByIDUnsafe(render_process_host_id, routing_id); - - if (i != active_page_list_.end()) { - delete (*i); - active_page_list_.erase(i); - } -} - - -void NavigationProfiler::AddFrameMetrics( - int render_process_host_id, - int routing_id, - FrameNavigationMetrics* frame_metrics) { - - AutoLock locked(access_lock_); - - if (!is_profiling()) - return; - - if (!frame_metrics) - return; - - PageTrackerIterator i = - GetPageLoadTrackerByIDUnsafe(render_process_host_id, routing_id); - - if (i != active_page_list_.end()) { - (*i)->AddFrameMetrics(frame_metrics); - } -} - -void NavigationProfiler::AddJobMetrics(int render_process_host_id, - int routing_id, - URLRequestJobMetrics* job_metrics) { - AutoLock locked(access_lock_); - - if (!is_profiling()) - return; - - if (!job_metrics) - return; - - PageTrackerIterator i = - GetPageLoadTrackerByIDUnsafe(render_process_host_id, routing_id); - - if (i != active_page_list_.end()) { - (*i)->AddJobMetrics(job_metrics); - } -} - -void NavigationProfiler::SetLoadingEndTime(int render_process_host_id, - int routing_id, - int32 page_id, - TimeTicks time) { - AutoLock locked(access_lock_); - - if (!is_profiling()) - return; - - PageTrackerIterator i = - GetPageLoadTrackerByIDUnsafe(render_process_host_id, routing_id); - - if (i != active_page_list_.end()) { - (*i)->SetLoadingEndTime(page_id, time); - } -} - -NavigationProfiler::PageTrackerIterator - NavigationProfiler::GetPageLoadTrackerByIDUnsafe( - int render_process_host_id, int routing_id) { - PageTrackerIterator i; - - for (i = active_page_list_.begin(); i != active_page_list_.end(); ++i) { - if ((*i)->render_process_host_id() == render_process_host_id && - (*i)->routing_id() == routing_id) { - break; - } - } - - return i; -} - -void NavigationProfiler::OnJobAdded(URLRequestJob* job) { -} - -void NavigationProfiler::OnJobRemoved(URLRequestJob* job) { -} - -void NavigationProfiler::OnJobDone(URLRequestJob* job, - const URLRequestStatus& status) { - if (!job) - return; - - int render_process_host_id, routing_id; - if (tab_util::GetTabContentsID(job->request(), - &render_process_host_id, &routing_id)) { - AddJobMetrics(render_process_host_id, routing_id, job->RetrieveMetrics()); - } -} - -void NavigationProfiler::OnJobRedirect(URLRequestJob* job, - const GURL& location, - int status_code) { -} - -void NavigationProfiler::OnBytesRead(URLRequestJob* job, int byte_count) { -} - diff --git a/chrome/browser/navigation_profiler.h b/chrome/browser/navigation_profiler.h deleted file mode 100644 index 59a769a..0000000 --- a/chrome/browser/navigation_profiler.h +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Overview of performance profiling. -// -// 1. Building blocks -// - NavigationProfiler: central place to collect performance data. -// - PageLoadTracker: tracking performance data of one page navigation. -// - FrameNavigationMetrics: tracking performance data of one frame loading. -// - URLRequestJobMetrics: tracking IO statistics of one URLRequestJob. -// - NavigationPerformanceViewer: analyzing and reporting performance data. -// -// 2. Data collection and management -// (1) NavigationProfiler maintains two lists of PageLoadTracker: the visited -// page list that saves performance measurement of visited pages, and the -// active page list that is used to update performance measurement for pages -// being loaded. -// (2) Every time when render navigates to a new page, an instance of -// PageLoadTracker is created by WebContents and added to the active page -// list. The WebContents updates frame related measurement data during page -// loading. When the page loading stops, the PageLoadTracker is detached from -// active page list and added to the visited page list. -// (3) Everytime when a new URLRequestJob is created, an instance of -// URLRequestJobMetrics is created and attached to the corresponding job -// object. When the job is done, NavigationProfiler maps the job to the page -// being loaded and attaches the URLRequestJobMetrics object to the -// corresponding PageLoadTracker object. -// (4) NavigationProfiler resets the lists of PageLoadTracker on demand. -// -// 3. Performance reporting -// NavigationPerformanceViewer retrieves the performance data from the visited -// page list and generates report. -// -// 4. design Notes -// An alternative design is using Microsoft ETW (Event Tracing for Windows) -// infrastructure. With ETW approach, WebContents, URLRequestJob, and other -// run time objects act as event providers and write events to ETW sessions. -// A seperate ETW consumer reads the data from ETW session and performs data -// analysis and report. ETW has the advantage of providing a unified platform -// for profiling and tracing, and build-in support to write log files. These -// advantages don't benefit us much, and it will be more difficult to analyze -// the relationships between events after all run time objects are gone. - -#ifndef CHROME_NAVIGATION_PROFILER_H__ -#define CHROME_NAVIGATION_PROFILER_H__ - -#include <vector> - -#include "base/lock.h" -#include "chrome/browser/page_load_tracker.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_job_tracker.h" -#include "testing/gtest/include/gtest/gtest_prod.h" - -class NavigationPerformanceViewer; - -class NavigationProfiler : public URLRequestJobTracker::JobObserver { - FRIEND_TEST(NavigationProfilerUnitTest, ActiveListAdd); - FRIEND_TEST(NavigationProfilerUnitTest, ActiveListRemove); - - public: - NavigationProfiler(); - virtual ~NavigationProfiler(); - - typedef std::vector<PageLoadTracker*> PageTrackerVector; - typedef PageTrackerVector::iterator PageTrackerIterator; - - // Start performance profiling. - // If a new profiling session needs to be started, the function starts - // the session and returns the new session ID. If there is an existing - // profiling session, the function returns the current session ID. - int StartProfiling(); - - // Stop performance profiling. The input session needs to match the - // current session ID to stop the profiling session. - void StopProfiling(int session); - - bool is_profiling() const { return is_profiling_; } - - int session_id() const { return session_id_; } - - // Retrieve PageLoadTrackers from visited page list and transfer them to - // viewer. Removes entries that have been transferred. - // Return values: number of PageLoadTrackers retrieved. - int RetrieveVisitedPages(NavigationPerformanceViewer* viewer); - - //------------------------------------------------------ - // Functions to update the active page list. - // (1) The functions are all atomic. (2) If a new data object - // (PageLoadTracker, FrameNavigationMetrics, URLRequestJobMetrics) is added, - // the NavigationProfiler owns the object from now on. - - // Add a new PageLoadTracker to the active page list. - // The NavigationProfiler owns the PageLoadTracker from now on. - void AddActivePage(PageLoadTracker* page); - - // Find the PageLoadTracker by render_process_host_id and routing_id, then - // remove the PageLoadTracker from the active page list and add it to the - // visited page list. - void MoveActivePageToVisited(int render_process_host_id, int routing_id); - - // Find the PageLoadTracker by render_process_host_id and routing_id, then - // remove the PageLoadTracker from the active page list. - void RemoveActivePage(int render_process_host_id, int routing_id); - - // Find the PageLoadTracker in the active page list by render_process_host_id - // and routing_id, then add the provided URLRequestJobMetrics to the - // PageLoadTracker. - // The NavigationProfiler owns the URLRequestJobMetrics from now on. - void AddJobMetrics(int render_process_host_id, int routing_id, - URLRequestJobMetrics* job_metrics); - - // Find the PageLoadTracker in the active page list by render_process_host_id - // and routing_id, then add the provided FrameNavigationMetrics to the - // PageLoadTracker. - // The NavigationProfiler owns the FrameNavigationMetrics from now on. - void AddFrameMetrics(int render_process_host_id, int routing_id, - FrameNavigationMetrics* frame_metrics); - - // Find the PageLoadTracker in the active page list by render_process_host_id - // and routing_id, then set the loading complete time of the main frame - // corresponding to page_id. - void SetLoadingEndTime(int render_process_host_id, int routing_id, - int32 page_id, TimeTicks time); - - //------------------------------------------------------ - // URLRequestJobTracker::JobObserver methods - // Invoked by g_url_request_job_tracker in IO thread - virtual void OnJobAdded(URLRequestJob* job); - virtual void OnJobRemoved(URLRequestJob* job); - virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); - virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, - int status_code); - virtual void OnBytesRead(URLRequestJob* job, int byte_count); - - // These are only used to create RunnableMethod. - void AddRef() { } - void Release() { } - - private: - // Start collecting performance data in IO thread. Should be called only in - // IO thread. - void StartProfilingInIOThread(int session); - - // Stop collecting performance data in IO thread. Should be called only in - // IO thread. - void StopProfilingInIOThread(int session); - - // Clear all performance measurement data - void Reset(); - - // Find the PageLoadTracker in the active page list by render_process_host_id - // and routing_id of the TabContent that serves the page. - // Note: The caller must acquire the lock on active page list before calling - // this function. - PageTrackerIterator GetPageLoadTrackerByIDUnsafe(int render_process_host_id, - int routing_id); - - - // Reset Visited page list by removing all its entries. - void ResetVisitedPageList(); - - // Reset active page list by removing all its entries. - void ResetActivePageList(); - - // List of PageLoadTrackers that save performance measurement of visited - // pages. - PageTrackerVector visited_page_list_; - - // List of PageLoadTrackers that track performance measurement of pages - // currently under loading. - PageTrackerVector active_page_list_; - - // Lock to access and update the profiler. - // The profiler is read and updated by UI thread, IO thread, and potentially - // backend viewer. All public access/update functions of NavigationProfiler - // acquire/release this lock. The operation of each method holding the lock - // is kept minimal. When a performance metrics is inserted/retrieved, the - // NavigationProfiler transfers ownership instead of copying the object. - Lock access_lock_; - - // The current profiling session ID. - int session_id_; - - // Specifies whether profiling is enabled. - bool is_profiling_; - - DISALLOW_EVIL_CONSTRUCTORS(NavigationProfiler); -}; - -extern NavigationProfiler g_navigation_profiler; - -#endif // #ifndef CHROME_NAVIGATION_PROFILER_H__ - diff --git a/chrome/browser/navigation_profiler_unittest.cc b/chrome/browser/navigation_profiler_unittest.cc deleted file mode 100644 index 165e45f..0000000 --- a/chrome/browser/navigation_profiler_unittest.cc +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/scoped_ptr.h" -#include "chrome/browser/navigation_profiler.h" -#include "chrome/browser/page_load_tracker.h" -#include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_util.h" -#include "chrome/browser/web_contents.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_job.h" -#include "testing/gtest/include/gtest/gtest.h" - -// Test functions that update the active page list. -TEST(NavigationProfilerUnitTest, ActiveListAdd) { - scoped_ptr<NavigationProfiler> profiler(new NavigationProfiler()); - profiler->is_profiling_ = true; - - std::string url_str("www.google.com"); - GURL url(url_str); - - int render_process_host_id = 10; - int routing_id = 10; - TimeTicks start_time = TimeTicks::Now(); - - PageLoadTracker* page = - new PageLoadTracker(url, render_process_host_id, routing_id, start_time); - - profiler->AddActivePage(page); - - // Add another two pages - page = new PageLoadTracker(url, render_process_host_id + 1, routing_id + 1, - start_time + TimeDelta::FromSeconds(1)); - profiler->AddActivePage(page); - - page = new PageLoadTracker(url, render_process_host_id + 2, routing_id + 2, - start_time + TimeDelta::FromSeconds(2)); - profiler->AddActivePage(page); - - ASSERT_TRUE(profiler->active_page_list_.size() == 3); - - // Add frames - int32 page_id = 1; - FrameNavigationMetrics* frame = - new FrameNavigationMetrics(PageTransition::TYPED, - start_time + TimeDelta::FromMilliseconds(100), - url, - page_id); - profiler->AddFrameMetrics(render_process_host_id, routing_id, frame); - - frame = new FrameNavigationMetrics(PageTransition::AUTO_SUBFRAME, - start_time + TimeDelta::FromMilliseconds(200), url, page_id); - - profiler->AddFrameMetrics(render_process_host_id, routing_id, frame); - - profiler->SetLoadingEndTime(render_process_host_id, routing_id, page_id, - start_time + TimeDelta::FromMilliseconds(300)); - - // Get the page - NavigationProfiler::PageTrackerIterator itr = - profiler->GetPageLoadTrackerByIDUnsafe(render_process_host_id, - routing_id); - - ASSERT_TRUE(itr != profiler->active_page_list_.end()); - ASSERT_TRUE((*itr)->start_time() == start_time); - ASSERT_TRUE((*itr)->stop_time() == - start_time + TimeDelta::FromMilliseconds(300)); -} - - -TEST(NavigationProfilerUnitTest, ActiveListRemove) { - scoped_ptr<NavigationProfiler> profiler(new NavigationProfiler()); - profiler->is_profiling_ = true; - - std::string url_str("www.google.com"); - GURL url(url_str); - - int render_process_host_id = 10; - int routing_id = 10; - TimeTicks start_time = TimeTicks::Now(); - - PageLoadTracker* page = - new PageLoadTracker(url, render_process_host_id, routing_id, - start_time); - - profiler->AddActivePage(page); - - // Add another two pages - page = new PageLoadTracker(url, render_process_host_id + 1, routing_id + 1, - start_time + TimeDelta::FromSeconds(1)); - profiler->AddActivePage(page); - - page = new PageLoadTracker(url, render_process_host_id + 2, routing_id + 2, - start_time + TimeDelta::FromSeconds(2)); - profiler->AddActivePage(page); - - ASSERT_TRUE(profiler->active_page_list_.size() == 3); - - // Remove a page - profiler->RemoveActivePage(render_process_host_id + 1, routing_id + 1); - - ASSERT_TRUE(profiler->active_page_list_.size() == 2); - - NavigationProfiler::PageTrackerIterator itr = - profiler->GetPageLoadTrackerByIDUnsafe(render_process_host_id + 1, - routing_id + 1); - - ASSERT_TRUE(itr == profiler->active_page_list_.end()); - - // Replace a page - page = new PageLoadTracker(url, render_process_host_id, routing_id, - start_time + TimeDelta::FromSeconds(3)); - - profiler->AddActivePage(page); - ASSERT_TRUE(profiler->active_page_list_.size() == 2); - - itr = profiler->GetPageLoadTrackerByIDUnsafe(render_process_host_id, - routing_id); - - ASSERT_TRUE(itr != profiler->active_page_list_.end()); - ASSERT_TRUE((*itr)->start_time() == - start_time + TimeDelta::FromSeconds(3)); -} - diff --git a/chrome/browser/network_status_view.cc b/chrome/browser/network_status_view.cc index 19eabe8..296d46e 100644 --- a/chrome/browser/network_status_view.cc +++ b/chrome/browser/network_status_view.cc @@ -10,9 +10,6 @@ #include "base/thread.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/navigation_profiler.h" -#include "chrome/browser/navigation_performance_viewer.h" -#include "chrome/browser/page_load_tracker.h" #include "chrome/browser/tab_contents_delegate.h" #include "chrome/views/hwnd_view_container.h" #include "chrome/views/root_view.h" @@ -24,12 +21,7 @@ const wchar_t kTitleMsg[] = L"Network Status"; const wchar_t kStartTrackingMsg[] = L"Start I/O Tracking"; const wchar_t kStopTrackingMsg[] = L"Stop I/O Tracking"; -const wchar_t kStartProfilingMsg[] = L"Start Profiling"; -const wchar_t kStopProfilingMsg[] = L"Stop Profiling"; - const wchar_t kShowIOStatusMsg[] = L"Show Current I/O Status"; -const wchar_t kShowPerformanceMsg[] = L"Show Performance"; -const wchar_t kRefreshPerformanceMsg[] = L"Refresh Performance"; const wchar_t kClearOutputMsg[] = L"Clear Output"; // Returns a string representing the URL, handling the case where the spec @@ -63,11 +55,6 @@ NetworkStatusView::~NetworkStatusView() { is_tracking_ = false; } - if (is_profiling_) { - g_navigation_profiler.StopProfiling(profiling_session_id_); - is_profiling_ = false; - } - tracker_->DetachView(); } @@ -78,12 +65,9 @@ const std::wstring NetworkStatusView::GetDefaultTitle() { void NetworkStatusView::OnCreate(const CRect& rect) { CreateButton(IDC_CONFIG_TRACKING_BUTTON, kStartTrackingMsg); CreateButton(IDC_CURRENT_STATUS_BUTTON, kShowIOStatusMsg); - CreateButton(IDC_CONFIG_PROFILING_BUTTON, kStartProfilingMsg); - CreateButton(IDC_SHOW_PERFORMANCE_BUTTON, kShowPerformanceMsg); CreateButton(IDC_CLEAR, kClearOutputMsg); is_tracking_ = false; - is_profiling_ = false; // Initialize the text box for network tracking // Don't worry about the size, we'll resize when we get WM_SIZE @@ -101,32 +85,6 @@ void NetworkStatusView::OnCreate(const CRect& rect) { wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Courier New"); monospaced_font_ = CreateFontIndirect(&lf); text_area_.SetFont(monospaced_font_); - - HideTrackingResults(); - - // Initialize the view for performance profiling - // Don't worry about the size, we'll resize when we get WM_SIZE - - // List of loaded pages - page_list_.Create(m_hWnd, const_cast<CRect&>(rect), NULL, - WS_CHILD | WS_HSCROLL | WS_VSCROLL | LBS_STANDARD, 0, - IDC_PAGE_LISTBOX); - - // Textual report of page loading - page_text_.Create(m_hWnd, const_cast<CRect&>(rect), NULL, - WS_CHILD | WS_HSCROLL | WS_VSCROLL | - ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0); - page_text_.SetFont(monospaced_font_); - // Raise the maximum number of chars from 32K to some large maximum. - page_text_.SendMessageW(EM_SETLIMITTEXT, 0, 0); - - // Graphical report of page loading - page_load_view_ = new PageLoadView(); - page_view_container_ = new ChromeViews::HWNDViewContainer; - page_view_container_->Init(m_hWnd, gfx::Rect(rect), false); - page_view_container_->SetContentsView(page_load_view_); - - HideProfilingResults(); } void NetworkStatusView::OnSize(const CRect& rect) { @@ -139,21 +97,6 @@ void NetworkStatusView::OnSize(const CRect& rect) { int list_height = static_cast<int>(rect.Height() / 5); int page_width = rect.Width() / 2; int page_height = static_cast<int>(rect.Height() * 4 / 5); - - new_rect.SetRect(rect.left, rect.top, - rect.left + list_width, rect.top + list_height); - page_list_.MoveWindow(new_rect); - - new_rect.SetRect(rect.left, - rect.top + list_height, - rect.left + page_width, - rect.top + list_height + page_height); - page_text_.MoveWindow(new_rect); - - page_view_container_->MoveWindow(rect.left + page_width + kLayoutPadding, - rect.top + list_height, - page_width - kLayoutPadding, page_height, - TRUE); } void NetworkStatusView::OnConfigTrackingClicked(UINT code, int button_id, @@ -184,71 +127,6 @@ void NetworkStatusView::OnCurrentStatusClicked(UINT code, int button_id, void NetworkStatusView::OnClearClicked(UINT code, int button_id, HWND hwnd) { ClearTrackingResults(); - ClearProfilingResults(); -} - -void NetworkStatusView::OnConfigProfilingClicked(UINT code, int button_id, - HWND hwnd) { - if (is_profiling_) { - g_navigation_profiler.StopProfiling(profiling_session_id_); - is_profiling_ = false; - - HideProfilingResults(); - - SetButtonText(IDC_CONFIG_PROFILING_BUTTON, kStartProfilingMsg); - } else { - profiling_session_id_ = g_navigation_profiler.StartProfiling(); - is_profiling_ = true; - - HideTrackingResults(); - ClearProfilingResults(); - - performance_viewer_.reset( - new NavigationPerformanceViewer(profiling_session_id_)); - - ShowProfilingResults(); - - SetButtonText(IDC_CONFIG_PROFILING_BUTTON, kStopProfilingMsg); - SetButtonText(IDC_SHOW_PERFORMANCE_BUTTON, kShowPerformanceMsg); - } -} - -void NetworkStatusView::OnShowPerformanceClicked(UINT code, int button_id, - HWND hwnd) { - HideTrackingResults(); - ShowProfilingResults(); - - if (!is_profiling_) - return; - - int num_pages = - g_navigation_profiler.RetrieveVisitedPages(performance_viewer_.get()); - - // Refresh display if there are new page profiling results - if (num_pages > 0) { - // Display the list of page URLs - page_list_.ResetContent(); - int size = performance_viewer_->GetSize(); - for (int i = 0; i < size; ++i) { - PageLoadTracker* page = performance_viewer_->GetPageReference(i); - page_list_.InsertString(i, StringForURL(page->url()).c_str()); - } - - page_list_.SetCurSel(current_page_index_); - ReportPagePerformance(current_page_index_); - - SetButtonText(IDC_SHOW_PERFORMANCE_BUTTON, kRefreshPerformanceMsg); - } -} - -void NetworkStatusView::OnPageDoubleClicked(UINT code, int command_id, - HWND window) { - int index = page_list_.GetCurSel(); - if (index == LB_ERR) - return; - - current_page_index_ = index; - ReportPagePerformance(current_page_index_); } void NetworkStatusView::AppendText(const std::wstring& text) { @@ -260,7 +138,6 @@ void NetworkStatusView::HideTrackingResults() { } void NetworkStatusView::ShowTrackingResults() { - HideProfilingResults(); text_area_.ShowWindow(SW_SHOW); } @@ -269,49 +146,6 @@ void NetworkStatusView::ClearTrackingResults() { text_area_.Clear(); } -void NetworkStatusView::HideProfilingResults() { - page_list_.ShowWindow(SW_HIDE); - page_text_.ShowWindow(SW_HIDE); - page_view_container_->ShowWindow(SW_HIDE); -} - -void NetworkStatusView::ShowProfilingResults() { - HideTrackingResults(); - page_list_.ShowWindow(SW_SHOW); - page_text_.ShowWindow(SW_SHOW); - page_view_container_->ShowWindow(SW_SHOW); -} - -void NetworkStatusView::ClearProfilingResults() { - page_list_.ResetContent(); - current_page_index_ = 0; - - page_text_.SetSelAll(); - page_text_.Clear(); - - page_load_view_->SetPage(NULL); - page_view_container_->GetRootView()->SchedulePaint(); - - if (performance_viewer_.get()) - performance_viewer_->Reset(); -} - -void NetworkStatusView::ReportPagePerformance(int page_index) { - PageLoadTracker* page = performance_viewer_->GetPageReference(page_index); - - page_text_.SetSelAll(); - page_text_.Clear(); - - if (page != NULL) { - std::wstring text; - page->AppendText(&text); - page_text_.AppendText(text.c_str()); - } - - page_load_view_->SetPage(page); - page_view_container_->GetRootView()->SchedulePaint(); -} - //----------------------------------------------------------------------------- // main thread: diff --git a/chrome/browser/network_status_view.h b/chrome/browser/network_status_view.h index a499504..bae43fa 100644 --- a/chrome/browser/network_status_view.h +++ b/chrome/browser/network_status_view.h @@ -26,10 +26,7 @@ class NetworkStatusView : public StatusView { enum { IDC_CONFIG_TRACKING_BUTTON = 101, IDC_CURRENT_STATUS_BUTTON, - IDC_CONFIG_PROFILING_BUTTON, - IDC_SHOW_PERFORMANCE_BUTTON, IDC_CLEAR, - IDC_PAGE_LISTBOX, }; NetworkStatusView(); @@ -46,22 +43,17 @@ class NetworkStatusView : public StatusView { COMMAND_HANDLER_EX(IDC_CONFIG_TRACKING_BUTTON, BN_CLICKED, OnConfigTrackingClicked) COMMAND_HANDLER_EX(IDC_CURRENT_STATUS_BUTTON, BN_CLICKED, OnCurrentStatusClicked) COMMAND_HANDLER_EX(IDC_CLEAR, BN_CLICKED, OnClearClicked) - COMMAND_HANDLER_EX(IDC_CONFIG_PROFILING_BUTTON, BN_CLICKED, OnConfigProfilingClicked) - COMMAND_HANDLER_EX(IDC_SHOW_PERFORMANCE_BUTTON, BN_CLICKED, OnShowPerformanceClicked) - COMMAND_HANDLER_EX(IDC_PAGE_LISTBOX, LBN_DBLCLK, OnPageDoubleClicked) CHAIN_MSG_MAP(StatusView); END_MSG_MAP() bool is_tracking() const { return is_tracking_; } + private: // Event handlers void OnConfigTrackingClicked(UINT code, int button_id, HWND hwnd); void OnCurrentStatusClicked(UINT code, int button_id, HWND hwnd); void OnClearClicked(UINT code, int button_id, HWND hwnd); - void OnConfigProfilingClicked(UINT code, int button_id, HWND hwnd); - void OnShowPerformanceClicked(UINT code, int button_id, HWND hwnd); - void OnPageDoubleClicked(UINT code, int listbox_id, HWND hwnd); void AppendText(const std::wstring& text); @@ -72,16 +64,6 @@ class NetworkStatusView : public StatusView { // Clear tracking output void ClearTrackingResults(); - // Hide/Show profiling output windows - void HideProfilingResults(); - void ShowProfilingResults(); - - // Clear profiling output - void ClearProfilingResults(); - - // Show detailed profiling results for the page with given index. - void ReportPagePerformance(int page_index); - // A JobTracker is allocated to monitor network jobs running on the IO // thread. This allows the NetworkStatusView to remain single-threaded. class JobTracker : public URLRequestJobTracker::JobObserver, @@ -131,29 +113,7 @@ class NetworkStatusView : public StatusView { HFONT monospaced_font_; - // For performance profiling - bool is_profiling_; - int profiling_session_id_; - scoped_ptr<NavigationPerformanceViewer> performance_viewer_; - - // Output of performance profiling - - // List of pages being profiled - CListBox page_list_; - - // Textual report of selected page loading performance - CEdit page_text_; - - // Graphical report of selected page loading performance - PageLoadView* page_load_view_; - // We don't use a scoped_ptr here since the page_view_container_ deletes - // itself when it is destroyed automatically by its parent window. - ChromeViews::HWNDViewContainer* page_view_container_; - - // Current page being selected - int current_page_index_; - - DISALLOW_EVIL_CONSTRUCTORS(NetworkStatusView); + DISALLOW_COPY_AND_ASSIGN(NetworkStatusView); }; #endif // #ifndef CHROME_BROWSER_NETWORK_STATUS_VIEW_H__ diff --git a/chrome/browser/page_load_tracker.cc b/chrome/browser/page_load_tracker.cc deleted file mode 100644 index 56449c281..0000000 --- a/chrome/browser/page_load_tracker.cc +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/page_load_tracker.h" - -#include "base/string_util.h" -#include "chrome/common/gfx/chrome_canvas.h" -#include "chrome/common/gfx/chrome_font.h" -#include "chrome/views/background.h" -#include "net/url_request/url_request_job_metrics.h" - -FrameNavigationMetrics::FrameNavigationMetrics( - PageTransition::Type type, - TimeTicks start_time, - const GURL& url, - int32 page_id) - : type_(type), - start_time_(start_time), - end_time_valid_(false), - url_(url), - page_id_(page_id) { -} - -FrameNavigationMetrics::~FrameNavigationMetrics() { -} - -void FrameNavigationMetrics::AppendText(std::wstring* text) { - DCHECK(text); - text->append(L"frame url = "); - text->append(UTF8ToWide(url().spec())); - - StringAppendF(text, L"; page id = %d; type = %d ", page_id(), type()); - if (PageTransition::IsMainFrame(type())) { - text->append(L"(main frame)"); - } else { - text->append(L"(sub frame)"); - } - - if (end_time_valid()) { - TimeDelta elapsed = end_time() - start_time(); - StringAppendF(text, L"; load time = %lld ms; success.", - elapsed.InMilliseconds()); - } -} - -PageLoadTracker::PageLoadTracker(const GURL& url, - int render_process_host_id, - int routing_id, - TimeTicks start_time) - : url_(url), - render_process_host_id_(render_process_host_id), - routing_id_(routing_id), - start_time_(start_time), - stop_time_set_(false) { -} - -PageLoadTracker::~PageLoadTracker() { - for (PageLoadTracker::FrameMetricsIterator itr = frame_metrics_list_.begin(); - itr != frame_metrics_list_.end(); - ++itr) { - delete (*itr); - } - - for (PageLoadTracker::JobMetricsIterator itr = job_metrics_list_.begin(); - itr != job_metrics_list_.end(); - ++itr) { - delete (*itr); - } -} - -void PageLoadTracker::AddFrameMetrics(FrameNavigationMetrics* frame_metrics) { - if (!frame_metrics) - return; - - frame_metrics_list_.push_back(frame_metrics); -} - -void PageLoadTracker::SetLoadingEndTime(int32 page_id, TimeTicks time) { - for (PageLoadTracker::FrameMetricsIterator itr = frame_metrics_list_.begin(); - itr != frame_metrics_list_.end(); - ++itr) { - // Set end time on main frame - if ((*itr)->page_id() == page_id && - PageTransition::IsMainFrame((*itr)->type())) { - if (!(*itr)->end_time_valid()) { // Only set once - (*itr)->set_end_time(time); - (*itr)->set_end_time_valid(true); - - // If there are multiple main frames, the stop time of the page is the - // time when the last main frame finishes loading. - if (stop_time_set_) { - if (time > stop_time_) { - // Overwrite the stop time previously set - stop_time_ = time; - } - } else { - stop_time_set_ = true; - stop_time_ = time; - } - } - } - } -} - -void PageLoadTracker::AddJobMetrics(URLRequestJobMetrics* job_metrics) { - if (!job_metrics) - return; - - job_metrics_list_.push_back(job_metrics); -} - -void PageLoadTracker::AppendText(std::wstring *text) { - DCHECK(text); - text->append(L"page url = "); - text->append(UTF8ToWide(url_.spec())); - - if (!stop_time_set_) { - text->append(L"; fail."); - } else { - TimeDelta delta = stop_time_ - start_time_; - StringAppendF(text, L"; loading time = %lld ms; success.\r\n\r\n", - delta.InMilliseconds()); - } - - for (PageLoadTracker::FrameMetricsIterator itr = frame_metrics_list_.begin(); - itr != frame_metrics_list_.end(); - ++itr) { - (*itr)->AppendText(text); - text->append(L"\r\n"); - } - - text->append(L"\r\n"); - - for (PageLoadTracker::JobMetricsIterator itr = job_metrics_list_.begin(); - itr != job_metrics_list_.end(); - ++itr) { - (*itr)->AppendText(text); - text->append(L"\r\n"); - } -} - -void PageLoadTracker::Draw(const CRect& bound, ChromeCanvas* canvas) { - if (bound.IsRectEmpty() || !canvas) - return; - - canvas->FillRectInt(SK_ColorWHITE, bound.left, bound.top, - bound.right, bound.bottom); - - int margin = bound.Width() / 40; - int width = bound.Width() - 2 * margin; - - if (!stop_time_set_) { - std::wstring text(L"Loading not completed"); - ChromeFont font; - canvas->DrawStringInt(text, font, SK_ColorRED, margin, 0, width, - bound.Height()); - return; - } - - int num_lines = static_cast<int>(frame_metrics_list_.size() + - job_metrics_list_.size() + 1); - int line_space = bound.Height() / (num_lines + 1); - if (line_space < 1) - line_space = 1; - - // Draw the timeline for page. - int line_x = bound.left + margin; - int line_y = bound.top + line_space; - int line_w = width; - int line_h = 1; - canvas->DrawRectInt(SK_ColorRED, line_x, line_y, line_w, line_h); - - TimeDelta total_time = stop_time() - start_time(); - - // Draw the timelines for frames. - for (PageLoadTracker::FrameMetricsIterator itr = frame_metrics_list_.begin(); - itr != frame_metrics_list_.end(); - ++itr) { - TimeDelta elapsed = (*itr)->start_time() - start_time(); - int64 start_pos = elapsed * width / total_time; - line_x = static_cast<int>(bound.left + margin + start_pos); - line_y = line_y + line_space; - - elapsed = stop_time() - (*itr)->start_time(); - line_w = static_cast<int>(elapsed * width / total_time); - canvas->DrawRectInt(SK_ColorYELLOW, line_x, line_y, line_w, line_h); - } - - // Draw the timelines for jobs. - for (PageLoadTracker::JobMetricsIterator itr = job_metrics_list_.begin(); - itr != job_metrics_list_.end(); - ++itr) { - TimeDelta elapsed = (*itr)->start_time_ - start_time(); - int64 start_pos = elapsed * width / total_time; - line_x = static_cast<int>(bound.left + margin + start_pos); - line_y = line_y + line_space; - - elapsed = (*itr)->end_time_ - (*itr)->start_time_; - line_w = static_cast<int>(elapsed * width / total_time); - canvas->DrawRectInt(SK_ColorBLUE, line_x, line_y, line_w, line_h); - } -} - -PageLoadView::PageLoadView() - : page_(NULL) { - SetBackground( - ChromeViews::Background::CreateSolidBackground(SK_ColorWHITE)); -} - -PageLoadView::~PageLoadView() { -} - -void PageLoadView::Layout() { - CRect parent_bounds; - GetParent()->GetLocalBounds(&parent_bounds, true); - SetBounds(parent_bounds); -} - -void PageLoadView::Paint(ChromeCanvas* canvas) { - PaintBackground(canvas); - if (!page_ || !canvas) - return; - CRect lb; - GetLocalBounds(&lb, true); - // TODO(huanr): PageLoadView should query PageLoadTracker and draw the - // graph. That way we separate data from UI. - page_->Draw(lb, canvas); -} - diff --git a/chrome/browser/page_load_tracker.h b/chrome/browser/page_load_tracker.h deleted file mode 100644 index 05c480a..0000000 --- a/chrome/browser/page_load_tracker.h +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// PageLoadTracker tracks performance related data on page loading. Its lifetime -// and usage are as follows: -// (1) Everytime when render process navigates to a new page, an instance of -// PageLoadTracker is created and hooked into the corresponding WebContents -// object. -// (2) During the page loading, the PageLoadTracker records measurement data -// around major events. For now these include url and time of each frame -// navigation. We may add Java script activity and render process memory usage -// later. But the list will be kept as minimal to reduce the overhead. -// (3) When the page loading stops, the PageLoadTracker is detached from -// WebContents and added to a global list. -// -// See the comments in navigation_profiler.h for an overview of profiling -// architecture. - -#ifndef CHROME_BROWSER_PAGE_LOAD_TRACKER_H_ -#define CHROME_BROWSER_PAGE_LOAD_TRACKER_H_ - -#include <string> -#include <vector> - -#include "base/time.h" -#include "chrome/common/page_transition_types.h" -#include "chrome/views/view.h" -#include "googleurl/src/gurl.h" -#include "testing/gtest/include/gtest/gtest_prod.h" - -class URLRequestJobMetrics; -class ChromeCanvas; - -// Tracks one frame navigation within the page. -class FrameNavigationMetrics { - public: - FrameNavigationMetrics(PageTransition::Type type, - TimeTicks start_time, - const GURL& url, - int32 page_id); - - virtual ~FrameNavigationMetrics(); - - PageTransition::Type type() const { return type_; } - - TimeTicks start_time() const { return start_time_; } - - TimeTicks end_time() const { return end_time_; } - void set_end_time(TimeTicks end_time) { end_time_ = end_time; } - - bool end_time_valid() const { return end_time_valid_; } - void set_end_time_valid(bool valid) { end_time_valid_ = valid; } - - const GURL& url() { return url_; } - - int32 page_id() const { return page_id_; } - - // Append the text report of the frame loading to the input string. - void AppendText(std::wstring* text); - - private: - // The transition type indicates whether this is a main frame or sub frame. - PageTransition::Type type_; - - // Time when the frame navigation starts. - TimeTicks start_time_; - - // Time when the render stops loading the frame. - // Its value is only valid for main frame. - TimeTicks end_time_; - - // True if end_time_ has been set, false otherwise. - // Used to prevent end_time_ from being overwritten if there are multiple - // updates on frame status. - bool end_time_valid_; - - // The URL of the frame. - GURL url_; - - // Page ID of this frame navigation - int32 page_id_; -}; - -class PageLoadTracker { - FRIEND_TEST(PageLoadTrackerUnitTest, AddMetrics); - public: - typedef std::vector<FrameNavigationMetrics*> FrameMetricsVector; - typedef FrameMetricsVector::const_iterator FrameMetricsIterator; - - typedef std::vector<URLRequestJobMetrics*> JobMetricsVector; - typedef JobMetricsVector::const_iterator JobMetricsIterator; - - PageLoadTracker(const GURL& url, int render_process_host_id, int routing_id, - TimeTicks start_time); - - virtual ~PageLoadTracker(); - - // Add a FrameNavigationMetrics entry into the frame list. - // The PageLoadTracker owns this object from now on. - void AddFrameMetrics(FrameNavigationMetrics* frame_metrics); - - // Set the end time of the main frame corresponding to the page_id. - void SetLoadingEndTime(int32 page_id, TimeTicks time); - - // Add a new URLRequestJobMetrics entry into the job data list. - // The PageLoadTracker owns this object from now on. - void AddJobMetrics(URLRequestJobMetrics* job_metrics); - - const GURL& url() const { return url_; } - - int render_process_host_id() const { return render_process_host_id_; } - - int routing_id() const { return routing_id_; } - - TimeTicks start_time() const { return start_time_; } - - TimeTicks stop_time() const { return stop_time_; } - - // Append the text report of the page loading to the input string. - void AppendText(std::wstring* text); - - // Draw the graphic report of the page loading on canvas. - void Draw(const CRect& bound, ChromeCanvas* canvas); - - private: - // List of frames loaded within the page. It may contain multiple main frame - // entries if this page has pop-ups. - FrameMetricsVector frame_metrics_list_; - - // List of IO statistics of URLRequestJob associated with the page - JobMetricsVector job_metrics_list_; - - // URL of the page - GURL url_; - - // The ID of the RenderProcessHost that serves the page - int render_process_host_id_; - - // The listener ID (or the message routing ID) of the TabContents - int routing_id_; - - // Time when the render process navigates to the page. - TimeTicks start_time_; - - // Time when the render process stops loading the page. - TimeTicks stop_time_; - - // True if stop_time_ has been set, false otherwise. - bool stop_time_set_; -}; - -// Graphical view of a page loading -class PageLoadView : public ChromeViews::View { - public: - PageLoadView(); - virtual ~PageLoadView(); - - virtual void Layout(); - virtual void Paint(ChromeCanvas* canvas); - - void SetPage(PageLoadTracker* page) { - page_ = page; - } - - private: - PageLoadTracker* page_; -}; - -#endif // CHROME_BROWSER_PAGE_LOAD_TRACKER_H_ - diff --git a/chrome/browser/page_load_tracker_unittest.cc b/chrome/browser/page_load_tracker_unittest.cc deleted file mode 100644 index 0e8d1d7..0000000 --- a/chrome/browser/page_load_tracker_unittest.cc +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/scoped_ptr.h" -#include "chrome/browser/page_load_tracker.h" -#include "chrome/browser/tab_contents.h" -#include "chrome/browser/tab_util.h" -#include "chrome/browser/web_contents.h" -#include "chrome/common/gfx/chrome_canvas.h" -#include "chrome/views/background.h" -#include "chrome/views/root_view.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_job.h" -#include "net/url_request/url_request_job_metrics.h" - -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -PageLoadTracker* CreateSamplePage(TimeTicks start_time, bool success) { - std::string url_str("www.google.com"); - GURL url(url_str); - - int render_process_host_id = 10; - int routing_id = 10; - - TimeDelta increment = TimeDelta::FromMicroseconds(100); - - PageLoadTracker* page = new PageLoadTracker(url, render_process_host_id, - routing_id, start_time); - - // Add frames - int32 page_id = 1; - FrameNavigationMetrics* frame = - new FrameNavigationMetrics(PageTransition::TYPED, - start_time + increment, - url, - page_id); - page->AddFrameMetrics(frame); - - frame = new FrameNavigationMetrics(PageTransition::AUTO_SUBFRAME, - start_time + 2*increment, - url, - page_id); - page->AddFrameMetrics(frame); - - frame = new FrameNavigationMetrics(PageTransition::AUTO_SUBFRAME, - start_time + 3*increment, - url, - page_id); - page->AddFrameMetrics(frame); - - if (success) { - page->SetLoadingEndTime(page_id, start_time + 4*increment); - } - - // Add JobMetrics - int total_bytes_read = 1000; - int number_of_read_IO = 3; - URLRequestJobMetrics* job = new URLRequestJobMetrics(); - job->total_bytes_read_ = total_bytes_read; - job->number_of_read_IO_ = number_of_read_IO; - job->start_time_ = start_time + TimeDelta::FromMicroseconds(150); - job->end_time_ = start_time + TimeDelta::FromMicroseconds(350); - page->AddJobMetrics(job); - - job = new URLRequestJobMetrics(); - job->total_bytes_read_ = total_bytes_read + 500; - job->number_of_read_IO_ = number_of_read_IO + 2; - job->start_time_ = start_time + TimeDelta::FromMicroseconds(250); - job->end_time_ = start_time + TimeDelta::FromMicroseconds(350); - page->AddJobMetrics(job); - - return page; -} - -class TestView : public ChromeViews::View { - public: - virtual void Paint(ChromeCanvas* canvas) { - CRect lb; - GetLocalBounds(&lb, true); - page_->Draw(lb, canvas); - } - void SetPage(PageLoadTracker* page) { - page_.reset(page); - } - private: - scoped_ptr<PageLoadTracker> page_; -}; - -} // namespace - -TEST(PageLoadTrackerUnitTest, AddMetrics) { - TimeTicks start_time = TimeTicks::Now(); - scoped_ptr<PageLoadTracker> page(CreateSamplePage(start_time, true)); - - // Verify - EXPECT_EQ(3, page->frame_metrics_list_.size()); - EXPECT_EQ(2, page->job_metrics_list_.size()); - EXPECT_TRUE(start_time + TimeDelta::FromMicroseconds(400) - == page->stop_time()); -} - -#if 0 -TEST(PageLoadTrackerUnitTest, ViewFailedPage) { - ChromeViews::Window window; - window.set_delete_on_destroy(false); - window.set_window_style(WS_OVERLAPPEDWINDOW); - window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL, NULL); - ChromeViews::RootView* root = window.GetRootView(); - - TestView* view = new TestView(); - CRect lb; - root->AddChildView(view); - root->GetLocalBounds(&lb); - view->SetBounds(lb); - view->SetPage(CreateSamplePage(20000, false)); - - root->PaintNow(); - - Sleep(1000); - - window.DestroyWindow(); -} - -TEST(PageLoadTrackerUnitTest, ViewSuccessPage) { - ChromeViews::Window window; - window.set_delete_on_destroy(false); - window.set_window_style(WS_OVERLAPPEDWINDOW); - window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL, NULL); - ChromeViews::RootView* root = window.GetRootView(); - - TestView* view = new TestView(); - CRect lb; - root->AddChildView(view); - root->GetLocalBounds(&lb); - view->SetBounds(lb); - view->SetPage(CreateSamplePage(20000, true)); - - root->PaintNow(); - - Sleep(1000); - window.DestroyWindow(); -} -#endif - diff --git a/chrome/browser/resource_dispatcher_host.cc b/chrome/browser/resource_dispatcher_host.cc index 7e57fd4..4b3c5f0 100644 --- a/chrome/browser/resource_dispatcher_host.cc +++ b/chrome/browser/resource_dispatcher_host.cc @@ -17,7 +17,6 @@ #include "chrome/browser/download_manager.h" #include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/login_prompt.h" -#include "chrome/browser/navigation_profiler.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/renderer_security_policy.h" #include "chrome/browser/render_view_host.h" @@ -1352,7 +1351,6 @@ void ResourceDispatcherHost::BeginRequest( request->set_referrer(request_data.referrer.spec()); request->SetExtraRequestHeaders(request_data.headers); request->set_load_flags(request_data.load_flags); - request->set_enable_profiling(g_navigation_profiler.is_profiling()); request->set_context(request_context); request->set_origin_pid(request_data.origin_pid); @@ -1468,7 +1466,6 @@ void ResourceDispatcherHost::BeginDownload(const GURL& url, request->set_method("GET"); request->set_referrer(referrer.spec()); - request->set_enable_profiling(g_navigation_profiler.is_profiling()); request->set_context(request_context); ExtraRequestInfo* extra_info = @@ -1518,7 +1515,6 @@ void ResourceDispatcherHost::BeginSaveFile(const GURL& url, URLRequest* request = new URLRequest(url, this); request->set_method("GET"); request->set_referrer(referrer.spec()); - request->set_enable_profiling(g_navigation_profiler.is_profiling()); // So far, for saving page, we need fetch content from cache, in the // future, maybe we can use a configuration to configure this behavior. request->set_load_flags(net::LOAD_ONLY_FROM_CACHE); diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 0034846..cb22b7e 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -23,8 +23,6 @@ #include "chrome/browser/load_notification_details.h" #include "chrome/browser/modal_html_dialog_delegate.h" #include "chrome/browser/navigation_entry.h" -#include "chrome/browser/navigation_profiler.h" -#include "chrome/browser/page_load_tracker.h" #include "chrome/browser/password_manager.h" #include "chrome/browser/plugin_installer.h" #include "chrome/browser/plugin_service.h" @@ -198,7 +196,6 @@ WebContents::WebContents(Profile* profile, #pragma warning(suppress: 4355) // Okay to pass "this" here. render_manager_(render_view_factory, this, this), render_view_factory_(render_view_factory), - is_profiling_(false), has_page_title_(false), info_bar_visible_(false), is_starred_(false), @@ -496,42 +493,6 @@ void WebContents::OnSetFocus(HWND window) { } } -NavigationProfiler* WebContents::GetNavigationProfiler() { - return &g_navigation_profiler; -} - -bool WebContents::EnableProfiling() { - NavigationProfiler* profiler = GetNavigationProfiler(); - is_profiling_ = profiler->is_profiling(); - - return is_profiling(); -} - -void WebContents::SaveCurrentProfilingEntry() { - if (is_profiling()) { - NavigationProfiler* profiler = GetNavigationProfiler(); - profiler->MoveActivePageToVisited(process()->host_id(), - render_view_host()->routing_id()); - } - is_profiling_ = false; -} - -void WebContents::CreateNewProfilingEntry(const GURL& url) { - SaveCurrentProfilingEntry(); - - // Check new profiling status. - if (EnableProfiling()) { - NavigationProfiler* profiler = GetNavigationProfiler(); - TimeTicks current_time = TimeTicks::Now(); - - PageLoadTracker *page = new PageLoadTracker( - url, process()->host_id(), render_view_host()->routing_id(), - current_time); - - profiler->AddActivePage(page); - } -} - void WebContents::OnSavePage() { // If we can not save the page, try to download it. if (!SavePackage::IsSavableContents(contents_mime_type())) { @@ -612,8 +573,6 @@ void WebContents::SavePage(const std::wstring& main_file, bool WebContents::Navigate(const NavigationEntry& entry, bool reload) { RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); - CreateNewProfilingEntry(entry.GetURL()); - // Used for page load time metrics. current_load_start_ = TimeTicks::Now(); @@ -1451,9 +1410,6 @@ void WebContents::DidNavigateAnyFramePreCommit( } } - // Reset timing data and log. - HandleProfilingForDidNavigate(params); - // Notify the password manager of the navigation or form submit. if (params.password_form.origin.is_valid()) GetPasswordManager()->ProvisionallySavePassword(params.password_form); @@ -1512,32 +1468,6 @@ void WebContents::WebAppImagesChanged(WebApp* web_app) { delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_FAVICON); } -void WebContents::HandleProfilingForDidNavigate( - const ViewHostMsg_FrameNavigate_Params& params) { - PageTransition::Type stripped_transition_type = - PageTransition::StripQualifier(params.transition); - if (stripped_transition_type == PageTransition::LINK || - stripped_transition_type == PageTransition::FORM_SUBMIT) { - CreateNewProfilingEntry(params.url); - } - - current_load_start_ = TimeTicks::Now(); - - if (is_profiling()) { - NavigationProfiler* profiler = GetNavigationProfiler(); - - FrameNavigationMetrics* frame = - new FrameNavigationMetrics(PageTransition::FromInt(params.transition), - current_load_start_, - params.url, - params.page_id); - - profiler->AddFrameMetrics(process()->host_id(), - render_view_host()->routing_id(), - frame); - } -} - void WebContents::BroadcastProvisionalLoadCommit( RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params) { @@ -1751,18 +1681,7 @@ void WebContents::DidStartLoading(RenderViewHost* rvh, int32 page_id) { } void WebContents::DidStopLoading(RenderViewHost* rvh, int32 page_id) { - TimeTicks current_time = TimeTicks::Now(); - if (is_profiling()) { - NavigationProfiler* profiler = GetNavigationProfiler(); - - profiler->SetLoadingEndTime(process()->host_id(), - render_view_host()->routing_id(), page_id, - current_time); - SaveCurrentProfilingEntry(); - } - scoped_ptr<LoadNotificationDetails> details; - if (controller()) { NavigationEntry* entry = controller()->GetActiveEntry(); if (entry) { @@ -1770,7 +1689,7 @@ void WebContents::DidStopLoading(RenderViewHost* rvh, int32 page_id) { process_util::ProcessMetrics::CreateProcessMetrics( process()->process())); - TimeDelta elapsed = current_time - current_load_start_; + TimeDelta elapsed = TimeTicks::Now() - current_load_start_; details.reset(new LoadNotificationDetails( entry->GetDisplayURL(), diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index eb7502f..fb9eaf5 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -19,7 +19,6 @@ class FindInPageController; class InterstitialPageDelegate; -class NavigationProfiler; class PasswordManager; class PluginInstaller; class RenderViewHost; @@ -101,9 +100,6 @@ class WebContents : public TabContents, // Default is not to block any message boxes. void SetSuppressJavascriptMessageBoxes(bool suppress_javascript_messages); - // Return true if the WebContents is doing performance profiling - bool is_profiling() const { return is_profiling_; } - // Various other systems need to know about our interstitials. bool showing_interstitial_page() const { return render_manager_.showing_interstitial_page(); @@ -112,14 +108,6 @@ class WebContents : public TabContents, return render_manager_.showing_repost_interstitial(); } - // Check with the global navigation profiler on whether to enable - // profiling. Return true if profiling needs to be enabled, return - // false otherwise. - bool EnableProfiling(); - - // Return the global navigation profiler. - NavigationProfiler* GetNavigationProfiler(); - // Overridden from TabContents to remember at what time the download bar was // shown. void SetDownloadShelfVisible(bool visible); @@ -664,21 +652,9 @@ class WebContents : public TabContents, virtual NavigationController* GetControllerForRenderManager() { return controller(); } - - // Profiling ----------------------------------------------------------------- - - // Logs the commit of the load for profiling purposes. Used by DidNavigate. - void HandleProfilingForDidNavigate( - const ViewHostMsg_FrameNavigate_Params& params); - - // If performance profiling is enabled, save current PageLoadTracker entry - // to visited page list. - void SaveCurrentProfilingEntry(); - - // If performance profiling is enabled, create a new PageLoadTracker entry - // when navigating to a new page. - void CreateNewProfilingEntry(const GURL& url); + // --------------------------------------------------------------------------- + // Enumerate and 'un-parent' any plugin windows that are children // of this web contents. void DetachPluginWindows(); @@ -709,9 +685,6 @@ class WebContents : public TabContents, typedef std::map<HistoryService::Handle, int32> HistoryRequestMap; HistoryRequestMap history_requests_; - // Whether the WebContents is doing performance profiling - bool is_profiling_; - // System time at which the current load was started. TimeTicks current_load_start_; diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index ee496de..c84a572 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -515,18 +515,6 @@ </File> </Filter> <Filter - Name="TestPerformanceProfiler" - > - <File - RelativePath="..\..\browser\navigation_profiler_unittest.cc" - > - </File> - <File - RelativePath="..\..\browser\page_load_tracker_unittest.cc" - > - </File> - </Filter> - <Filter Name="TestNavigationController" > <File |