| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/stl_util.h" |
| 14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 15 #include "base/string_split.h" | 16 #include "base/string_split.h" |
| 16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 22 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 22 | 23 |
| 23 namespace performance_monitor { | 24 namespace performance_monitor { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 start, static_cast<MetricType>(0), std::string()); | 373 start, static_cast<MetricType>(0), std::string()); |
| 373 scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_)); | 374 scoped_ptr<leveldb::Iterator> it(recent_db_->NewIterator(read_options_)); |
| 374 for (it->Seek(start_key); it->Valid(); it->Next()) { | 375 for (it->Seek(start_key); it->Valid(); it->Next()) { |
| 375 RecentKey split_key = SplitRecentKey(it->key().ToString()); | 376 RecentKey split_key = SplitRecentKey(it->key().ToString()); |
| 376 if (split_key.type == metric_type) | 377 if (split_key.type == metric_type) |
| 377 results.push_back(split_key.activity); | 378 results.push_back(split_key.activity); |
| 378 } | 379 } |
| 379 return results; | 380 return results; |
| 380 } | 381 } |
| 381 | 382 |
| 383 bool Database::GetRecentStatsForActivityAndMetric( |
| 384 const std::string& activity, |
| 385 MetricType metric, |
| 386 MetricInfo* info) { |
| 387 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 388 std::string recent_map_key = CreateRecentMapKey(metric, activity); |
| 389 if (!ContainsKey(recent_map_, recent_map_key)) |
| 390 return false; |
| 391 std::string recent_key = recent_map_[recent_map_key]; |
| 392 |
| 393 std::string result; |
| 394 leveldb::Status status = recent_db_->Get(read_options_, recent_key, &result); |
| 395 if (status.ok()) |
| 396 *info = MetricInfo(SplitRecentKey(recent_key).time, result); |
| 397 return status.ok(); |
| 398 } |
| 399 |
| 382 Database::MetricInfoVector Database::GetStatsForActivityAndMetric( | 400 Database::MetricInfoVector Database::GetStatsForActivityAndMetric( |
| 383 const std::string& activity, MetricType metric_type, | 401 const std::string& activity, MetricType metric_type, |
| 384 const base::Time& start, const base::Time& end) { | 402 const base::Time& start, const base::Time& end) { |
| 385 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 403 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 386 MetricInfoVector results; | 404 MetricInfoVector results; |
| 387 std::string start_key = CreateMetricKey(start, metric_type, activity); | 405 std::string start_key = CreateMetricKey(start, metric_type, activity); |
| 388 std::string end_key = CreateMetricKey(end, metric_type, activity); | 406 std::string end_key = CreateMetricKey(end, metric_type, activity); |
| 389 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_)); | 407 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_)); |
| 390 for (it->Seek(start_key); | 408 for (it->Seek(start_key); |
| 391 it->Valid() && it->key().ToString() <= end_key; | 409 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); | 523 start_time_key_ = CreateActiveIntervalKey(current_time); |
| 506 end_time = start_time_key_; | 524 end_time = start_time_key_; |
| 507 } else { | 525 } else { |
| 508 end_time = CreateActiveIntervalKey(clock_->GetTime()); | 526 end_time = CreateActiveIntervalKey(clock_->GetTime()); |
| 509 } | 527 } |
| 510 last_update_time_ = current_time; | 528 last_update_time_ = current_time; |
| 511 active_interval_db_->Put(write_options_, start_time_key_, end_time); | 529 active_interval_db_->Put(write_options_, start_time_key_, end_time); |
| 512 } | 530 } |
| 513 | 531 |
| 514 } // namespace performance_monitor | 532 } // namespace performance_monitor |
| OLD | NEW |