Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 void LatencyInfo::MergeWith(const LatencyInfo& other) { | |
| 12 for (LatencyMap::const_iterator b = other.latency_components.begin(); | |
| 13 b != other.latency_components.end(); ++b) { | |
| 14 AddLatencyNumberWithTimestamp(b->first.first, b->first.second, | |
| 15 b->second.sequence_number, | |
| 16 b->second.event_time, | |
| 17 b->second.event_count); | |
| 18 } | |
| 19 } | |
| 20 | |
| 21 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, | |
| 22 int64 id, int64 component_sequence_number) { | |
| 23 AddLatencyNumberWithTimestamp(component, id, component_sequence_number, | |
| 24 base::TimeTicks::Now(), 1); | |
| 25 } | |
| 26 | |
| 27 void LatencyInfo::AddLatencyNumberWithTimestamp( | |
| 28 LatencyComponentType component, int64 id, int64 component_sequence_number, | |
| 29 base::TimeTicks time, int event_count) { | |
| 30 LatencyMap::key_type key = std::make_pair(component, id); | |
| 31 LatencyMap::iterator f = latency_components.find(key); | |
| 32 if (f == latency_components.end()) { | |
| 33 LatencyComponent info = {component_sequence_number, time, event_count}; | |
| 34 latency_components[key] = info; | |
| 35 } else { | |
| 36 f->second.sequence_number = std::max(component_sequence_number, | |
| 37 f->second.sequence_number); | |
| 38 if (event_count > 0) { | |
| 39 // Do a weighted average, so that the new event_time is the average of | |
| 40 // the times of events currently in this structure with the time passed | |
| 41 // into this method. | |
| 42 f->second.event_time += (time - f->second.event_time) * event_count / | |
| 43 (event_count + f->second.event_count); | |
|
Chris Evans
2013/04/15 21:06:25
Seems like there's opportunity to be more careful
| |
| 44 f->second.event_count += event_count; | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void LatencyInfo::Clear() { | |
| 50 latency_components.clear(); | |
| 51 } | |
| 52 | |
| 53 } // namespace cc | |
| 54 | |
| OLD | NEW |