OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/browser/performance_monitor/constants.h" | 11 #include "chrome/browser/performance_monitor/constants.h" |
12 #include "chrome/browser/performance_monitor/database.h" | 12 #include "chrome/browser/performance_monitor/database.h" |
13 #include "chrome/browser/performance_monitor/performance_monitor.h" | 13 #include "chrome/browser/performance_monitor/performance_monitor.h" |
14 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/unpacked_installer.h" | 16 #include "chrome/browser/extensions/unpacked_installer.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
26 | 27 |
27 using extensions::Extension; | 28 using extensions::Extension; |
28 using performance_monitor::Event; | 29 using performance_monitor::Event; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 Database::kDatabaseSequenceToken, | 134 Database::kDatabaseSequenceToken, |
134 FROM_HERE, | 135 FROM_HERE, |
135 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, | 136 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, |
136 base::Unretained(this), | 137 base::Unretained(this), |
137 &events)); | 138 &events)); |
138 | 139 |
139 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 140 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
140 return events; | 141 return events; |
141 } | 142 } |
142 | 143 |
144 void GetStatsForActivityAndMetricOnBackgroundThread( | |
145 const std::string& activity, | |
146 const std::string& metric, | |
147 Database::MetricInfoVector* stats) { | |
148 *stats = performance_monitor_->database()-> | |
149 GetStatsForActivityAndMetric(activity, metric); | |
150 } | |
151 | |
152 Database::MetricInfoVector GetStatsForActivityAndMetric( | |
153 const std::string& activity, | |
154 const std::string& metric) { | |
155 Database::MetricInfoVector stats; | |
156 content::BrowserThread::PostBlockingPoolSequencedTask( | |
157 Database::kDatabaseSequenceToken, | |
158 FROM_HERE, | |
159 base::Bind(&PerformanceMonitorBrowserTest:: | |
160 GetStatsForActivityAndMetricOnBackgroundThread, | |
161 base::Unretained(this), | |
162 activity, | |
163 metric, | |
164 &stats)); | |
165 | |
166 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
167 return stats; | |
168 } | |
169 | |
143 PerformanceMonitor* performance_monitor() const { | 170 PerformanceMonitor* performance_monitor() const { |
144 return performance_monitor_; | 171 return performance_monitor_; |
145 } | 172 } |
146 | 173 |
147 protected: | 174 protected: |
148 ScopedTempDir db_dir_; | 175 ScopedTempDir db_dir_; |
149 PerformanceMonitor* performance_monitor_; | 176 PerformanceMonitor* performance_monitor_; |
150 }; | 177 }; |
151 | 178 |
152 // Test that PerformanceMonitor will correctly record an extension installation | 179 // Test that PerformanceMonitor will correctly record an extension installation |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 342 |
316 std::string previous_version; | 343 std::string previous_version; |
317 std::string current_version; | 344 std::string current_version; |
318 | 345 |
319 ASSERT_TRUE(value->GetString("previous_version", &previous_version)); | 346 ASSERT_TRUE(value->GetString("previous_version", &previous_version)); |
320 ASSERT_EQ(kOldVersion, previous_version); | 347 ASSERT_EQ(kOldVersion, previous_version); |
321 ASSERT_TRUE(value->GetString("current_version", ¤t_version)); | 348 ASSERT_TRUE(value->GetString("current_version", ¤t_version)); |
322 ASSERT_EQ(version_string, current_version); | 349 ASSERT_EQ(version_string, current_version); |
323 } | 350 } |
324 | 351 |
352 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) { | |
353 content::BrowserThread::PostBlockingPoolSequencedTask( | |
354 Database::kDatabaseSequenceToken, | |
355 FROM_HERE, | |
356 base::Bind(&PerformanceMonitor::GatherStatistics, | |
357 base::Unretained(performance_monitor()))); | |
358 | |
359 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
360 | |
361 // CPU Usage -- no stats recorded the first time | |
362 Database::MetricInfoVector stats = GetStatsForActivityAndMetric( | |
363 performance_monitor::kProcessChromeAggregate, | |
364 performance_monitor::kMetricCPUUsage); | |
365 ASSERT_EQ(0u, stats.size()); | |
366 | |
367 // Private memory usage | |
368 stats = GetStatsForActivityAndMetric( | |
369 performance_monitor::kProcessChromeAggregate, | |
370 performance_monitor::kMetricPrivateMemoryUsage); | |
371 ASSERT_EQ(1u, stats.size()); | |
372 LOG(INFO) << "Private memory usage median: " << stats[0].value; | |
373 | |
374 // Shared memory usage | |
375 stats = GetStatsForActivityAndMetric( | |
376 performance_monitor::kProcessChromeAggregate, | |
377 performance_monitor::kMetricSharedMemoryUsage); | |
378 ASSERT_EQ(1u, stats.size()); | |
379 LOG(INFO) << "Shared memory usage median: " << stats[0].value; | |
380 | |
381 // TODO(mwrosen) something less barbaric? | |
382 // Spin for a while, so CPU usage isn't 0 | |
Yoyo Zhou
2012/07/09 21:33:36
Why is this necessary? Could CPU usage be 0 in the
mitchellwrosen
2012/07/09 22:45:23
Yeah, the CPU usage could be zero in the real worl
Yoyo Zhou
2012/07/10 21:58:00
Well, the LOG(INFO) also suggests that these are t
| |
383 for (int i = 0; i < 1000000000; ++i) { | |
Yoyo Zhou
2012/07/09 21:33:36
I'd be careful with something like this... a compi
mitchellwrosen
2012/07/09 22:45:23
Done.
| |
384 } | |
385 | |
386 content::BrowserThread::PostBlockingPoolSequencedTask( | |
387 Database::kDatabaseSequenceToken, | |
388 FROM_HERE, | |
389 base::Bind(&PerformanceMonitor::GatherStatistics, | |
390 base::Unretained(performance_monitor()))); | |
391 | |
392 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
393 | |
394 stats = GetStatsForActivityAndMetric( | |
395 performance_monitor::kProcessChromeAggregate, | |
396 performance_monitor::kMetricCPUUsage); | |
397 ASSERT_EQ(1u, stats.size()); | |
398 EXPECT_GT(stats[0].value, 0); | |
399 LOG(INFO) << "CPU usage median: " << stats[0].value; | |
400 | |
401 // Private memory usage #2 | |
402 stats = GetStatsForActivityAndMetric( | |
403 performance_monitor::kProcessChromeAggregate, | |
404 performance_monitor::kMetricPrivateMemoryUsage); | |
405 ASSERT_EQ(2u, stats.size()); | |
406 LOG(INFO) << "Private memory usage median #2: " << stats[1].value; | |
407 | |
408 // Shared memory usage #2 | |
409 stats = GetStatsForActivityAndMetric( | |
410 performance_monitor::kProcessChromeAggregate, | |
411 performance_monitor::kMetricSharedMemoryUsage); | |
412 ASSERT_EQ(2u, stats.size()); | |
413 LOG(INFO) << "Shared memory usage median #2: " << stats[1].value; | |
414 } | |
415 | |
325 } // namespace performance_monitor | 416 } // namespace performance_monitor |
OLD | NEW |