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

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

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

Powered by Google App Engine
This is Rietveld 408576698