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

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 + separation for disk/network reads 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
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("title2.html"))));
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, DiskBytesRead) {
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 ui_test_utils::NavigateToURL(
747 browser(),
748 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
749 FilePath(FILE_PATH_LITERAL(kSimplePage1))));
750 performance_monitor()->DoTimedCollections();
751
752 Database::MetricInfoVector metrics = GetStats(METRIC_DISK_BYTES_READ);
753 ASSERT_EQ(1u, metrics.size());
754 ASSERT_EQ(page1_size, metrics[0].value);
755
756 ui_test_utils::NavigateToURL(
757 browser(),
758 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
759 FilePath(FILE_PATH_LITERAL(kSimplePage2))));
760 performance_monitor()->DoTimedCollections();
761
762 metrics = GetStats(METRIC_DISK_BYTES_READ);
763 ASSERT_EQ(2u, metrics.size());
764 ASSERT_EQ(page1_size + page2_size, metrics[1].value);
765 }
766
767 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NetworkBytesRead) {
768 int64 page1_size = 0;
769 ASSERT_TRUE(GetFileSize(kSimplePage1, &page1_size));
770
771 int64 page2_size = 0;
772 ASSERT_TRUE(GetFileSize(kSimplePage2, &page2_size));
773
774 ASSERT_TRUE(test_server()->Start());
775
776 ui_test_utils::NavigateToURL(
777 browser(),
778 test_server()->GetURL(std::string("files/").append(kSimplePage1)));
779
780 performance_monitor()->DoTimedCollections();
781
782 Database::MetricInfoVector metrics = GetStats(METRIC_NETWORK_BYTES_READ);
783 ASSERT_EQ(1u, metrics.size());
784 // Since these pages are read over the "network" (actually the test_server),
785 // some extraneous information is carried along, and the best check we can do
786 // is for greater than or equal to.
787 ASSERT_GE(metrics[0].value, page1_size);
788
789 ui_test_utils::NavigateToURL(
790 browser(),
791 test_server()->GetURL(std::string("files/").append(kSimplePage2)));
792
793 performance_monitor()->DoTimedCollections();
794
795 metrics = GetStats(METRIC_NETWORK_BYTES_READ);
796 ASSERT_EQ(2u, metrics.size());
797 ASSERT_GE(metrics[1].value, page1_size + page2_size);
798 }
799
724 } // namespace performance_monitor 800 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698