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 "chrome/browser/performance_monitor/database.h" | 5 #include "chrome/browser/performance_monitor/database.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 start, static_cast<MetricType>(0), std::string()); | 372 start, static_cast<MetricType>(0), std::string()); |
373 scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_)); | 373 scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_)); |
374 for (it->Seek(start_key); it->Valid(); it->Next()) { | 374 for (it->Seek(start_key); it->Valid(); it->Next()) { |
375 RecentKey split_key = SplitRecentKey(it->key().ToString()); | 375 RecentKey split_key = SplitRecentKey(it->key().ToString()); |
376 if (split_key.type == metric_type) | 376 if (split_key.type == metric_type) |
377 results.push_back(split_key.activity); | 377 results.push_back(split_key.activity); |
378 } | 378 } |
379 return results; | 379 return results; |
380 } | 380 } |
381 | 381 |
382 bool Database::GetRecentStatsForActivityAndMetric( | |
383 const std::string& activity, | |
384 MetricType metric, | |
385 MetricInfo* info) { | |
386 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
387 std::string recent_map_key = CreateRecentMapKey(metric, activity); | |
388 if (!recent_map_.count(recent_map_key)) | |
389 return false; | |
390 std::string recent_start_key = recent_map_[recent_map_key]; | |
eaugusti
2012/07/31 18:46:06
Not really a "start" key, just a key.
chebert
2012/07/31 19:26:36
Done.
| |
391 | |
392 scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_)); | |
eaugusti
2012/07/31 18:46:06
Maybe use Get() instead of an iterator:
http://lev
chebert
2012/07/31 19:26:36
Done.
| |
393 | |
394 it->Seek(recent_start_key); | |
395 if (it->Valid()) { | |
396 RecentKey split_key = SplitRecentKey(it->key().ToString()); | |
397 if (split_key.activity == activity) { | |
398 *info = MetricInfo(split_key.time, it->value().ToString()); | |
399 return true; | |
400 } | |
401 } | |
402 return false; | |
403 } | |
404 | |
382 Database::MetricInfoVector Database::GetStatsForActivityAndMetric( | 405 Database::MetricInfoVector Database::GetStatsForActivityAndMetric( |
383 const std::string& activity, MetricType metric_type, | 406 const std::string& activity, MetricType metric_type, |
384 const base::Time& start, const base::Time& end) { | 407 const base::Time& start, const base::Time& end) { |
385 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 408 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
386 MetricInfoVector results; | 409 MetricInfoVector results; |
387 std::string start_key = CreateMetricKey(start, metric_type, activity); | 410 std::string start_key = CreateMetricKey(start, metric_type, activity); |
388 std::string end_key = CreateMetricKey(end, metric_type, activity); | 411 std::string end_key = CreateMetricKey(end, metric_type, activity); |
389 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_)); | 412 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_)); |
390 for (it->Seek(start_key); | 413 for (it->Seek(start_key); |
391 it->Valid() && it->key().ToString() <= end_key; | 414 it->Valid() && it->key().ToString() <= end_key; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 start_time_key_ = CreateActiveIntervalKey(current_time); | 528 start_time_key_ = CreateActiveIntervalKey(current_time); |
506 end_time = start_time_key_; | 529 end_time = start_time_key_; |
507 } else { | 530 } else { |
508 end_time = CreateActiveIntervalKey(clock_->GetTime()); | 531 end_time = CreateActiveIntervalKey(clock_->GetTime()); |
509 } | 532 } |
510 last_update_time_ = current_time; | 533 last_update_time_ = current_time; |
511 active_interval_db_->Put(write_options_, start_time_key_, end_time); | 534 active_interval_db_->Put(write_options_, start_time_key_, end_time); |
512 } | 535 } |
513 | 536 |
514 } // namespace performance_monitor | 537 } // namespace performance_monitor |
OLD | NEW |