| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // A clock that increments every access. Great for testing. | 83 // A clock that increments every access. Great for testing. |
| 84 class TestingClock : public Database::Clock { | 84 class TestingClock : public Database::Clock { |
| 85 public: | 85 public: |
| 86 TestingClock() | 86 TestingClock() |
| 87 : counter_(0) { | 87 : counter_(0) { |
| 88 } | 88 } |
| 89 explicit TestingClock(const TestingClock& other) | 89 explicit TestingClock(const TestingClock& other) |
| 90 : counter_(other.counter_) { | 90 : counter_(other.counter_) { |
| 91 } | 91 } |
| 92 virtual ~TestingClock() {} | 92 virtual ~TestingClock() {} |
| 93 base::Time GetTime() { | 93 virtual base::Time GetTime() OVERRIDE { |
| 94 return base::Time::FromInternalValue(++counter_); | 94 return base::Time::FromInternalValue(++counter_); |
| 95 } | 95 } |
| 96 private: | 96 private: |
| 97 int64 counter_; | 97 int64 counter_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class PerformanceMonitorDatabaseEventTest : public ::testing::Test { | 100 class PerformanceMonitorDatabaseEventTest : public ::testing::Test { |
| 101 protected: | 101 protected: |
| 102 PerformanceMonitorDatabaseEventTest() { | 102 PerformanceMonitorDatabaseEventTest() { |
| 103 clock_ = new TestingClock(); | 103 clock_ = new TestingClock(); |
| 104 CHECK(temp_dir_.CreateUniqueTempDir()); | 104 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 105 db_ = Database::Create(temp_dir_.path()); | 105 db_ = Database::Create(temp_dir_.path()); |
| 106 CHECK(db_.get()); | 106 CHECK(db_.get()); |
| 107 db_->set_clock(scoped_ptr<Database::Clock>(clock_)); | 107 db_->set_clock(scoped_ptr<Database::Clock>(clock_)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void SetUp() { | 110 virtual void SetUp() { |
| 111 ASSERT_TRUE(db_.get()); | 111 ASSERT_TRUE(db_.get()); |
| 112 PopulateDB(); | 112 PopulateDB(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void PopulateDB() { | 115 void PopulateDB() { |
| 116 InitEvents(); | 116 InitEvents(); |
| 117 db_->AddEvent(*install_event_1_.get()); | 117 db_->AddEvent(*install_event_1_.get()); |
| 118 db_->AddEvent(*install_event_2_.get()); | 118 db_->AddEvent(*install_event_2_.get()); |
| 119 db_->AddEvent(*uninstall_event_1_.get()); | 119 db_->AddEvent(*uninstall_event_1_.get()); |
| 120 db_->AddEvent(*uninstall_event_2_.get()); | 120 db_->AddEvent(*uninstall_event_2_.get()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 protected: | 153 protected: |
| 154 PerformanceMonitorDatabaseMetricTest() { | 154 PerformanceMonitorDatabaseMetricTest() { |
| 155 clock_ = new TestingClock(); | 155 clock_ = new TestingClock(); |
| 156 CHECK(temp_dir_.CreateUniqueTempDir()); | 156 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 157 db_ = Database::Create(temp_dir_.path()); | 157 db_ = Database::Create(temp_dir_.path()); |
| 158 CHECK(db_.get()); | 158 CHECK(db_.get()); |
| 159 db_->set_clock(scoped_ptr<Database::Clock>(clock_)); | 159 db_->set_clock(scoped_ptr<Database::Clock>(clock_)); |
| 160 activity_ = std::string("A"); | 160 activity_ = std::string("A"); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void SetUp() { | 163 virtual void SetUp() { |
| 164 ASSERT_TRUE(db_.get()); | 164 ASSERT_TRUE(db_.get()); |
| 165 PopulateDB(); | 165 PopulateDB(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void PopulateDB() { | 168 void PopulateDB() { |
| 169 db_->AddMetric(kProcessChromeAggregate, | 169 db_->AddMetric(kProcessChromeAggregate, |
| 170 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 50.5)); | 170 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 50.5)); |
| 171 db_->AddMetric(activity_, | 171 db_->AddMetric(activity_, |
| 172 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 13.1)); | 172 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 13.1)); |
| 173 db_->AddMetric(kProcessChromeAggregate, | 173 db_->AddMetric(kProcessChromeAggregate, |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 db_->AddMetric(kProcessChromeAggregate, | 526 db_->AddMetric(kProcessChromeAggregate, |
| 527 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0)); | 527 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0)); |
| 528 Database::MetricVector stats = | 528 Database::MetricVector stats = |
| 529 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); | 529 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); |
| 530 ASSERT_EQ(2u, stats.size()); | 530 ASSERT_EQ(2u, stats.size()); |
| 531 ASSERT_EQ(3, stats[0].value); | 531 ASSERT_EQ(3, stats[0].value); |
| 532 ASSERT_EQ(9, stats[1].value); | 532 ASSERT_EQ(9, stats[1].value); |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace performance_monitor | 535 } // namespace performance_monitor |
| OLD | NEW |