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

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor_browsertest.cc

Issue 10829342: Add BytesRead metric to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Requested changes Created 8 years, 4 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
44 #include "base/mac/scoped_nsautorelease_pool.h" 44 #include "base/mac/scoped_nsautorelease_pool.h"
45 #endif 45 #endif
46 46
47 using extensions::Extension; 47 using extensions::Extension;
48 using performance_monitor::Event; 48 using performance_monitor::Event;
49 49
50 namespace { 50 namespace {
51 51
52 const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3); 52 const base::TimeDelta kMaxStartupTime = base::TimeDelta::FromMinutes(3);
53 const char kSimplePage1[] = "title1.html";
54 const char kSimplePage2[] = "title2.html";
53 55
54 // Helper struct to store the information of an extension; this is needed if the 56 // Helper struct to store the information of an extension; this is needed if the
55 // pointer to the extension ever becomes invalid (e.g., if we uninstall the 57 // pointer to the extension ever becomes invalid (e.g., if we uninstall the
56 // extension). 58 // extension).
57 struct ExtensionBasicInfo { 59 struct ExtensionBasicInfo {
58 // Empty constructor for stl-container-happiness. 60 // Empty constructor for stl-container-happiness.
59 ExtensionBasicInfo() { 61 ExtensionBasicInfo() {
60 } 62 }
61 explicit ExtensionBasicInfo(const Extension* extension) 63 explicit ExtensionBasicInfo(const Extension* extension)
62 : description(extension->description()), 64 : description(extension->description()),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 CheckEventTypes(expected_event_types, events); 131 CheckEventTypes(expected_event_types, events);
130 132
131 for (size_t i = 0; i < expected_event_types.size(); ++i) { 133 for (size_t i = 0; i < expected_event_types.size(); ++i) {
132 ValidateExtensionInfo(extension_infos[i], events[i]->data()); 134 ValidateExtensionInfo(extension_infos[i], events[i]->data());
133 int event_type; 135 int event_type;
134 ASSERT_TRUE(events[i]->data()->GetInteger("eventType", &event_type)); 136 ASSERT_TRUE(events[i]->data()->GetInteger("eventType", &event_type));
135 ASSERT_EQ(expected_event_types[i], event_type); 137 ASSERT_EQ(expected_event_types[i], event_type);
136 } 138 }
137 } 139 }
138 140
141 // A wrapper for file_util::GetFileSize which takes an ASCII path relative to
142 // chrome::DIR_TEST_DATA.
143 bool GetFileSize(const std::string& relative_path, int64* size) {
144 FilePath test_dir;
145 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
146
147 return file_util::GetFileSize(test_dir.AppendASCII(relative_path), size);
148 }
149
139 } // namespace 150 } // namespace
140 151
141 namespace performance_monitor { 152 namespace performance_monitor {
142 153
143 class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { 154 class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
144 public: 155 public:
145 virtual void SetUpOnMainThread() OVERRIDE { 156 virtual void SetUpOnMainThread() OVERRIDE {
146 CHECK(db_dir_.CreateUniqueTempDir()); 157 CHECK(db_dir_.CreateUniqueTempDir());
147 performance_monitor_ = PerformanceMonitor::GetInstance(); 158 performance_monitor_ = PerformanceMonitor::GetInstance();
148 performance_monitor_->SetDatabasePath(db_dir_.path()); 159 performance_monitor_->SetDatabasePath(db_dir_.path());
149 160
150 // PerformanceMonitor's initialization process involves a significant 161 // PerformanceMonitor's initialization process involves a significant
151 // amount of thread-hopping between the UI thread and the background thread. 162 // amount of thread-hopping between the UI thread and the background thread.
152 // If we begin the tests prior to full initialization, we cannot predict 163 // If we begin the tests prior to full initialization, we cannot predict
153 // the behavior or mock synchronicity as we must. Wait for initialization 164 // the behavior or mock synchronicity as we must. Wait for initialization
154 // to complete fully before proceeding with the test. 165 // to complete fully before proceeding with the test.
155 content::WindowedNotificationObserver windowed_observer( 166 content::WindowedNotificationObserver windowed_observer(
156 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, 167 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
157 content::NotificationService::AllSources()); 168 content::NotificationService::AllSources());
158 169
159 performance_monitor_->Start(); 170 performance_monitor_->Start();
160 171
161 windowed_observer.Wait(); 172 windowed_observer.Wait();
173
174 // We stop the timer in charge of doing timed collections so that we can
175 // enforce when, and how many times, we do these collections.
176 performance_monitor_->timer_.Stop();
162 } 177 }
163 178
164 // A handle for gathering statistics from the database, which must be done on 179 // A handle for gathering statistics from the database, which must be done on
165 // the background thread. Since we are testing, we can mock synchronicity with 180 // the background thread. Since we are testing, we can mock synchronicity with
166 // FlushForTesting(). 181 // FlushForTesting().
167 void GatherStatistics() { 182 void GatherStatistics() {
168 content::BrowserThread::PostBlockingPoolSequencedTask( 183 content::BrowserThread::PostBlockingPoolSequencedTask(
169 Database::kDatabaseSequenceToken, 184 Database::kDatabaseSequenceToken,
170 FROM_HERE, 185 FROM_HERE,
171 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread, 186 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 575
561 stats = GetStats(METRIC_SHARED_MEMORY_USAGE); 576 stats = GetStats(METRIC_SHARED_MEMORY_USAGE);
562 ASSERT_EQ(1u, stats.size()); 577 ASSERT_EQ(1u, stats.size());
563 EXPECT_GT(stats[0].value, 0); 578 EXPECT_GT(stats[0].value, 0);
564 579
565 // Open new tabs to incur CPU usage. 580 // Open new tabs to incur CPU usage.
566 for (int i = 0; i < 10; ++i) { 581 for (int i = 0; i < 10; ++i) {
567 chrome::NavigateParams params( 582 chrome::NavigateParams params(
568 browser(), 583 browser(),
569 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 584 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
570 FilePath(FILE_PATH_LITERAL("title1.html"))), 585 FilePath(FILE_PATH_LITERAL(kSimplePage1))),
571 content::PAGE_TRANSITION_LINK); 586 content::PAGE_TRANSITION_LINK);
572 params.disposition = NEW_BACKGROUND_TAB; 587 params.disposition = NEW_BACKGROUND_TAB;
573 ui_test_utils::NavigateToURL(&params); 588 ui_test_utils::NavigateToURL(&params);
574 } 589 }
575 GatherStatistics(); 590 GatherStatistics();
576 591
577 // One CPUUsage stat should exist now. 592 // One CPUUsage stat should exist now.
578 stats = GetStats(METRIC_CPU_USAGE); 593 stats = GetStats(METRIC_CPU_USAGE);
579 ASSERT_EQ(1u, stats.size()); 594 ASSERT_EQ(1u, stats.size());
580 EXPECT_GT(stats[0].value, 0); 595 EXPECT_GT(stats[0].value, 0);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 696
682 ASSERT_EQ(1u, metrics.size()); 697 ASSERT_EQ(1u, metrics.size());
683 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); 698 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue());
684 } 699 }
685 700
686 IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest, 701 IN_PROC_BROWSER_TEST_F(PerformanceMonitorSessionRestoreBrowserTest,
687 StartupWithSessionRestore) { 702 StartupWithSessionRestore) {
688 ui_test_utils::NavigateToURL( 703 ui_test_utils::NavigateToURL(
689 browser(), 704 browser(),
690 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 705 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
691 FilePath(FILE_PATH_LITERAL("title1.html")))); 706 FilePath(FILE_PATH_LITERAL(kSimplePage1))));
692 707
693 QuitBrowserAndRestore(browser(), 1); 708 QuitBrowserAndRestore(browser(), 1);
694 709
695 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME); 710 Database::MetricInfoVector metrics = GetStats(METRIC_TEST_STARTUP_TIME);
696 ASSERT_EQ(1u, metrics.size()); 711 ASSERT_EQ(1u, metrics.size());
697 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); 712 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue());
698 713
699 metrics = GetStats(METRIC_SESSION_RESTORE_TIME); 714 metrics = GetStats(METRIC_SESSION_RESTORE_TIME);
700 ASSERT_EQ(1u, metrics.size()); 715 ASSERT_EQ(1u, metrics.size());
701 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue()); 716 ASSERT_LT(metrics[0].value, kMaxStartupTime.ToInternalValue());
702 } 717 }
703 718
704 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) { 719 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, PageLoadTime) {
705 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30); 720 const base::TimeDelta kMaxLoadTime = base::TimeDelta::FromSeconds(30);
706 721
707 ui_test_utils::NavigateToURL( 722 ui_test_utils::NavigateToURL(
708 browser(), 723 browser(),
709 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 724 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
710 FilePath(FILE_PATH_LITERAL("title1.html")))); 725 FilePath(FILE_PATH_LITERAL(kSimplePage1))));
711 726
712 ui_test_utils::NavigateToURL( 727 ui_test_utils::NavigateToURL(
713 browser(), 728 browser(),
714 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 729 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
715 FilePath(FILE_PATH_LITERAL("title2.html")))); 730 FilePath(FILE_PATH_LITERAL(kSimplePage1))));
716 731
717 Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME); 732 Database::MetricInfoVector metrics = GetStats(METRIC_PAGE_LOAD_TIME);
718 733
719 ASSERT_EQ(2u, metrics.size()); 734 ASSERT_EQ(2u, metrics.size());
720 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue()); 735 ASSERT_LT(metrics[0].value, kMaxLoadTime.ToInternalValue());
721 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue()); 736 ASSERT_LT(metrics[1].value, kMaxLoadTime.ToInternalValue());
722 } 737 }
723 738
739 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NetworkBytesRead) {
740 int64 page1_size = 0;
741 ASSERT_TRUE(GetFileSize(kSimplePage1, &page1_size));
742
743 int64 page2_size = 0;
744 ASSERT_TRUE(GetFileSize(kSimplePage2, &page2_size));
745
746 ASSERT_TRUE(test_server()->Start());
747
748 ui_test_utils::NavigateToURL(
749 browser(),
750 test_server()->GetURL(std::string("files/").append(kSimplePage1)));
751
752 performance_monitor()->DoTimedCollections();
753
754 // Since network bytes are read and set on the IO thread, we must flush this
755 // additional thread to be sure that all messages are run.
756 RunAllPendingInMessageLoop(content::BrowserThread::IO);
757
758 Database::MetricInfoVector metrics = GetStats(METRIC_NETWORK_BYTES_READ);
759 ASSERT_EQ(1u, metrics.size());
760 // Since these pages are read over the "network" (actually the test_server),
761 // some extraneous information is carried along, and the best check we can do
762 // is for greater than or equal to.
763 ASSERT_GE(metrics[0].value, page1_size);
battre 2012/08/22 20:50:24 I think this should be EXPECT_GE (not the ASSERT_E
Devlin 2012/08/23 16:41:02 Done.
764
765 ui_test_utils::NavigateToURL(
766 browser(),
767 test_server()->GetURL(std::string("files/").append(kSimplePage2)));
768
769 performance_monitor()->DoTimedCollections();
770
771 metrics = GetStats(METRIC_NETWORK_BYTES_READ);
772 ASSERT_EQ(2u, metrics.size());
773 ASSERT_GE(metrics[1].value, page1_size + page2_size);
battre 2012/08/22 20:50:24 I think this should be EXPECT_GE
Devlin 2012/08/23 16:41:02 Done.
774 }
775
724 } // namespace performance_monitor 776 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698