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

Side by Side 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: Numero 3 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 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 "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;
29 30
30 namespace { 31 namespace {
31 32
33 // Used in PerformanceMonitorBrowserTest.GatherStatistics to consume CPU cycles.
34 int kSpinCount = 1000000000;
35
32 // Helper struct to store the information of an extension; this is needed if the 36 // Helper struct to store the information of an extension; this is needed if the
33 // pointer to the extension ever becomes invalid (e.g., if we uninstall the 37 // pointer to the extension ever becomes invalid (e.g., if we uninstall the
34 // extension). 38 // extension).
35 struct ExtensionBasicInfo { 39 struct ExtensionBasicInfo {
36 // Empty constructor for stl-container-happiness. 40 // Empty constructor for stl-container-happiness.
37 ExtensionBasicInfo() { 41 ExtensionBasicInfo() {
38 } 42 }
39 explicit ExtensionBasicInfo(const Extension* extension) 43 explicit ExtensionBasicInfo(const Extension* extension)
40 : description(extension->description()), 44 : description(extension->description()),
41 id(extension->id()), 45 id(extension->id()),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 Database::kDatabaseSequenceToken, 128 Database::kDatabaseSequenceToken,
125 FROM_HERE, 129 FROM_HERE,
126 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, 130 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread,
127 base::Unretained(this), 131 base::Unretained(this),
128 &events)); 132 &events));
129 133
130 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 134 content::BrowserThread::GetBlockingPool()->FlushForTesting();
131 return events; 135 return events;
132 } 136 }
133 137
138 // Retrieves stats from the database, given |activity| and |metric|. Does the
139 // retrieval on a background thread.
140 Database::MetricInfoVector GetStatsForActivityAndMetric(
141 const std::string& activity,
142 const std::string& metric) {
143 Database::MetricInfoVector stats;
144 content::BrowserThread::PostBlockingPoolSequencedTask(
145 Database::kDatabaseSequenceToken,
146 FROM_HERE,
147 base::Bind(&PerformanceMonitorBrowserTest::
148 GetStatsForActivityAndMetricOnBackgroundThread,
149 base::Unretained(this),
150 activity,
151 metric,
152 &stats));
153
154 content::BrowserThread::GetBlockingPool()->FlushForTesting();
155 return stats;
156 }
157
158 void GetStatsForActivityAndMetricOnBackgroundThread(
159 const std::string& activity,
160 const std::string& metric,
161 Database::MetricInfoVector* stats) {
162 *stats = performance_monitor_->database()->
163 GetStatsForActivityAndMetric(activity, metric);
164 }
165
134 PerformanceMonitor* performance_monitor() const { 166 PerformanceMonitor* performance_monitor() const {
135 return performance_monitor_; 167 return performance_monitor_;
136 } 168 }
137 169
138 protected: 170 protected:
139 ScopedTempDir db_dir_; 171 ScopedTempDir db_dir_;
140 PerformanceMonitor* performance_monitor_; 172 PerformanceMonitor* performance_monitor_;
141 }; 173 };
142 174
143 // Test that PerformanceMonitor will correctly record an extension installation 175 // Test that PerformanceMonitor will correctly record an extension installation
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 342
311 std::string previous_version; 343 std::string previous_version;
312 std::string current_version; 344 std::string current_version;
313 345
314 ASSERT_TRUE(value->GetString("previousVersion", &previous_version)); 346 ASSERT_TRUE(value->GetString("previousVersion", &previous_version));
315 ASSERT_EQ(kOldVersion, previous_version); 347 ASSERT_EQ(kOldVersion, previous_version);
316 ASSERT_TRUE(value->GetString("currentVersion", &current_version)); 348 ASSERT_TRUE(value->GetString("currentVersion", &current_version));
317 ASSERT_EQ(version_string, current_version); 349 ASSERT_EQ(version_string, current_version);
318 } 350 }
319 351
352 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) {
353 content::BrowserThread::PostBlockingPoolSequencedTask(
354 Database::kDatabaseSequenceToken,
355 FROM_HERE,
356 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
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 EXPECT_GT(stats[0].value, 0);
373
374 // Shared memory usage
375 stats = GetStatsForActivityAndMetric(
376 performance_monitor::kProcessChromeAggregate,
377 performance_monitor::kMetricSharedMemoryUsage);
378 ASSERT_EQ(1u, stats.size());
379 EXPECT_GT(stats[0].value, 0);
380
381 // TODO(mwrosen) something less barbaric?
382 // Spin for a while, so CPU usage isn't 0
Devlin 2012/07/17 18:07:58 add a period.
mitchellwrosen 2012/07/20 19:42:36 Done.
383 int i = 0;
384 for (; i < kSpinCount; ++i) {
385 }
386 ASSERT_EQ(kSpinCount, i);
Devlin 2012/07/17 18:07:58 Is this just testing that a for-loop runs? If so,
mitchellwrosen 2012/07/20 19:42:36 See yoz's previous comment
387
388 content::BrowserThread::PostBlockingPoolSequencedTask(
389 Database::kDatabaseSequenceToken,
390 FROM_HERE,
391 base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
392 base::Unretained(performance_monitor())));
393
394 content::BrowserThread::GetBlockingPool()->FlushForTesting();
395
396 stats = GetStatsForActivityAndMetric(
397 performance_monitor::kProcessChromeAggregate,
398 performance_monitor::kMetricCPUUsage);
399 ASSERT_EQ(1u, stats.size());
400 EXPECT_GT(stats[0].value, 0);
401
402 // Private memory usage #2
403 stats = GetStatsForActivityAndMetric(
404 performance_monitor::kProcessChromeAggregate,
405 performance_monitor::kMetricPrivateMemoryUsage);
406 ASSERT_EQ(2u, stats.size());
407 EXPECT_GT(stats[1].value, 0);
408
409 // Shared memory usage #2
410 stats = GetStatsForActivityAndMetric(
411 performance_monitor::kProcessChromeAggregate,
412 performance_monitor::kMetricSharedMemoryUsage);
413 ASSERT_EQ(2u, stats.size());
414 EXPECT_GT(stats[1].value, 0);
415 }
416
320 } // namespace performance_monitor 417 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698