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

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: Changes per comments 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;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 Database::kDatabaseSequenceToken, 125 Database::kDatabaseSequenceToken,
125 FROM_HERE, 126 FROM_HERE,
126 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread, 127 base::Bind(&PerformanceMonitorBrowserTest::GetEventsOnBackgroundThread,
127 base::Unretained(this), 128 base::Unretained(this),
128 &events)); 129 &events));
129 130
130 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 131 content::BrowserThread::GetBlockingPool()->FlushForTesting();
131 return events; 132 return events;
132 } 133 }
133 134
135 void GetStatsForActivityAndMetricOnBackgroundThread(
Devlin 2012/07/11 16:28:08 Add function documentation.
mitchellwrosen 2012/07/11 18:30:18 Done.
136 const std::string& activity,
137 const std::string& metric,
138 Database::MetricInfoVector* stats) {
139 *stats = performance_monitor_->database()->
140 GetStatsForActivityAndMetric(activity, metric);
141 }
142
143 Database::MetricInfoVector GetStatsForActivityAndMetric(
144 const std::string& activity,
145 const std::string& metric) {
146 Database::MetricInfoVector stats;
147 content::BrowserThread::PostBlockingPoolSequencedTask(
148 Database::kDatabaseSequenceToken,
149 FROM_HERE,
150 base::Bind(&PerformanceMonitorBrowserTest::
151 GetStatsForActivityAndMetricOnBackgroundThread,
152 base::Unretained(this),
153 activity,
154 metric,
155 &stats));
156
157 content::BrowserThread::GetBlockingPool()->FlushForTesting();
158 return stats;
159 }
160
134 PerformanceMonitor* performance_monitor() const { 161 PerformanceMonitor* performance_monitor() const {
135 return performance_monitor_; 162 return performance_monitor_;
136 } 163 }
137 164
138 protected: 165 protected:
139 ScopedTempDir db_dir_; 166 ScopedTempDir db_dir_;
140 PerformanceMonitor* performance_monitor_; 167 PerformanceMonitor* performance_monitor_;
141 }; 168 };
142 169
143 // Test that PerformanceMonitor will correctly record an extension installation 170 // Test that PerformanceMonitor will correctly record an extension installation
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 337
311 std::string previous_version; 338 std::string previous_version;
312 std::string current_version; 339 std::string current_version;
313 340
314 ASSERT_TRUE(value->GetString("previousVersion", &previous_version)); 341 ASSERT_TRUE(value->GetString("previousVersion", &previous_version));
315 ASSERT_EQ(kOldVersion, previous_version); 342 ASSERT_EQ(kOldVersion, previous_version);
316 ASSERT_TRUE(value->GetString("currentVersion", &current_version)); 343 ASSERT_TRUE(value->GetString("currentVersion", &current_version));
317 ASSERT_EQ(version_string, current_version); 344 ASSERT_EQ(version_string, current_version);
318 } 345 }
319 346
347 IN_PROC_BROWSER_TEST_F(PerformanceMonitorBrowserTest, GatherStatistics) {
348 content::BrowserThread::PostBlockingPoolSequencedTask(
349 Database::kDatabaseSequenceToken,
350 FROM_HERE,
351 base::Bind(&PerformanceMonitor::GatherStatistics,
352 base::Unretained(performance_monitor())));
353
354 content::BrowserThread::GetBlockingPool()->FlushForTesting();
355
356 // CPU Usage -- no stats recorded the first time
357 Database::MetricInfoVector stats = GetStatsForActivityAndMetric(
358 performance_monitor::kProcessChromeAggregate,
359 performance_monitor::kMetricCPUUsage);
360 ASSERT_EQ(0u, stats.size());
361
362 // Private memory usage
363 stats = GetStatsForActivityAndMetric(
364 performance_monitor::kProcessChromeAggregate,
365 performance_monitor::kMetricPrivateMemoryUsage);
366 ASSERT_EQ(1u, stats.size());
367 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.
368
369 // Shared memory usage
370 stats = GetStatsForActivityAndMetric(
371 performance_monitor::kProcessChromeAggregate,
372 performance_monitor::kMetricSharedMemoryUsage);
373 ASSERT_EQ(1u, stats.size());
374 LOG(INFO) << "Shared memory usage median: " << stats[0].value;
375
376 // 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
377 // Spin for a while, so CPU usage isn't 0
378 int i = 0;
379 for (; i < 1000000000; ++i) {
380 }
381 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.
382
383 content::BrowserThread::PostBlockingPoolSequencedTask(
384 Database::kDatabaseSequenceToken,
385 FROM_HERE,
386 base::Bind(&PerformanceMonitor::GatherStatistics,
387 base::Unretained(performance_monitor())));
388
389 content::BrowserThread::GetBlockingPool()->FlushForTesting();
390
391 stats = GetStatsForActivityAndMetric(
392 performance_monitor::kProcessChromeAggregate,
393 performance_monitor::kMetricCPUUsage);
394 ASSERT_EQ(1u, stats.size());
395 EXPECT_GT(stats[0].value, 0);
396 LOG(INFO) << "CPU usage median: " << stats[0].value;
397
398 // Private memory usage #2
399 stats = GetStatsForActivityAndMetric(
400 performance_monitor::kProcessChromeAggregate,
401 performance_monitor::kMetricPrivateMemoryUsage);
402 ASSERT_EQ(2u, stats.size());
403 LOG(INFO) << "Private memory usage median #2: " << stats[1].value;
404
405 // Shared memory usage #2
406 stats = GetStatsForActivityAndMetric(
407 performance_monitor::kProcessChromeAggregate,
408 performance_monitor::kMetricSharedMemoryUsage);
409 ASSERT_EQ(2u, stats.size());
410 LOG(INFO) << "Shared memory usage median #2: " << stats[1].value;
411 }
412
320 } // namespace performance_monitor 413 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698