| 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 dedcf9993e4fd27b8d1541d3c8675194f044e98f..4ed40ba31249e517b6229151cdac93f6d1d14281 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/browser/ui/browser_tabstrip.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/chrome_paths.h"
|
| @@ -30,6 +31,10 @@ using extensions::Extension;
|
| using performance_monitor::Event;
|
|
|
| namespace {
|
| +
|
| +// Used in PerformanceMonitorBrowserTest.GatherStatistics to consume CPU cycles.
|
| +int kSpinCount = 1000000000;
|
| +
|
| // Helper struct to store the information of an extension; this is needed if the
|
| // pointer to the extension ever becomes invalid (e.g., if we uninstall the
|
| // extension).
|
| @@ -171,6 +176,34 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
|
| return events;
|
| }
|
|
|
| + // Retrieves stats from the database, given |activity| and |metric|. Does the
|
| + // retrieval on a background thread.
|
| + 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;
|
| + }
|
| +
|
| + void GetStatsForActivityAndMetricOnBackgroundThread(
|
| + const std::string& activity,
|
| + const std::string& metric,
|
| + Database::MetricInfoVector* stats) {
|
| + *stats = performance_monitor_->database()->
|
| + GetStatsForActivityAndMetric(activity, metric);
|
| + }
|
| +
|
| // A handle for inserting a state value into the database, which must be done
|
| // on the background thread. This is useful for mocking up a scenario in which
|
| // the database has prior data stored. We mock synchronicity with
|
| @@ -395,6 +428,71 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) {
|
| ASSERT_EQ(version_string, current_version);
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) {
|
| + content::BrowserThread::PostBlockingPoolSequencedTask(
|
| + Database::kDatabaseSequenceToken,
|
| + FROM_HERE,
|
| + base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
|
| + 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());
|
| + EXPECT_GT(stats[0].value, 0);
|
| +
|
| + // Shared memory usage
|
| + stats = GetStatsForActivityAndMetric(
|
| + performance_monitor::kProcessChromeAggregate,
|
| + performance_monitor::kMetricSharedMemoryUsage);
|
| + ASSERT_EQ(1u, stats.size());
|
| + EXPECT_GT(stats[0].value, 0);
|
| +
|
| + // TODO(mwrosen) something less barbaric?
|
| + // Spin for a while, so CPU usage isn't 0.
|
| + int i = 0;
|
| + for (; i < kSpinCount; ++i) {
|
| + }
|
| + ASSERT_EQ(kSpinCount, i);
|
| +
|
| + content::BrowserThread::PostBlockingPoolSequencedTask(
|
| + Database::kDatabaseSequenceToken,
|
| + FROM_HERE,
|
| + base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
|
| + 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);
|
| +
|
| + // Private memory usage #2
|
| + stats = GetStatsForActivityAndMetric(
|
| + performance_monitor::kProcessChromeAggregate,
|
| + performance_monitor::kMetricPrivateMemoryUsage);
|
| + ASSERT_EQ(2u, stats.size());
|
| + EXPECT_GT(stats[1].value, 0);
|
| +
|
| + // Shared memory usage #2
|
| + stats = GetStatsForActivityAndMetric(
|
| + performance_monitor::kProcessChromeAggregate,
|
| + performance_monitor::kMetricSharedMemoryUsage);
|
| + ASSERT_EQ(2u, stats.size());
|
| + EXPECT_GT(stats[1].value, 0);
|
| +}
|
| +
|
| #if !defined(OS_WIN)
|
| // Disabled on Windows due to a bug where Windows will return a normal exit
|
| // code in the testing environment, even if the process died (this is not the
|
|
|