CPM Page Load timing

Add metric recording in CPM for how long it takes to load a page.

BUG=130212
TEST=included browsertest


Review URL: https://chromiumcodereview.appspot.com/10829078

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151197 0039d316-1c4b-4281-b951-d872f2087c98
parent 345c042d
...@@ -58,6 +58,13 @@ const char kMetricSessionRestoreTimeDescription[] = ...@@ -58,6 +58,13 @@ const char kMetricSessionRestoreTimeDescription[] =
const char kMetricSessionRestoreTimeUnits[] = "microseconds"; const char kMetricSessionRestoreTimeUnits[] = "microseconds";
const double kMetricSessionRestoreTimeTickSize = 5000000; const double kMetricSessionRestoreTimeTickSize = 5000000;
// Page Load Time
const char kMetricPageLoadTimeName[] = "Page Load Time";
const char kMetricPageLoadTimeDescription[] =
"The amount of time taken to load a page measured in microseconds.";
const char kMetricPageLoadTimeUnits[] = "microseconds";
const double kMetricPageLoadTimeTickSize = 30000000.0;
// Keep this array synced with MetricTypes in the header file. // Keep this array synced with MetricTypes in the header file.
// TODO(mtytel): i18n. // TODO(mtytel): i18n.
const MetricDetails kMetricDetailsList[] = { const MetricDetails kMetricDetailsList[] = {
...@@ -96,6 +103,12 @@ const MetricDetails kMetricDetailsList[] = { ...@@ -96,6 +103,12 @@ const MetricDetails kMetricDetailsList[] = {
kMetricSessionRestoreTimeDescription, kMetricSessionRestoreTimeDescription,
kMetricSessionRestoreTimeUnits, kMetricSessionRestoreTimeUnits,
kMetricSessionRestoreTimeTickSize kMetricSessionRestoreTimeTickSize
},
{
kMetricPageLoadTimeName,
kMetricPageLoadTimeDescription,
kMetricPageLoadTimeUnits,
kMetricPageLoadTimeTickSize
} }
}; };
COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kMetricDetailsList) == METRIC_NUMBER_OF_METRICS, COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kMetricDetailsList) == METRIC_NUMBER_OF_METRICS,
......
...@@ -17,6 +17,7 @@ enum MetricType { ...@@ -17,6 +17,7 @@ enum MetricType {
METRIC_STARTUP_TIME, METRIC_STARTUP_TIME,
METRIC_TEST_STARTUP_TIME, METRIC_TEST_STARTUP_TIME,
METRIC_SESSION_RESTORE_TIME, METRIC_SESSION_RESTORE_TIME,
METRIC_PAGE_LOAD_TIME,
METRIC_NUMBER_OF_METRICS METRIC_NUMBER_OF_METRICS
}; };
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "chrome/test/base/chrome_process_util.h" #include "chrome/test/base/chrome_process_util.h"
#include "content/public/browser/browser_child_process_host.h" #include "content/public/browser/browser_child_process_host.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/load_notification_details.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -146,6 +147,10 @@ void PerformanceMonitor::RegisterForNotifications() { ...@@ -146,6 +147,10 @@ void PerformanceMonitor::RegisterForNotifications() {
// Profiles (for unclean exit) // Profiles (for unclean exit)
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
// Page load times
registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
} }
// We check if profiles exited cleanly initialization time in case they were // We check if profiles exited cleanly initialization time in case they were
...@@ -228,6 +233,12 @@ void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { ...@@ -228,6 +233,12 @@ void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) {
database_->AddEvent(*event.get()); database_->AddEvent(*event.get());
} }
void PerformanceMonitor::AddMetricOnBackgroundThread(MetricType type,
const std::string& value) {
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
database_->AddMetric(type, value);
}
void PerformanceMonitor::NotifyInitialized() { void PerformanceMonitor::NotifyInitialized() {
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
...@@ -419,6 +430,21 @@ void PerformanceMonitor::Observe(int type, ...@@ -419,6 +430,21 @@ void PerformanceMonitor::Observe(int type,
} }
break; break;
} }
case content::NOTIFICATION_LOAD_STOP: {
const content::LoadNotificationDetails* load_details =
content::Details<content::LoadNotificationDetails>(details).ptr();
if (!load_details)
break;
BrowserThread::PostBlockingPoolSequencedTask(
Database::kDatabaseSequenceToken,
FROM_HERE,
base::Bind(
&PerformanceMonitor::AddMetricOnBackgroundThread,
base::Unretained(this),
METRIC_PAGE_LOAD_TIME,
base::Int64ToString(load_details->load_time.ToInternalValue())));
break;
}
default: { default: {
NOTREACHED(); NOTREACHED();
break; break;
......
...@@ -99,6 +99,10 @@ class PerformanceMonitor : public content::NotificationObserver { ...@@ -99,6 +99,10 @@ class PerformanceMonitor : public content::NotificationObserver {
void AddEventOnBackgroundThread(scoped_ptr<Event> event); void AddEventOnBackgroundThread(scoped_ptr<Event> event);
// Since Database::AddMetric() is overloaded, base::Bind() does not work and
// we need a helper function.
void AddMetricOnBackgroundThread(MetricType type, const std::string& value);
// Notify any listeners that PerformanceMonitor has finished the initializing. // Notify any listeners that PerformanceMonitor has finished the initializing.
void NotifyInitialized(); void NotifyInitialized();
......
...@@ -701,4 +701,24 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, ...@@ -701,4 +701,24 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest,
ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue());
} }
IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) {
const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30);
ui_test_utils::NavigateToURL(
browser(),
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(FILE_PATH_LITERAL("title1.html"))));
ui_test_utils::NavigateToURL(
browser(),
ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(FILE_PATH_LITERAL("title2.html"))));
Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME);
ASSERT_EQ(2u, metrics.size());
ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue());
ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue());
}
} // namespace performance_monitor } // namespace performance_monitor
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment