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

Side by Side Diff: ui/base/latency_info.cc

Issue 14999012: Move cc/debug/latency_info to ui/base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « ui/base/latency_info.h ('k') | ui/ui.gyp » ('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 "ui/base/latency_info.h"
6
7 #include <algorithm>
8
9 namespace ui {
10
11 LatencyInfo::LatencyInfo() {
12 }
13
14 LatencyInfo::~LatencyInfo() {
15 }
16
17 void LatencyInfo::MergeWith(const LatencyInfo& other) {
18 for (LatencyMap::const_iterator it = other.latency_components.begin();
19 it != other.latency_components.end();
20 ++it) {
21 AddLatencyNumberWithTimestamp(it->first.first,
22 it->first.second,
23 it->second.sequence_number,
24 it->second.event_time,
25 it->second.event_count);
26 }
27 }
28
29 void LatencyInfo::AddLatencyNumber(LatencyComponentType component,
30 int64 id,
31 int64 component_sequence_number) {
32 AddLatencyNumberWithTimestamp(component, id, component_sequence_number,
33 base::TimeTicks::Now(), 1);
34 }
35
36 void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component,
37 int64 id,
38 int64 component_sequence_number,
39 base::TimeTicks time,
40 uint32 event_count) {
41 LatencyMap::key_type key = std::make_pair(component, id);
42 LatencyMap::iterator it = latency_components.find(key);
43 if (it == latency_components.end()) {
44 LatencyComponent info = {component_sequence_number, time, event_count};
45 latency_components[key] = info;
46 return;
47 }
48 it->second.sequence_number = std::max(component_sequence_number,
49 it->second.sequence_number);
50 uint32 new_count = event_count + it->second.event_count;
51 if (event_count > 0 && new_count != 0) {
52 // Do a weighted average, so that the new event_time is the average of
53 // the times of events currently in this structure with the time passed
54 // into this method.
55 it->second.event_time += (time - it->second.event_time) * event_count /
56 new_count;
57 it->second.event_count = new_count;
58 }
59 }
60
61 void LatencyInfo::Clear() {
62 latency_components.clear();
63 }
64
65 } // namespace ui
66
OLDNEW
« no previous file with comments | « ui/base/latency_info.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698