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

Side by Side Diff: cc/debug/latency_info.cc

Issue 13874002: Switch LatencyInfo struct to use a map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/debug/latency_info.h ('k') | content/common/cc_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/debug/latency_info.h"
6
7 #include <algorithm>
8
9 namespace cc {
10
11 LatencyInfo::LatencyInfo() {
12 }
13
14 LatencyInfo::~LatencyInfo() {
15 }
16
17 void LatencyInfo::MergeWith(const LatencyInfo& other) {
18 for (LatencyMap::const_iterator b = other.latency_components.begin();
19 b != other.latency_components.end(); ++b) {
20 AddLatencyNumberWithTimestamp(b->first.first, b->first.second,
21 b->second.sequence_number,
22 b->second.event_time,
23 b->second.event_count);
24 }
25 }
26
27 void LatencyInfo::AddLatencyNumber(LatencyComponentType component,
28 int64 id, int64 component_sequence_number) {
29 AddLatencyNumberWithTimestamp(component, id, component_sequence_number,
30 base::TimeTicks::Now(), 1);
31 }
32
33 void LatencyInfo::AddLatencyNumberWithTimestamp(
34 LatencyComponentType component, int64 id, int64 component_sequence_number,
35 base::TimeTicks time, uint32 event_count) {
36 LatencyMap::key_type key = std::make_pair(component, id);
37 LatencyMap::iterator f = latency_components.find(key);
38 if (f == latency_components.end()) {
39 LatencyComponent info = {component_sequence_number, time, event_count};
40 latency_components[key] = info;
41 } else {
42 f->second.sequence_number = std::max(component_sequence_number,
43 f->second.sequence_number);
44 uint32 new_count = event_count + f->second.event_count;
45 if (event_count > 0 && new_count != 0) {
46 // Do a weighted average, so that the new event_time is the average of
47 // the times of events currently in this structure with the time passed
48 // into this method.
49 f->second.event_time += (time - f->second.event_time) * event_count /
50 new_count;
51 f->second.event_count += new_count;
52 }
53 }
54 }
55
56 void LatencyInfo::Clear() {
57 latency_components.clear();
58 }
59
60 } // namespace cc
61
OLDNEW
« no previous file with comments | « cc/debug/latency_info.h ('k') | content/common/cc_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698