| 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/performance_monitor_util.h" | 5 #include "chrome/browser/performance_monitor/performance_monitor_util.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "chrome/browser/performance_monitor/database.h" | |
| 13 #include "chrome/browser/performance_monitor/events.h" | 12 #include "chrome/browser/performance_monitor/events.h" |
| 14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 15 | 14 |
| 16 namespace performance_monitor { | 15 namespace performance_monitor { |
| 17 namespace util { | 16 namespace util { |
| 18 | 17 |
| 19 std::vector<MetricInfo> AggregateMetric( | 18 Database::MetricVector AggregateMetric(const Database::MetricVector& metrics, |
| 20 const std::vector<MetricInfo>& metric_infos, | 19 const base::Time& start, |
| 21 const base::Time& start, | 20 const base::TimeDelta& resolution) { |
| 22 const base::TimeDelta& resolution) { | 21 Database::MetricVector results; |
| 23 std::vector<MetricInfo> results; | |
| 24 // Ignore all the points before the aggregation start. | 22 // Ignore all the points before the aggregation start. |
| 25 std::vector<MetricInfo>::const_iterator it = metric_infos.begin(); | 23 Database::MetricVector::const_iterator it = metrics.begin(); |
| 26 for (; it != metric_infos.end() && it->time < start; ++it) { } | 24 for (; it != metrics.end() && it->time < start; ++it) { } |
| 27 | 25 |
| 28 while (it != metric_infos.end()) { | 26 while (it != metrics.end()) { |
| 29 // Finds the beginning of the next aggregation window. | 27 // Finds the beginning of the next aggregation window. |
| 30 int64 window_offset = (it->time - start) / resolution; | 28 int64 window_offset = (it->time - start) / resolution; |
| 31 base::Time window_start = start + (window_offset * resolution); | 29 base::Time window_start = start + (window_offset * resolution); |
| 32 base::Time window_end = window_start + resolution; | 30 base::Time window_end = window_start + resolution; |
| 33 base::Time last_sample_time = window_start; | 31 base::Time last_sample_time = window_start; |
| 34 double integrated = 0.0; | 32 double integrated = 0.0; |
| 35 double metric_value = 0.0; | 33 double metric_value = 0.0; |
| 36 | 34 |
| 37 // Aggregate the step function defined by the MetricInfos in |metric_infos|. | 35 // Aggregate the step function defined by the Metrics in |metrics|. |
| 38 while (it != metric_infos.end() && it->time <= window_end) { | 36 while (it != metrics.end() && it->time <= window_end) { |
| 39 metric_value = it->value; | 37 metric_value = it->value; |
| 40 integrated += metric_value * (it->time - last_sample_time).InSecondsF(); | 38 integrated += metric_value * (it->time - last_sample_time).InSecondsF(); |
| 41 last_sample_time = it->time; | 39 last_sample_time = it->time; |
| 42 ++it; | 40 ++it; |
| 43 } | 41 } |
| 44 if (it != metric_infos.end()) | 42 if (it != metrics.end()) |
| 45 metric_value = it->value; | 43 metric_value = it->value; |
| 46 | 44 |
| 47 // If the window splits an area of the step function, split the aggregation | 45 // If the window splits an area of the step function, split the aggregation |
| 48 // at the end of the window. | 46 // at the end of the window. |
| 49 integrated += metric_value * (window_end - last_sample_time).InSecondsF(); | 47 integrated += metric_value * (window_end - last_sample_time).InSecondsF(); |
| 50 double average = integrated / resolution.InSecondsF(); | 48 double average = integrated / resolution.InSecondsF(); |
| 51 results.push_back(MetricInfo(window_end, average)); | 49 results.push_back(Metric(window_end, average)); |
| 52 } | 50 } |
| 53 return results; | 51 return results; |
| 54 } | 52 } |
| 55 | 53 |
| 56 bool PostTaskToDatabaseThreadAndReply( | 54 bool PostTaskToDatabaseThreadAndReply( |
| 57 const tracked_objects::Location& from_here, | 55 const tracked_objects::Location& from_here, |
| 58 const base::Closure& request, | 56 const base::Closure& request, |
| 59 const base::Closure& reply) { | 57 const base::Closure& reply) { |
| 60 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 58 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 61 base::SequencedWorkerPool::SequenceToken token = | 59 base::SequencedWorkerPool::SequenceToken token = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 event.time = static_cast<double>(time.ToInternalValue()); | 123 event.time = static_cast<double>(time.ToInternalValue()); |
| 126 event.previous_version = previous_version; | 124 event.previous_version = previous_version; |
| 127 event.current_version = current_version; | 125 event.current_version = current_version; |
| 128 scoped_ptr<base::DictionaryValue> value = event.ToValue(); | 126 scoped_ptr<base::DictionaryValue> value = event.ToValue(); |
| 129 return scoped_ptr<Event>(new Event( | 127 return scoped_ptr<Event>(new Event( |
| 130 EVENT_CHROME_UPDATE, time, value.Pass())); | 128 EVENT_CHROME_UPDATE, time, value.Pass())); |
| 131 } | 129 } |
| 132 | 130 |
| 133 } // namespace util | 131 } // namespace util |
| 134 } // namespace performance_monitor | 132 } // namespace performance_monitor |
| OLD | NEW |