Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / performance_monitor / database_unittest.cc
blobdd4b01210facffa02a78b77ff955a6920e5b3dd2
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
3 // found in the LICENSE file.
5 #include <algorithm>
6 #include <string>
7 #include <vector>
9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/performance_monitor/database.h"
14 #include "chrome/browser/performance_monitor/key_builder.h"
15 #include "chrome/browser/performance_monitor/metric.h"
16 #include "chrome/browser/performance_monitor/performance_monitor_util.h"
17 #include "extensions/common/extension.h"
18 #include "extensions/common/manifest.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/leveldatabase/src/include/leveldb/db.h"
21 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
23 using extensions::Extension;
24 using extensions::Manifest;
26 namespace performance_monitor {
28 // A class which is friended by Database, in order to hold the private methods
29 // and avoid friending all the different test classes.
30 class DatabaseTestHelper {
31 public:
32 explicit DatabaseTestHelper(Database* database) : database_(database) { }
33 ~DatabaseTestHelper() { }
35 bool Close() { return database_->Close(); }
37 // Override the check for a metric's validity and insert it in the database.
38 // Note: This does not do extraneous updates, like updating the recent_db or
39 // the max_value_map.
40 bool AddInvalidMetric(std::string activity, Metric metric) {
41 std::string metric_key =
42 database_->key_builder_->CreateMetricKey(database_->clock_->GetTime(),
43 metric.type,
44 activity);
45 leveldb::Status status =
46 database_->metric_db_->Put(database_->write_options_,
47 metric_key,
48 metric.ValueAsString());
49 return status.ok();
52 // Writes an invalid event to the database; since events are stored as JSON
53 // strings, this is equivalent to writing a garbage string.
54 bool AddInvalidEvent(base::Time time, EventType type) {
55 std::string key = database_->key_builder_->CreateEventKey(time, type);
56 leveldb::Status status =
57 database_->event_db_->Put(database_->write_options_, key, "fake_event");
58 return status.ok();
61 size_t GetNumberOfMetricEntries() {
62 return GetNumberOfEntries(database_->metric_db_.get());
64 size_t GetNumberOfEventEntries() {
65 return GetNumberOfEntries(database_->event_db_.get());
68 private:
69 // Returns the number of entries in a given database.
70 size_t GetNumberOfEntries(leveldb::DB* level_db) {
71 size_t number_of_entries = 0;
72 scoped_ptr<leveldb::Iterator> iter(
73 level_db->NewIterator(database_->read_options_));
74 for (iter->SeekToFirst(); iter->Valid(); iter->Next())
75 ++number_of_entries;
76 return number_of_entries;
79 Database* database_;
82 // A clock that increments every access. Great for testing.
83 class TestingClock : public Database::Clock {
84 public:
85 TestingClock()
86 : counter_(0) {
88 explicit TestingClock(const TestingClock& other)
89 : counter_(other.counter_) {
91 virtual ~TestingClock() {}
92 virtual base::Time GetTime() OVERRIDE {
93 return base::Time::FromInternalValue(++counter_);
95 private:
96 int64 counter_;
99 class PerformanceMonitorDatabaseEventTest : public ::testing::Test {
100 protected:
101 PerformanceMonitorDatabaseEventTest() {
102 clock_ = new TestingClock();
103 CHECK(temp_dir_.CreateUniqueTempDir());
104 db_ = Database::Create(temp_dir_.path());
105 CHECK(db_.get());
106 db_->set_clock(scoped_ptr<Database::Clock>(clock_));
109 virtual void SetUp() {
110 ASSERT_TRUE(db_.get());
111 PopulateDB();
114 void PopulateDB() {
115 InitEvents();
116 db_->AddEvent(*install_event_1_.get());
117 db_->AddEvent(*install_event_2_.get());
118 db_->AddEvent(*uninstall_event_1_.get());
119 db_->AddEvent(*uninstall_event_2_.get());
122 scoped_ptr<Database> db_;
123 Database::Clock* clock_;
124 base::ScopedTempDir temp_dir_;
125 scoped_ptr<Event> install_event_1_;
126 scoped_ptr<Event> install_event_2_;
127 scoped_ptr<Event> uninstall_event_1_;
128 scoped_ptr<Event> uninstall_event_2_;
130 private:
131 void InitEvents() {
132 install_event_1_ = util::CreateExtensionEvent(
133 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "a", "extension 1",
134 "http://foo.com", static_cast<int>(Manifest::UNPACKED), "0.1",
135 "Test Test");
136 install_event_2_ = util::CreateExtensionEvent(
137 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "b", "extension 2",
138 "http://bar.com", static_cast<int>(Manifest::UNPACKED), "0.1",
139 "Test Test");
140 uninstall_event_1_ = util::CreateExtensionEvent(
141 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "a", "extension 1",
142 "http://foo.com", static_cast<int>(Manifest::UNPACKED), "0.1",
143 "Test Test");
144 uninstall_event_2_ = util::CreateExtensionEvent(
145 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "b", "extension 2",
146 "http://bar.com", static_cast<int>(Manifest::UNPACKED), "0.1",
147 "Test Test");
151 class PerformanceMonitorDatabaseMetricTest : public ::testing::Test {
152 protected:
153 PerformanceMonitorDatabaseMetricTest() {
154 clock_ = new TestingClock();
155 CHECK(temp_dir_.CreateUniqueTempDir());
156 db_ = Database::Create(temp_dir_.path());
157 CHECK(db_.get());
158 db_->set_clock(scoped_ptr<Database::Clock>(clock_));
159 activity_ = std::string("A");
162 virtual void SetUp() {
163 ASSERT_TRUE(db_.get());
164 PopulateDB();
167 void PopulateDB() {
168 db_->AddMetric(kProcessChromeAggregate,
169 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 50.5));
170 db_->AddMetric(activity_,
171 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 13.1));
172 db_->AddMetric(kProcessChromeAggregate,
173 Metric(METRIC_PRIVATE_MEMORY_USAGE,
174 clock_->GetTime(),
175 1000000.0));
176 db_->AddMetric(activity_,
177 Metric(METRIC_PRIVATE_MEMORY_USAGE,
178 clock_->GetTime(),
179 3000000.0));
182 scoped_ptr<Database> db_;
183 Database::Clock* clock_;
184 base::ScopedTempDir temp_dir_;
185 std::string activity_;
188 ////// PerformanceMonitorDatabaseSetupTests ////////////////////////////////////
189 TEST(PerformanceMonitorDatabaseSetupTest, OpenClose) {
190 base::ScopedTempDir temp_dir;
191 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
192 scoped_ptr<Database> db = Database::Create(temp_dir.path());
193 ASSERT_TRUE(db.get());
194 DatabaseTestHelper helper(db.get());
195 ASSERT_TRUE(helper.Close());
198 TEST(PerformanceMonitorDatabaseSetupTest, ActiveInterval) {
199 base::ScopedTempDir temp_dir;
200 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
202 TestingClock* clock_1 = new TestingClock();
203 base::Time start_time = clock_1->GetTime();
205 scoped_ptr<Database> db_1 = Database::Create(temp_dir.path());
206 db_1->set_clock(scoped_ptr<Database::Clock>(clock_1));
207 DatabaseTestHelper helper1(db_1.get());
208 db_1->AddStateValue("test", "test");
209 ASSERT_TRUE(db_1.get());
210 ASSERT_TRUE(helper1.Close());
212 TestingClock* clock_2 = new TestingClock(*clock_1);
213 base::Time mid_time = clock_2->GetTime();
214 scoped_ptr<Database> db_2 = Database::Create(temp_dir.path());
215 db_2->set_clock(scoped_ptr<Database::Clock>(clock_2));
216 DatabaseTestHelper helper2(db_2.get());
217 db_2->AddStateValue("test", "test");
218 ASSERT_TRUE(db_2.get());
219 ASSERT_TRUE(helper2.Close());
221 TestingClock* clock_3 = new TestingClock(*clock_2);
222 base::Time end_time = clock_3->GetTime();
223 scoped_ptr<Database> db_3 = Database::Create(temp_dir.path());
224 db_3->set_clock(scoped_ptr<Database::Clock>(clock_3));
225 db_3->AddStateValue("test", "test");
226 ASSERT_TRUE(db_3.get());
228 std::vector<TimeRange> active_interval = db_3->GetActiveIntervals(start_time,
229 end_time);
230 ASSERT_EQ(active_interval.size(), 2u);
231 ASSERT_TRUE(active_interval[0].start > start_time &&
232 active_interval[0].end < mid_time);
233 ASSERT_TRUE(active_interval[1].start > mid_time &&
234 active_interval[1].end < end_time);
237 TEST(PerformanceMonitorDatabaseSetupTest,
238 ActiveIntervalRetrievalDuringActiveInterval) {
239 base::ScopedTempDir temp_dir;
240 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
242 TestingClock* clock = new TestingClock();
243 scoped_ptr<Database> db = Database::Create(temp_dir.path());
244 db->set_clock(scoped_ptr<Database::Clock>(clock));
245 db->AddStateValue("test", "test");
246 base::Time start_time = clock->GetTime();
247 db->AddStateValue("test", "test");
248 base::Time end_time = clock->GetTime();
249 db->AddStateValue("test", "test");
251 std::vector<TimeRange> active_interval = db->GetActiveIntervals(start_time,
252 end_time);
253 ASSERT_EQ(1u, active_interval.size());
254 EXPECT_LT(active_interval[0].start, start_time);
255 EXPECT_GT(active_interval[0].end, start_time);
258 TEST(PerformanceMonitorDatabaseSetupTest,
259 ActiveIntervalRetrievalAfterActiveInterval) {
260 base::ScopedTempDir temp_dir;
261 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
263 TestingClock* clock = new TestingClock();
264 scoped_ptr<Database> db = Database::Create(temp_dir.path());
265 db->set_clock(scoped_ptr<Database::Clock>(clock));
266 db->AddStateValue("test", "test");
268 base::Time start_time = clock->GetTime();
269 base::Time end_time = clock->GetTime();
270 std::vector<TimeRange> active_interval = db->GetActiveIntervals(start_time,
271 end_time);
272 EXPECT_TRUE(active_interval.empty());
275 ////// PerformanceMonitorDatabaseEventTests ////////////////////////////////////
276 TEST_F(PerformanceMonitorDatabaseEventTest, GetAllEvents) {
277 Database::EventVector events = db_->GetEvents();
278 ASSERT_EQ(4u, events.size());
279 EXPECT_TRUE(events[0]->data()->Equals(install_event_1_->data()));
280 EXPECT_TRUE(events[1]->data()->Equals(install_event_2_->data()));
281 EXPECT_TRUE(events[2]->data()->Equals(uninstall_event_1_->data()));
282 EXPECT_TRUE(events[3]->data()->Equals(uninstall_event_2_->data()));
285 TEST_F(PerformanceMonitorDatabaseMetricTest, GetMaxMetric) {
286 Metric stat;
287 EXPECT_EQ(0.0, db_->GetMaxStatsForActivityAndMetric(activity_,
288 METRIC_PAGE_LOAD_TIME));
290 EXPECT_EQ(1000000,
291 db_->GetMaxStatsForActivityAndMetric(METRIC_PRIVATE_MEMORY_USAGE));
293 db_->AddMetric(kProcessChromeAggregate,
294 Metric(METRIC_PRIVATE_MEMORY_USAGE, clock_->GetTime(), 99.0));
295 EXPECT_EQ(1000000,
296 db_->GetMaxStatsForActivityAndMetric(METRIC_PRIVATE_MEMORY_USAGE));
298 db_->AddMetric(kProcessChromeAggregate,
299 Metric(METRIC_PRIVATE_MEMORY_USAGE,
300 clock_->GetTime(),
301 6000000.0));
302 EXPECT_EQ(6000000,
303 db_->GetMaxStatsForActivityAndMetric(METRIC_PRIVATE_MEMORY_USAGE));
306 TEST_F(PerformanceMonitorDatabaseEventTest, GetAllEventTypes) {
307 Database::EventTypeSet types = db_->GetEventTypes();
308 ASSERT_EQ(2u, types.size());
309 ASSERT_EQ(1u, types.count(EVENT_EXTENSION_INSTALL));
310 ASSERT_EQ(1u, types.count(EVENT_EXTENSION_UNINSTALL));
313 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventInTimeRange) {
314 base::Time start_time = clock_->GetTime();
315 scoped_ptr<Event> crash_event = util::CreateRendererFailureEvent(
316 clock_->GetTime(), EVENT_RENDERER_CRASH, "http://www.google.com/");
317 db_->AddEvent(*crash_event.get());
318 Database::EventVector events = db_->GetEvents(start_time, clock_->GetTime());
319 ASSERT_EQ(1u, events.size());
320 EXPECT_TRUE(events[0]->data()->Equals(crash_event->data()));
323 TEST_F(PerformanceMonitorDatabaseEventTest, GetInstallEvents) {
324 Database::EventVector events = db_->GetEvents(EVENT_EXTENSION_INSTALL);
325 ASSERT_EQ(2u, events.size());
326 EXPECT_TRUE(events[0]->data()->Equals(install_event_1_->data()));
327 EXPECT_TRUE(events[1]->data()->Equals(install_event_2_->data()));
330 TEST_F(PerformanceMonitorDatabaseEventTest, InvalidEvents) {
331 DatabaseTestHelper helper(db_.get());
333 // Insert an invalid event into the database; verify it is inserted.
334 size_t original_number_of_entries = helper.GetNumberOfEventEntries();
335 ASSERT_TRUE(helper.AddInvalidEvent(
336 clock_->GetTime(), EVENT_EXTENSION_INSTALL));
337 ASSERT_EQ(original_number_of_entries + 1u, helper.GetNumberOfEventEntries());
339 // Should not retrieve the invalid event.
340 Database::EventVector events = db_->GetEvents();
341 ASSERT_EQ(original_number_of_entries, events.size());
343 // Invalid event should have been deleted.
344 ASSERT_EQ(original_number_of_entries, helper.GetNumberOfEventEntries());
347 TEST_F(PerformanceMonitorDatabaseEventTest, GetUnusedEventType) {
348 Database::EventVector events = db_->GetEvents(EVENT_EXTENSION_DISABLE);
349 ASSERT_TRUE(events.empty());
350 events = db_->GetEvents(EVENT_EXTENSION_DISABLE, clock_->GetTime(),
351 clock_->GetTime());
352 ASSERT_TRUE(events.empty());
355 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventsTimeRange) {
356 base::Time start_time = clock_->GetTime();
357 scoped_ptr<Event> new_install_event =
358 util::CreateExtensionEvent(EVENT_EXTENSION_INSTALL, clock_->GetTime(),
359 "c", "test extension", "http://foo.com",
360 static_cast<int>(Manifest::UNPACKED), "0.1",
361 "Test Test");
362 scoped_ptr<Event> new_uninstall_event =
363 util::CreateExtensionEvent(EVENT_EXTENSION_UNINSTALL, clock_->GetTime(),
364 "c", "test extension", "http://foo.com",
365 static_cast<int>(Manifest::UNPACKED), "0.1",
366 "Test Test");
367 base::Time end_time = clock_->GetTime();
368 db_->AddEvent(*new_install_event.get());
369 db_->AddEvent(*new_uninstall_event.get());
370 Database::EventVector events = db_->GetEvents(start_time, end_time);
371 ASSERT_EQ(2u, events.size());
372 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data()));
373 EXPECT_TRUE(events[1]->data()->Equals(new_uninstall_event->data()));
374 events = db_->GetEvents(
375 EVENT_EXTENSION_INSTALL, start_time, end_time);
376 ASSERT_EQ(1u, events.size());
377 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data()));
380 ////// PerformanceMonitorDatabaseMetricTests ///////////////////////////////////
381 TEST_F(PerformanceMonitorDatabaseMetricTest, GetActiveMetrics) {
382 Database::MetricTypeSet active_metrics =
383 db_->GetActiveMetrics(base::Time(), clock_->GetTime());
385 Database::MetricTypeSet expected_metrics;
386 expected_metrics.insert(METRIC_CPU_USAGE);
387 expected_metrics.insert(METRIC_PRIVATE_MEMORY_USAGE);
388 EXPECT_EQ(expected_metrics, active_metrics);
391 TEST_F(PerformanceMonitorDatabaseMetricTest, GetRecentMetric) {
392 Metric stat;
393 ASSERT_TRUE(db_->GetRecentStatsForActivityAndMetric(activity_,
394 METRIC_PRIVATE_MEMORY_USAGE, &stat));
395 EXPECT_EQ(3000000, stat.value);
397 ASSERT_TRUE(db_->GetRecentStatsForActivityAndMetric(METRIC_CPU_USAGE, &stat));
398 EXPECT_EQ(50.5, stat.value);
400 base::ScopedTempDir dir;
401 CHECK(dir.CreateUniqueTempDir());
402 scoped_ptr<Database> db = Database::Create(dir.path());
403 CHECK(db.get());
404 db->set_clock(scoped_ptr<Database::Clock>(new TestingClock()));
405 EXPECT_FALSE(db->GetRecentStatsForActivityAndMetric(METRIC_CPU_USAGE, &stat));
408 TEST_F(PerformanceMonitorDatabaseMetricTest, GetState) {
409 std::string key("version");
410 std::string value("1.0.0.0.1");
411 db_->AddStateValue(key, value);
412 EXPECT_EQ(db_->GetStateValue(key), value);
415 TEST_F(PerformanceMonitorDatabaseMetricTest, GetStateOverride) {
416 std::string key("version");
417 std::string value_1("1.0.0.0.0");
418 std::string value_2("1.0.0.0.1");
419 db_->AddStateValue(key, value_1);
420 db_->AddStateValue(key, value_2);
421 EXPECT_EQ(db_->GetStateValue(key), value_2);
424 TEST_F(PerformanceMonitorDatabaseMetricTest, GetStatsForActivityAndMetric) {
425 Database::MetricVector stats = *db_->GetStatsForActivityAndMetric(
426 activity_, METRIC_CPU_USAGE, base::Time(), clock_->GetTime());
427 ASSERT_EQ(1u, stats.size());
428 EXPECT_EQ(13.1, stats[0].value);
429 base::Time before = clock_->GetTime();
430 db_->AddMetric(activity_,
431 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 18.0));
432 stats = *db_->GetStatsForActivityAndMetric(activity_, METRIC_CPU_USAGE,
433 before, clock_->GetTime());
434 ASSERT_EQ(1u, stats.size());
435 EXPECT_EQ(18, stats[0].value);
436 stats = *db_->GetStatsForActivityAndMetric(activity_, METRIC_CPU_USAGE);
437 ASSERT_EQ(2u, stats.size());
438 EXPECT_EQ(13.1, stats[0].value);
439 EXPECT_EQ(18, stats[1].value);
440 stats = *db_->GetStatsForActivityAndMetric(METRIC_PRIVATE_MEMORY_USAGE);
441 ASSERT_EQ(1u, stats.size());
442 EXPECT_EQ(1000000, stats[0].value);
443 stats = *db_->GetStatsForActivityAndMetric(activity_, METRIC_CPU_USAGE,
444 clock_->GetTime(),
445 clock_->GetTime());
446 EXPECT_TRUE(stats.empty());
449 TEST_F(PerformanceMonitorDatabaseMetricTest, GetStatsForMetricByActivity) {
450 Database::MetricVectorMap stats_map = db_->GetStatsForMetricByActivity(
451 METRIC_CPU_USAGE, base::Time(), clock_->GetTime());
452 ASSERT_EQ(2u, stats_map.size());
453 linked_ptr<Database::MetricVector> stats = stats_map[activity_];
454 ASSERT_EQ(1u, stats->size());
455 EXPECT_EQ(13.1, stats->at(0).value);
456 stats = stats_map[kProcessChromeAggregate];
457 ASSERT_EQ(1u, stats->size());
458 EXPECT_EQ(50.5, stats->at(0).value);
459 stats_map = db_->GetStatsForMetricByActivity(
460 METRIC_CPU_USAGE, clock_->GetTime(), clock_->GetTime());
461 EXPECT_EQ(0u, stats_map.size());
462 base::Time before = clock_->GetTime();
463 db_->AddMetric(activity_,
464 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 18.0));
465 stats_map = db_->GetStatsForMetricByActivity(METRIC_CPU_USAGE, before,
466 clock_->GetTime());
467 ASSERT_EQ(1u, stats_map.size());
468 stats = stats_map[activity_];
469 ASSERT_EQ(1u, stats->size());
470 EXPECT_EQ(18, stats->at(0).value);
473 TEST_F(PerformanceMonitorDatabaseMetricTest, InvalidMetrics) {
474 DatabaseTestHelper helper(db_.get());
475 Metric invalid_metric(METRIC_CPU_USAGE, clock_->GetTime(), -5.0);
476 ASSERT_FALSE(invalid_metric.IsValid());
478 // Find the original number of entries in the database.
479 size_t original_number_of_entries = helper.GetNumberOfMetricEntries();
480 Database::MetricVector stats = *db_->GetStatsForActivityAndMetric(
481 activity_, METRIC_CPU_USAGE, base::Time(), clock_->GetTime());
482 size_t original_number_of_cpu_entries = stats.size();
484 // Check that the database normally refuses to insert bad metrics.
485 EXPECT_FALSE(db_->AddMetric(invalid_metric));
487 // Verify that it was not inserted into the database.
488 stats = *db_->GetStatsForActivityAndMetric(
489 activity_, METRIC_CPU_USAGE, base::Time(), clock_->GetTime());
490 ASSERT_EQ(original_number_of_cpu_entries, stats.size());
492 // Forcefully insert it into the database.
493 ASSERT_TRUE(helper.AddInvalidMetric(activity_, invalid_metric));
494 ASSERT_EQ(original_number_of_entries + 1u, helper.GetNumberOfMetricEntries());
496 // Try to retrieve it; should only get one result.
497 stats = *db_->GetStatsForActivityAndMetric(
498 activity_, METRIC_CPU_USAGE, base::Time(), clock_->GetTime());
499 ASSERT_EQ(original_number_of_cpu_entries, stats.size());
501 // Entry should have been deleted in the database.
502 ASSERT_EQ(original_number_of_entries, helper.GetNumberOfMetricEntries());
505 TEST_F(PerformanceMonitorDatabaseMetricTest, GetFullRange) {
506 db_->AddMetric(kProcessChromeAggregate,
507 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 3.4));
508 db_->AddMetric(kProcessChromeAggregate,
509 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0));
510 Database::MetricVector stats =
511 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE);
512 ASSERT_EQ(3u, stats.size());
513 ASSERT_EQ(50.5, stats[0].value);
514 ASSERT_EQ(3.4, stats[1].value);
515 ASSERT_EQ(21, stats[2].value);
518 TEST_F(PerformanceMonitorDatabaseMetricTest, GetRange) {
519 base::Time start = clock_->GetTime();
520 db_->AddMetric(kProcessChromeAggregate,
521 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 3.0));
522 db_->AddMetric(kProcessChromeAggregate,
523 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 9.0));
524 base::Time end = clock_->GetTime();
525 db_->AddMetric(kProcessChromeAggregate,
526 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0));
527 Database::MetricVector stats =
528 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end);
529 ASSERT_EQ(2u, stats.size());
530 ASSERT_EQ(3, stats[0].value);
531 ASSERT_EQ(9, stats[1].value);
534 } // namespace performance_monitor