OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 db_->GetActiveMetrics(base::Time(), clock_->GetTime()); | 278 db_->GetActiveMetrics(base::Time(), clock_->GetTime()); |
279 std::sort(active_metrics.begin(), active_metrics.end()); | 279 std::sort(active_metrics.begin(), active_metrics.end()); |
280 | 280 |
281 std::vector<const MetricDetails*> expected_metrics; | 281 std::vector<const MetricDetails*> expected_metrics; |
282 expected_metrics.push_back(GetMetricDetails(METRIC_CPU_USAGE)); | 282 expected_metrics.push_back(GetMetricDetails(METRIC_CPU_USAGE)); |
283 expected_metrics.push_back(GetMetricDetails(METRIC_PRIVATE_MEMORY_USAGE)); | 283 expected_metrics.push_back(GetMetricDetails(METRIC_PRIVATE_MEMORY_USAGE)); |
284 std::sort(expected_metrics.begin(), expected_metrics.end()); | 284 std::sort(expected_metrics.begin(), expected_metrics.end()); |
285 EXPECT_EQ(expected_metrics, active_metrics); | 285 EXPECT_EQ(expected_metrics, active_metrics); |
286 } | 286 } |
287 | 287 |
| 288 TEST_F(PerformanceMonitorDatabaseMetricTest, GetRecentMetric) { |
| 289 MetricInfo stat; |
| 290 ASSERT_TRUE(db_->GetRecentStatsForActivityAndMetric(activity_, |
| 291 METRIC_PRIVATE_MEMORY_USAGE, &stat)); |
| 292 EXPECT_EQ(3000000, stat.value); |
| 293 |
| 294 ASSERT_TRUE(db_->GetRecentStatsForActivityAndMetric(METRIC_CPU_USAGE, &stat)); |
| 295 EXPECT_EQ(50.5, stat.value); |
| 296 |
| 297 ScopedTempDir dir; |
| 298 CHECK(dir.CreateUniqueTempDir()); |
| 299 scoped_ptr<Database> db = Database::Create(dir.path()); |
| 300 CHECK(db.get()); |
| 301 db->set_clock(scoped_ptr<Database::Clock>(new TestingClock())); |
| 302 EXPECT_FALSE(db->GetRecentStatsForActivityAndMetric(METRIC_CPU_USAGE, &stat)); |
| 303 } |
| 304 |
288 TEST_F(PerformanceMonitorDatabaseMetricTest, GetState) { | 305 TEST_F(PerformanceMonitorDatabaseMetricTest, GetState) { |
289 std::string key("version"); | 306 std::string key("version"); |
290 std::string value("1.0.0.0.1"); | 307 std::string value("1.0.0.0.1"); |
291 db_->AddStateValue(key, value); | 308 db_->AddStateValue(key, value); |
292 EXPECT_EQ(db_->GetStateValue(key), value); | 309 EXPECT_EQ(db_->GetStateValue(key), value); |
293 } | 310 } |
294 | 311 |
295 TEST_F(PerformanceMonitorDatabaseMetricTest, GetStateOverride) { | 312 TEST_F(PerformanceMonitorDatabaseMetricTest, GetStateOverride) { |
296 std::string key("version"); | 313 std::string key("version"); |
297 std::string value_1("1.0.0.0.0"); | 314 std::string value_1("1.0.0.0.0"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 base::Time end = clock_->GetTime(); | 383 base::Time end = clock_->GetTime(); |
367 db_->AddMetric(kProcessChromeAggregate, METRIC_CPU_USAGE, std::string("21")); | 384 db_->AddMetric(kProcessChromeAggregate, METRIC_CPU_USAGE, std::string("21")); |
368 Database::MetricInfoVector stats = | 385 Database::MetricInfoVector stats = |
369 db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); | 386 db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); |
370 ASSERT_EQ(2u, stats.size()); | 387 ASSERT_EQ(2u, stats.size()); |
371 ASSERT_EQ(3, stats[0].value); | 388 ASSERT_EQ(3, stats[0].value); |
372 ASSERT_EQ(9, stats[1].value); | 389 ASSERT_EQ(9, stats[1].value); |
373 } | 390 } |
374 | 391 |
375 } // namespace performance_monitor | 392 } // namespace performance_monitor |
OLD | NEW |