Chromium Code Reviews| Index: chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
| diff --git a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
| index 9867d1cd517adb44676ff79a1313605d6f43c2d3..96fa3f34d42b46afae8681da5189971f8756ac73 100644 |
| --- a/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
| +++ b/chrome/browser/performance_monitor/performance_monitor_browsertest.cc |
| @@ -16,6 +16,7 @@ |
| #include "chrome/browser/extensions/unpacked_installer.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_version_info.h" |
| @@ -131,6 +132,32 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest { |
| return events; |
| } |
| + void GetStatsForActivityAndMetricOnBackgroundThread( |
|
Devlin
2012/07/11 16:28:08
Add function documentation.
mitchellwrosen
2012/07/11 18:30:18
Done.
|
| + const std::string& activity, |
| + const std::string& metric, |
| + Database::MetricInfoVector* stats) { |
| + *stats = performance_monitor_->database()-> |
| + GetStatsForActivityAndMetric(activity, metric); |
| + } |
| + |
| + Database::MetricInfoVector GetStatsForActivityAndMetric( |
| + const std::string& activity, |
| + const std::string& metric) { |
| + Database::MetricInfoVector stats; |
| + content::BrowserThread::PostBlockingPoolSequencedTask( |
| + Database::kDatabaseSequenceToken, |
| + FROM_HERE, |
| + base::Bind(&PerformanceMonitorBrowserTest:: |
| + GetStatsForActivityAndMetricOnBackgroundThread, |
| + base::Unretained(this), |
| + activity, |
| + metric, |
| + &stats)); |
| + |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + return stats; |
| + } |
| + |
| PerformanceMonitor* performance_monitor() const { |
| return performance_monitor_; |
| } |
| @@ -317,4 +344,70 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, MAYBE_NewVersionEvent) { |
| ASSERT_EQ(version_string, current_version); |
| } |
| +IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) { |
| + content::BrowserThread::PostBlockingPoolSequencedTask( |
| + Database::kDatabaseSequenceToken, |
| + FROM_HERE, |
| + base::Bind(&PerformanceMonitor::GatherStatistics, |
| + base::Unretained(performance_monitor()))); |
| + |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + |
| + // CPU Usage -- no stats recorded the first time |
| + Database::MetricInfoVector stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricCPUUsage); |
| + ASSERT_EQ(0u, stats.size()); |
| + |
| + // Private memory usage |
| + stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricPrivateMemoryUsage); |
| + ASSERT_EQ(1u, stats.size()); |
| + LOG(INFO) << "Private memory usage median: " << stats[0].value; |
|
Devlin
2012/07/11 16:28:08
Remove debugging LOGs.
mitchellwrosen
2012/07/11 18:30:18
Done.
|
| + |
| + // Shared memory usage |
| + stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricSharedMemoryUsage); |
| + ASSERT_EQ(1u, stats.size()); |
| + LOG(INFO) << "Shared memory usage median: " << stats[0].value; |
| + |
| + // TODO(mwrosen) something less barbaric? |
|
Devlin
2012/07/11 16:28:08
hmmm...check out base::? base::PlatformThread::Sle
mitchellwrosen
2012/07/11 18:30:18
Sleeping doesn't consume CPU. OneShotTimer is awkw
|
| + // Spin for a while, so CPU usage isn't 0 |
| + int i = 0; |
| + for (; i < 1000000000; ++i) { |
| + } |
| + ASSERT_EQ(1000000000, i); |
|
Devlin
2012/07/11 16:28:08
If this stays in here, you should define this to b
mitchellwrosen
2012/07/11 18:30:18
Done.
|
| + |
| + content::BrowserThread::PostBlockingPoolSequencedTask( |
| + Database::kDatabaseSequenceToken, |
| + FROM_HERE, |
| + base::Bind(&PerformanceMonitor::GatherStatistics, |
| + base::Unretained(performance_monitor()))); |
| + |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + |
| + stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricCPUUsage); |
| + ASSERT_EQ(1u, stats.size()); |
| + EXPECT_GT(stats[0].value, 0); |
| + LOG(INFO) << "CPU usage median: " << stats[0].value; |
| + |
| + // Private memory usage #2 |
| + stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricPrivateMemoryUsage); |
| + ASSERT_EQ(2u, stats.size()); |
| + LOG(INFO) << "Private memory usage median #2: " << stats[1].value; |
| + |
| + // Shared memory usage #2 |
| + stats = GetStatsForActivityAndMetric( |
| + performance_monitor::kProcessChromeAggregate, |
| + performance_monitor::kMetricSharedMemoryUsage); |
| + ASSERT_EQ(2u, stats.size()); |
| + LOG(INFO) << "Shared memory usage median #2: " << stats[1].value; |
| +} |
| + |
| } // namespace performance_monitor |