Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/performance_monitor/database.cc

Issue 10843010: Adds a method to the Performance Monitor Database to fetch the most recent metric. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: using get instead of an iterator Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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))
Yoyo Zhou 2012/08/02 11:54:57 Use ContainsKey from stl_util.h.
389 return false;
390 std::string recent_key = recent_map_[recent_map_key];
391
392 std::string result;
393 leveldb::Status status = recent_db_->Get(read_options_, recent_key, &result);
394 if (status.ok())
395 *info = MetricInfo(SplitRecentKey(recent_key).time, result);
396 return status.ok();
397 }
398
382 Database::MetricInfoVector Database::GetStatsForActivityAndMetric( 399 Database::MetricInfoVector Database::GetStatsForActivityAndMetric(
383 const std::string& activity, MetricType metric_type, 400 const std::string& activity, MetricType metric_type,
384 const base::Time& start, const base::Time& end) { 401 const base::Time& start, const base::Time& end) {
385 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 402 CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
386 MetricInfoVector results; 403 MetricInfoVector results;
387 std::string start_key = CreateMetricKey(start, metric_type, activity); 404 std::string start_key = CreateMetricKey(start, metric_type, activity);
388 std::string end_key = CreateMetricKey(end, metric_type, activity); 405 std::string end_key = CreateMetricKey(end, metric_type, activity);
389 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_)); 406 scoped_ptr<leveldb::Iterator> it(metric_db_->NewIterator(read_options_));
390 for (it->Seek(start_key); 407 for (it->Seek(start_key);
391 it->Valid() && it->key().ToString() <= end_key; 408 it->Valid() && it->key().ToString() <= end_key;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 start_time_key_ = CreateActiveIntervalKey(current_time); 522 start_time_key_ = CreateActiveIntervalKey(current_time);
506 end_time = start_time_key_; 523 end_time = start_time_key_;
507 } else { 524 } else {
508 end_time = CreateActiveIntervalKey(clock_->GetTime()); 525 end_time = CreateActiveIntervalKey(clock_->GetTime());
509 } 526 }
510 last_update_time_ = current_time; 527 last_update_time_ = current_time;
511 active_interval_db_->Put(write_options_, start_time_key_, end_time); 528 active_interval_db_->Put(write_options_, start_time_key_, end_time);
512 } 529 }
513 530
514 } // namespace performance_monitor 531 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698