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

Unified Diff: chrome/browser/performance_monitor/performance_monitor_browsertest.cc

Issue 10656052: Performance monitor stats gathering. (Closed) Base URL: http://git.chromium.org/chromium/src.git@cpm_main
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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 512c397a34bd08981c26f8bbe67ce83ae3148f9d..464188a9d38b0b4002b1714172a288f2ad78d45f 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"
Devlin 2012/07/31 17:05:13 Sort.
mitchellwrosen 2012/07/31 17:15:36 Done.
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
@@ -31,6 +32,7 @@ using extensions::Extension;
using performance_monitor::Event;
namespace {
+
// 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).
@@ -141,6 +143,16 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
windowed_observer.Wait();
}
+ void GatherStatistics() {
Devlin 2012/07/31 17:05:13 Document.
mitchellwrosen 2012/07/31 17:15:36 Done.
+ content::BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
+ base::Unretained(performance_monitor())));
+
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ }
+
void GetEventsOnBackgroundThread(std::vector<linked_ptr<Event> >* events) {
// base::Time is potentially flaky in that there is no guarantee that it
// won't actually decrease between successive calls. If we call GetEvents
@@ -172,6 +184,31 @@ class PerformanceMonitorBrowserTest : public ExtensionBrowserTest {
return events;
}
+ void GetStatsOnBackgroundThread(Database::MetricInfoVector* metrics,
+ MetricType type) {
+ *metrics = performance_monitor_->database()->GetStatsForActivityAndMetric(
+ type, base::Time(), base::Time::FromInternalValue(kint64max));
+ }
+
+ // A handle for getting statistics from the database (see previous comments on
+ // GetEvents() and GetEventsOnBackgroundThread).
+ Database::MetricInfoVector GetStats(MetricType type) {
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ Database::MetricInfoVector metrics;
+ content::BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitorBrowserTest::GetStatsOnBackgroundThread,
+ base::Unretained(this),
+ &metrics,
+ type));
+
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ return metrics;
+ }
+
// 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
@@ -396,6 +433,52 @@ IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, NewVersionEvent) {
ASSERT_EQ(version_string, current_version);
}
+IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) {
+ const int kSpinCount = 1000000000;
Devlin 2012/07/31 17:05:13 This one's my fault - you're supposed to put this
mitchellwrosen 2012/07/31 17:15:36 Done.
+
+ GatherStatistics();
+
+ // Gather CPU usage. No stats should be recorded because this was the first
+ // call to GatherStatistics.
+ Database::MetricInfoVector stats = GetStats(METRIC_CPU_USAGE);
+ ASSERT_EQ(0u, stats.size());
+
+ // Gather private memory usage.
+ stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE);
+ ASSERT_EQ(1u, stats.size());
+ EXPECT_GT(stats[0].value, 0);
+
+ // Gather shared memory usage.
+ stats = GetStats(METRIC_SHARED_MEMORY_USAGE);
+ ASSERT_EQ(1u, stats.size());
+ EXPECT_GT(stats[0].value, 0);
+
+ // Spin for a while, so CPU usage isn't 0.
+ int i = 0;
+ for (; i < kSpinCount; ++i) {
+ }
+ ASSERT_EQ(kSpinCount, i);
+
+ GatherStatistics();
+
+ // Gather CPU usage a second time and verify a stat was recorded.
+ stats = GetStats(METRIC_CPU_USAGE);
+ ASSERT_EQ(1u, stats.size());
+ EXPECT_GT(stats[0].value, 0);
+
+ // Gather private memory usage a second time and verify a second stat was
+ // recorded.
+ stats = GetStats(METRIC_PRIVATE_MEMORY_USAGE);
+ ASSERT_EQ(2u, stats.size());
+ EXPECT_GT(stats[1].value, 0);
+
+ // Gather shared memory usage a second time and verify a second stat was
+ // recorded.
+ stats = GetStats(METRIC_SHARED_MEMORY_USAGE);
+ 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

Powered by Google App Engine
This is Rietveld 408576698